Flowdock
read_nonblock(*args) public

Reads at most maxlen bytes from ios using the read(2) system call after O_NONBLOCK is set for the underlying file descriptor.

If the optional outbuf argument is present, it must reference a String, which will receive the data.

read_nonblock just calls the read(2) system call. It causes all errors the read(2) system call causes: Errno::EWOULDBLOCK, Errno::EINTR, etc. The caller should care such errors.

read_nonblock causes EOFError on EOF.

If the read buffer is not empty, read_nonblock reads from the buffer like readpartial. In this case, the read(2) system call is not called.

When read_nonblock raises EWOULDBLOCK, read_nonblock should not be called until io is readable for avoiding busy loop. This can be done as follows.

begin
  result = io.read_nonblock(maxlen)
rescue Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EINTR
  IO.select([io])
  retry
end

Note that this is identical to readpartial except the non-blocking flag is set.

Show source
Register or log in to add new notes.