This is a Ruby tree! It shows every object from the Ruby Programming Language in a tree format.

read_nonblock

        # IO.read_nonblock

(from ruby core)
---
    ios.read_nonblock(maxlen [, options])              -> string
    ios.read_nonblock(maxlen, outbuf [, options])      -> outbuf

---

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. The *outbuf* will contain only the
received data after the method call even if it is not empty at the
beginning.

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.

If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended
by IO::WaitReadable. So IO::WaitReadable can be used to rescue the
exceptions for retrying read_nonblock.

read_nonblock causes EOFError on EOF.

On some platforms, such as Windows, non-blocking mode is not supported
on IO objects other than sockets. In such cases, Errno::EBADF will be
raised.

If the read byte 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 an exception kind of IO::WaitReadable,
read_nonblock should not be called until io is readable for avoiding
busy loop. This can be done as follows.

    # emulates blocking read (readpartial).
    begin
      result = io.read_nonblock(maxlen)
    rescue IO::WaitReadable
      IO.select([io])
      retry
    end

Although IO#read_nonblock doesn't raise IO::WaitWritable.
OpenSSL::Buffering#read_nonblock can raise IO::WaitWritable. If IO and
SSL should be used polymorphically, IO::WaitWritable should be rescued
too. See the document of OpenSSL::Buffering#read_nonblock for sample
code.

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

By specifying a keyword argument *exception* to `false`, you can
indicate that read_nonblock should not raise an IO::WaitReadable
exception, but return the symbol `:wait_readable` instead. At EOF, it
will return nil instead of raising EOFError.



      

This is MURDOC! A Ruby documentation browser inspired by Smalltalk-80. It allows you to learn about Ruby by browsing through its class hierarchies, and see any of its methods.