Issue #5138 has been updated by Charles Nutter.


Charles Nutter wrote:
> JRuby master (1.7.4) now has a new ext io/try_nonblock that implements just the IO portion of wycats's patch (I did not implement the StringIO and SSLSocket logic).

Just closing the circle here... JRuby 9000 will remove the hidden io/try_nonblock (which we never *really* intended to ship). It's ok, though...we'll ship support for the :exception option.

Carry on!

----------------------------------------
Feature #5138: Add nonblocking IO that does not use exceptions for EOF and EWOULDBLOCK
https://bugs.ruby-lang.org/issues/5138#change-46969

* Author: Yehuda Katz
* Status: Closed
* Priority: Normal
* Assignee: Aaron Patterson
* Category: core
* Target version: next minor
----------------------------------------
The current Ruby I/O classes have non-blocking methods (read_nonblock and write_nonblock). These methods will never block, and if they would block, they raise an exception instead (IO::WaitReadable or IO::WaitWritable). In addition, if the IO is at EOF, they raise an EOFError.

These exceptions are raised repeatedly in virtually every use of the non-blocking methods. This patch adds a pair of methods (try_read_nonblock and try_write_nonblock) that have the same semantics as the existing methods, but they return Symbols instead of raising exceptions for these routine cases:

* :read_would_block
* :write_would_block
* :eof

The patch contains updates for IO, StringIO, and OpenSSL. The updates are fully documented and tested.

---Files--------------------------------
try_nonblock.diff (19.8 KB)
try_nonblock.diff (20.3 KB)
try_nonblock.diff (20.2 KB)
noname (500 Bytes)
noname (500 Bytes)
feature5138.pdf (38.2 KB)
noname (500 Bytes)
nonblock_no_tuple.patch (20.3 KB)
nonblock_tuple.patch (21.9 KB)


-- 
https://bugs.ruby-lang.org/