Skip to content
instance method

Fiber::Scheduler#io_read

io_read(io, buffer, length, offset) → read length or -errno

Invoked by IO#read or IO#Buffer.read to read length bytes from io into a specified buffer (see IO::Buffer) at the given offset.

The length argument is the “minimum length to be read”. If the IO buffer size is 8KiB, but the length is 1024 (1KiB), up to 8KiB might be read, but at least 1KiB will be. Generally, the only case where less data than length will be read is if there is an error reading the data.

Specifying a length of 0 is valid and means try reading at least once and return any available data.

Suggested implementation should try to read from io in a non-blocking manner and call io_wait if the io is not ready (which will yield control to other fibers).

See IO::Buffer for an interface available to return data.

Expected to return number of bytes read, or, in case of an error, -errno (negated number corresponding to system’s error code).

The method should be considered experimental.

See also #io_pwrite #io_select #io_pread #io_wait also in 4.1 · 3.4 · 3.3 · 3.2