diff options
Diffstat (limited to 'ext/openssl/lib/openssl/buffering.rb')
-rw-r--r-- | ext/openssl/lib/openssl/buffering.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/buffering.rb b/ext/openssl/lib/openssl/buffering.rb index 8e67fd7e8..3028fe5b5 100644 --- a/ext/openssl/lib/openssl/buffering.rb +++ b/ext/openssl/lib/openssl/buffering.rb @@ -116,6 +116,7 @@ module Buffering # # So OpenSSL::Buffering#read_nonblock needs two rescue clause as follows. # + # # emulates blocking read (readpartial). # begin # result = ssl.read_nonblock(maxlen) # rescue IO::WaitReadable @@ -249,6 +250,48 @@ module Buffering s.length end + # Writes _str_ in the non-blocking manner. + # + # If there are buffered data, it is flushed at first. + # This may block. + # + # write_nonblock returns number of bytes written to the SSL connection. + # + # When no data can be written without blocking, + # It raises OpenSSL::SSL::SSLError extended by + # IO::WaitReadable or IO::WaitWritable. + # + # IO::WaitReadable means SSL needs to read internally. + # So write_nonblock should be called again after + # underlying IO is readable. + # + # IO::WaitWritable means SSL needs to write internally. + # So write_nonblock should be called again after + # underlying IO is writable. + # + # So OpenSSL::Buffering#write_nonblock needs two rescue clause as follows. + # + # # emulates blocking write. + # begin + # result = ssl.write_nonblock(str) + # rescue IO::WaitReadable + # IO.select([io]) + # retry + # rescue IO::WaitWritable + # IO.select(nil, [io]) + # retry + # end + # + # Note that one reason that write_nonblock read from 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 + # + def write_nonblock(s) + flush + syswrite_nonblock(s) + end + def << (s) do_write(s) self |