Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change libevent event loop to wait forever when blocking #15243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading