Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)
|
Public APIs to provide rb_fd_select(). More...
#include "ruby/internal/config.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/intern/select/posix.h"
Go to the source code of this file.
Macros | |
#define | rb_fd_resize(n, f) |
Does nothing (defined for compatibility). |
Functions | |
int | rb_thread_fd_select (int nfds, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout) |
Waits for multiple file descriptors at once. |
Public APIs to provide rb_fd_select().
Definition in file select.h.
#define rb_fd_resize | ( | n, | |
f ) |
int rb_thread_fd_select | ( | int | nfds, |
rb_fdset_t * | rfds, | ||
rb_fdset_t * | wfds, | ||
rb_fdset_t * | efds, | ||
struct timeval * | timeout ) |
Waits for multiple file descriptors at once.
This is basically a wrapper of system-provided select() with releasing GVL, to allow other Ruby threads run in parallel.
[in] | nfds | Max FD in everything passed, plus one. |
[in,out] | rfds | Set of FDs to wait for reads. |
[in,out] | wfds | Set of FDs to wait for writes. |
[in,out] | efds | Set of FDs to wait for OOBs. |
[in,out] | timeout | Max blocking duration. |
-1 | Failed, errno set. |
0 | Timeout exceeded. |
otherwise | Total number of file descriptors returned. |
Although backend threads can run in parallel of this function, touching a file descriptor from multiple threads could be problematic. For instance what happens when a thread closes a file descriptor that is selected by someone else, vastly varies among operating systems. You would better avoid touching an fd from more than one threads.
Definition at line 4335 of file thread.c.
Referenced by rb_thread_fd_select().