ruby-changes:42392
From: normal <ko1@a...>
Date: Fri, 1 Apr 2016 04:37:22 +0900 (JST)
Subject: [ruby-changes:42392] normal:r54466 (trunk): openssl: accept moving write buffer for write_nonblock
normal 2016-04-01 05:33:55 +0900 (Fri, 01 Apr 2016) New Revision: 54466 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54466 Log: openssl: accept moving write buffer for write_nonblock By setting the SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER flag. This flag was introduced at the same time as SSL_MODE_ENABLE_PARTIAL_WRITE in OpenSSL 0.9.4 and makes usage with non-blocking sockets much easier. Before this, a Rubyist would need to remember the exact object which failed to write and reuse it later when the socket became writable again. This causes problems when the buffer is given by another layer of the application (e.g. a buffer is given by a Rack middleware or application to a Rack web server). * ext/openssl/ossl_ssl.c (ossl_sslctx_s_alloc): enable SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER by default [Bug #12126] Modified files: trunk/ChangeLog trunk/ext/openssl/ossl_ssl.c trunk/test/openssl/test_pair.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 54465) +++ ChangeLog (revision 54466) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Apr 1 04:50:44 2016 Eric Wong <e@8...> + + * ext/openssl/ossl_ssl.c (ossl_sslctx_s_alloc): + enable SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER by default + [Bug #12126] + Fri Apr 1 01:13:55 2016 Benoit Daloze <eregontp@g...> * thread.c (update_coverage): Do not track coverage in loaded files Index: ext/openssl/ossl_ssl.c =================================================================== --- ext/openssl/ossl_ssl.c (revision 54465) +++ ext/openssl/ossl_ssl.c (revision 54466) @@ -145,7 +145,8 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L145 ossl_sslctx_s_alloc(VALUE klass) { SSL_CTX *ctx; - long mode = SSL_MODE_ENABLE_PARTIAL_WRITE; + long mode = SSL_MODE_ENABLE_PARTIAL_WRITE | + SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER; VALUE obj; #ifdef SSL_MODE_RELEASE_BUFFERS Index: test/openssl/test_pair.rb =================================================================== --- test/openssl/test_pair.rb (revision 54465) +++ test/openssl/test_pair.rb (revision 54466) @@ -280,6 +280,35 @@ module OpenSSL::TestPairM https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pair.rb#L280 } end + def test_write_nonblock_retry + ssl_pair {|s1, s2| + # fill up a socket so we hit EAGAIN + written = String.new + n = 0 + buf = 'a' * 11 + case ret = s1.write_nonblock(buf, exception: false) + when :wait_readable then break + when :wait_writable then break + when Integer + written << buf + n += ret + exp = buf.bytesize + if ret != exp + buf = buf.byteslice(ret, exp - ret) + end + end while true + assert_kind_of Symbol, ret + + # make more space for subsequent write: + readed = s2.read(n) + assert_equal written, readed + + # this fails if SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER is missing: + buf2 = Marshal.load(Marshal.dump(buf)) + assert_kind_of Integer, s1.write_nonblock(buf2, exception: false) + } + end + def tcp_pair host = "127.0.0.1" serv = TCPServer.new(host, 0) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/