Skip to content

rb_wait_for_single_fd() should probably be used instead of rb_thread_fd_select() #90

@eregon

Description

@eregon

I've noticed this gem is using rb_thread_fd_select() in

#define _thread_fd_select(n, r, w, e, t) rb_thread_fd_select(n, r, w, e, t)

And it's used by
if (_thread_fd_select(fd + 1, &fds, NULL, NULL, toptr) < 0) {

and
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions