-
Notifications
You must be signed in to change notification settings - Fork 86
Description
I've noticed this gem is using rb_thread_fd_select() in
hiredis-rb/ext/hiredis_ext/connection.c
Line 94 in d62cb77
| #define _thread_fd_select(n, r, w, e, t) rb_thread_fd_select(n, r, w, e, t) |
And it's used by
hiredis-rb/ext/hiredis_ext/connection.c
Line 126 in d62cb77
| if (_thread_fd_select(fd + 1, &fds, NULL, NULL, toptr) < 0) { |
and
hiredis-rb/ext/hiredis_ext/connection.c
Line 156 in d62cb77
| if (_thread_fd_select(fd + 1, NULL, &fds, NULL, toptr) < 0) { |
to wait for a single file descriptor, either read or write.
rb_thread_fd_select() uses select(2) internally which is rather inefficient, especially with a large number of open file descriptors.
So int rb_wait_for_single_fd(int fd, int events, struct timeval *tv); seems a better fit there, and that uses poll() internally which is much more efficient.
As Ruby APIs there is also IO#wait_readable and IO#wait_writable. That's probably less easy to use from C as it takes a Float and not a struct timeval for the timeout.