Skip to content

Commit

Permalink
Change libevent event loop to wait forever when blocking (#15243)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden authored Dec 4, 2024
1 parent bf0a586 commit 0580ff2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/crystal/event_loop/libevent.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class Crystal::EventLoop::LibEvent < Crystal::EventLoop
{% end %}

def run(blocking : Bool) : Bool
event_base.loop(once: true, nonblock: !blocking)
flags = LibEvent2::EventLoopFlags::Once
flags |= blocking ? LibEvent2::EventLoopFlags::NoExitOnEmpty : LibEvent2::EventLoopFlags::NonBlock
event_base.loop(flags)
end

def interrupt : Nil
Expand Down
5 changes: 1 addition & 4 deletions src/crystal/event_loop/libevent/event.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ class Crystal::EventLoop::LibEvent < Crystal::EventLoop

# NOTE: may return `true` even if no event has been triggered (e.g.
# nonblocking), but `false` means that nothing was processed.
def loop(once : Bool, nonblock : Bool) : Bool
flags = LibEvent2::EventLoopFlags::None
flags |= LibEvent2::EventLoopFlags::Once if once
flags |= LibEvent2::EventLoopFlags::NonBlock if nonblock
def loop(flags : LibEvent2::EventLoopFlags) : Bool
LibEvent2.event_base_loop(@base, flags) == 0
end

Expand Down
5 changes: 3 additions & 2 deletions src/crystal/event_loop/libevent/lib_event2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ lib LibEvent2

@[Flags]
enum EventLoopFlags
Once = 0x01
NonBlock = 0x02
Once = 0x01
NonBlock = 0x02
NoExitOnEmpty = 0x04
end

@[Flags]
Expand Down

0 comments on commit 0580ff2

Please sign in to comment.