Skip to content
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
18 changes: 18 additions & 0 deletions ext/io/event/selector/epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,25 @@ VALUE IO_Event_Selector_EPoll_wakeup(VALUE self) {
return Qfalse;
}

static int IO_Event_Selector_EPoll_supported_p(void) {
int fd = epoll_create1(EPOLL_CLOEXEC);

if (fd < 0) {
rb_warn("epoll_create1() was available at compile time but failed at run time: %s\n", strerror(errno));

return 0;
}

close(fd);

return 1;
}

void Init_IO_Event_Selector_EPoll(VALUE IO_Event_Selector) {
if (!IO_Event_Selector_EPoll_supported_p()) {
return;
}

VALUE IO_Event_Selector_EPoll = rb_define_class_under(IO_Event_Selector, "EPoll", rb_cObject);

rb_define_alloc_func(IO_Event_Selector_EPoll, IO_Event_Selector_EPoll_allocate);
Expand Down
19 changes: 19 additions & 0 deletions ext/io/event/selector/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,26 @@ VALUE IO_Event_Selector_KQueue_wakeup(VALUE self) {
return Qfalse;
}


static int IO_Event_Selector_KQueue_supported_p(void) {
int fd = kqueue();

if (fd < 0) {
rb_warn("kqueue() was available at compile time but failed at run time: %s\n", strerror(errno));

return 0;
}

close(fd);

return 1;
}

void Init_IO_Event_Selector_KQueue(VALUE IO_Event_Selector) {
if (!IO_Event_Selector_KQueue_supported_p()) {
return;
}

VALUE IO_Event_Selector_KQueue = rb_define_class_under(IO_Event_Selector, "KQueue", rb_cObject);

rb_define_alloc_func(IO_Event_Selector_KQueue, IO_Event_Selector_KQueue_allocate);
Expand Down
19 changes: 19 additions & 0 deletions ext/io/event/selector/uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,26 @@ VALUE IO_Event_Selector_URing_wakeup(VALUE self) {

#pragma mark - Native Methods

static int IO_Event_Selector_URing_supported_p(void) {
struct io_uring ring;
int result = io_uring_queue_init(32, &ring, 0);

if (result < 0) {
rb_warn("io_uring_queue_init() was available at compile time but failed at run time: %s\n", strerror(-result));

return 0;
}

io_uring_queue_exit(&ring);

return 1;
}

void Init_IO_Event_Selector_URing(VALUE IO_Event_Selector) {
if (!IO_Event_Selector_URing_supported_p()) {
return;
}

VALUE IO_Event_Selector_URing = rb_define_class_under(IO_Event_Selector, "URing", rb_cObject);

rb_define_alloc_func(IO_Event_Selector_URing, IO_Event_Selector_URing_allocate);
Expand Down
1 change: 1 addition & 0 deletions releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- `IO::Event::Profiler` is moved to dedicated gem: [fiber-profiler](https://github.com/socketry/fiber-profiler).
- Perform runtime checks for native selectors to ensure they are supported in the current environment. While compile-time checks determine availability, restrictions like seccomp and SELinux may still prevent them from working.

## v1.9.0

Expand Down
Loading