Skip to content

Commit

Permalink
Better handling of timeout in rb_io_maybe_wait_*.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 14, 2024
1 parent 37b0905 commit 16f4667
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions include/ruby/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,16 @@ VALUE rb_io_maybe_wait(int error, VALUE io, VALUE events, VALUE timeout);
* passed errno. This is a special case of rb_io_maybe_wait() that only
* concerns for reading.
*
* If you do not want the default timeout handling, consider using
* ::rb_io_maybe_wait directly.
*
* @param[in] error System errno.
* @param[in] io An IO object to wait.
* @param[in] timeout Time, or numeric seconds since UNIX epoch.
* @exception rb_eIOError `io` is not open.
* @exception rb_eRangeError `timeout` is out of range.
* @exception rb_eSystemCallError `select(2)` failed for some reason.
* @retval 0 Operation timed out.
* @exception rb_eIOTimeoutError The wait operation timed out.
* @retval Otherwise Always returns ::RUBY_IO_READABLE.
*/
int rb_io_maybe_wait_readable(int error, VALUE io, VALUE timeout);
Expand All @@ -1001,13 +1004,16 @@ int rb_io_maybe_wait_readable(int error, VALUE io, VALUE timeout);
* passed errno. This is a special case of rb_io_maybe_wait() that only
* concernsfor writing.
*
* If you do not want the default timeout handling, consider using
* ::rb_io_maybe_wait directly.
*
* @param[in] error System errno.
* @param[in] io An IO object to wait.
* @param[in] timeout Time, or numeric seconds since UNIX epoch.
* @exception rb_eIOError `io` is not open.
* @exception rb_eRangeError `timeout` is out of range.
* @exception rb_eSystemCallError `select(2)` failed for some reason.
* @retval 0 Operation timed out.
* @exception rb_eIOTimeoutError The wait operation timed out.
* @retval Otherwise Always returns ::RUBY_IO_WRITABLE.
*/
int rb_io_maybe_wait_writable(int error, VALUE io, VALUE timeout);
Expand Down
4 changes: 2 additions & 2 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ rb_io_maybe_wait_readable(int error, VALUE io, VALUE timeout)
return RB_NUM2INT(result);
}
else {
return 0;
rb_raise(rb_eIOTimeoutError, "Timed out waiting for IO to become readable!");
}
}

Expand All @@ -1642,7 +1642,7 @@ rb_io_maybe_wait_writable(int error, VALUE io, VALUE timeout)
return RB_NUM2INT(result);
}
else {
return 0;
rb_raise(rb_eIOTimeoutError, "Timed out waiting for IO to become writable!");
}
}

Expand Down

0 comments on commit 16f4667

Please sign in to comment.