Project

General

Profile

Feature #12085

Updated by normalperson (Eric Wong) over 4 years ago

* ext/openssl/lib/openssl/buffering.rb (write_nonblock): 
   (read_nonblock, write_nonblock): document `exception: false' keyword and warn about retrying 
   the using the same object. 

 Updated v2 The following test patch illustrates the problem I encountered: 

 ```diff 
 --- a/test/openssl/test_pair.rb 
 +++ b/test/openssl/test_pair.rb 
 @@ -280,6 +280,33 @@ def test_write_nonblock_with_buffered_data_no_exceptions 
      } 
    end 

 +    def test_write_nonblock_retry 
 +      ssl_pair {|s1, s2| 
 +        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 
 +        readed = s2.read(n) 
 +        assert_equal written, readed 
 +        assert_kind_of Symbol, ret 
 +        buf2 = Marshal.load(Marshal.dump(buf)) 
 +        assert_raise(OpenSSL::SSL::SSLError) do 
 +          s1.write_nonblock(buf2, exception: false) 
 +        end 
 +        assert_kind_of Integer, s1.write_nonblock(buf, exception: false) 
 +      } 
 +    end 
 + 
    def tcp_pair 
      host = "127.0.0.1" 
      serv = TCPServer.new(host, 0) 
 ~~~ 

 I do not plan to commit the test change since [Bug #12126] is split out. OpenSSL behavior 
 Also updated for read_nonblock. 
 may be improved in the future. 

Back