diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-20 17:39:44 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-20 17:39:44 +0000 |
commit | 17a085ea8cd6f5e9d5dcdacfa48ef4364b3e7025 (patch) | |
tree | 012b5baffce83aa0e150a36c588fee1060c62ff2 /ext/openssl/lib/openssl/buffering.rb | |
parent | 88db4af385823214b918d6f694370aa90a0add01 (diff) | |
download | ruby-17a085ea8cd6f5e9d5dcdacfa48ef4364b3e7025.tar.gz |
* ext/openssl/lib/openssl/buffering.rb
(OpenSSL::Buffering#write_nonblock): new method.
* ext/openssl/ossl_ssl.c (ossl_ssl_write_nonblock): new method.
(ossl_ssl_write_internal): defined.
(ossl_ssl_write): use ossl_ssl_write_internal.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 8e67fd7e83..3028fe5b52 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 |