Skip to content

Commit

Permalink
Add :evloop_epoll and :evloop_kqueue flags + opt-in on some targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Nov 4, 2024
1 parent b14fa3c commit b4c192e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/crystal/system/event_loop.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ abstract class Crystal::EventLoop
{% if flag?(:wasi) %}
Crystal::Wasi::EventLoop.new
{% elsif flag?(:unix) %}
{% if flag?(:evloop_libevent) %}
# TODO: dragonfly: the kqueue evloop hasn't been tested
# TODO: netbsd: the kqueue evloop doesn't work (needs investigation)
# TODO: openbsd: the kqueue evloop is magnitudes slower (needs investigation)
# TODO: solaris: the epoll evloop hasn't been tested (better: use event-ports)
{% if flag?(:evloop_libevent) || flag?(:dragonfly) || flag?(:netbsd) || flag?(:openbsd) || flag?(:solaris) %}
Crystal::LibEvent::EventLoop.new
{% elsif flag?(:android) || flag?(:linux) || flag?(:solaris) %}
{% elsif flag?(:evloop_epoll) || flag?(:android) || flag?(:linux) %}
Crystal::Epoll::EventLoop.new
{% elsif flag?(:bsd) || flag?(:darwin) %}
{% elsif flag?(:evloop_kqueue) || flag?(:darwin) || flag?(:freebsd) %}
Crystal::Kqueue::EventLoop.new
{% else %}
Crystal::LibEvent::EventLoop.new
{% raise "Event loop not supported" %}
{% end %}
{% elsif flag?(:win32) %}
Crystal::IOCP::EventLoop.new
Expand Down Expand Up @@ -86,14 +90,14 @@ end
{% if flag?(:wasi) %}
require "./wasi/event_loop"
{% elsif flag?(:unix) %}
{% if flag?(:evloop_libevent) %}
{% if flag?(:evloop_libevent) || flag?(:dragonfly) || flag?(:netbsd) || flag?(:openbsd) || flag?(:solaris) %}
require "./unix/event_loop_libevent"
{% elsif flag?(:android) || flag?(:linux) || flag?(:solaris) %}
{% elsif flag?(:evloop_epoll) || flag?(:android) || flag?(:linux) %}
require "./unix/epoll/event_loop"
{% elsif flag?(:bsd) || flag?(:darwin) %}
{% elsif flag?(:evloop_kqueue) || flag?(:darwin) || flag?(:freebsd) %}
require "./unix/kqueue/event_loop"
{% else %}
require "./unix/event_loop_libevent"
{% raise "Event loop not supported" %}
{% end %}
{% elsif flag?(:win32) %}
require "./win32/event_loop_iocp"
Expand Down
2 changes: 1 addition & 1 deletion src/io/evented.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% skip_file unless flag?(:evloop_libevent) || flag?(:wasi) %}
{% skip_file unless flag?(:evloop_libevent) || flag?(:wasi) || flag?(:dragonfly) || flag?(:netbsd) || flag?(:openbsd) || flag?(:solaris) %}

require "crystal/thread_local_value"

Expand Down

0 comments on commit b4c192e

Please sign in to comment.