read_nonblock
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180 (0)
- 1_9_3_125 (5)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (38)
- 2_5_5 (12)
- 2_6_3 (0)
- What's this?
read_nonblock(maxlen, buf=nil)
public
Reads at most maxlen bytes in the non-blocking manner.
When no data can be read without blocking, It raises OpenSSL::SSL::SSLError extended by IO::WaitReadable or IO::WaitWritable.
IO::WaitReadable means SSL needs to read internally. So read_nonblock should be called again after underlying IO is readable.
IO::WaitWritable means SSL needs to write internally. So read_nonblock should be called again after underlying IO is writable.
So OpenSSL::Buffering#read_nonblock needs two rescue clause as follows.
# emulates blocking read (readpartial). begin
result = ssl.read_nonblock(maxlen)
rescue IO::WaitReadable
IO.select([io]) retry
rescue IO::WaitWritable
IO.select(nil, [io]) retry
end
Note that one reason that read_nonblock write to a underlying IO is the peer requests a new TLS/SSL handshake. See openssl FAQ for more details. http://www.openssl.org/support/faq.html