mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/openssl/ossl_ssl.c (write_would_block): defined.
(read_would_block): defined. (ossl_start_ssl): add nonblock argument. (ossl_ssl_connect): follow ossl_start_ssl change. (ossl_ssl_connect_nonblock): new method. (ossl_ssl_accept): follow ossl_start_ssl change. (ossl_ssl_accept_nonblock): new method. (ossl_ssl_read_internal): use write_would_block and read_would_block. (ossl_ssl_write_internal): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f65d706529
commit
7fd155cf0f
4 changed files with 126 additions and 24 deletions
|
@ -192,6 +192,62 @@ class OpenSSL::TestPair < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_connect_accept_nonblock
|
||||
host = "127.0.0.1"
|
||||
port = 0
|
||||
ctx = OpenSSL::SSL::SSLContext.new()
|
||||
ctx.ciphers = "ADH"
|
||||
serv = TCPServer.new(host, port)
|
||||
ssls = OpenSSL::SSL::SSLServer.new(serv, ctx)
|
||||
|
||||
port = serv.connect_address.ip_port
|
||||
|
||||
sock1 = TCPSocket.new(host, port)
|
||||
sock2 = serv.accept
|
||||
serv.close
|
||||
|
||||
th = Thread.new {
|
||||
s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx)
|
||||
s2.sync_close = true
|
||||
begin
|
||||
sleep 0.2
|
||||
s2.accept_nonblock
|
||||
rescue IO::WaitReadable
|
||||
IO.select([s2])
|
||||
retry
|
||||
rescue IO::WaitWritable
|
||||
IO.select(nil, [s2])
|
||||
retry
|
||||
end
|
||||
s2
|
||||
}
|
||||
|
||||
sleep 0.1
|
||||
ctx = OpenSSL::SSL::SSLContext.new()
|
||||
ctx.ciphers = "ADH"
|
||||
s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx)
|
||||
begin
|
||||
sleep 0.2
|
||||
s1.connect_nonblock
|
||||
rescue IO::WaitReadable
|
||||
IO.select([s1])
|
||||
retry
|
||||
rescue IO::WaitWritable
|
||||
IO.select(nil, [s1])
|
||||
retry
|
||||
end
|
||||
s1.sync_close = true
|
||||
|
||||
s2 = th.value
|
||||
|
||||
s1.print "a\ndef"
|
||||
assert_equal("a\n", s2.gets)
|
||||
ensure
|
||||
serv.close if serv && !serv.closed?
|
||||
sock1.close if sock1 && !sock1.closed?
|
||||
sock2.close if sock2 && !sock2.closed?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue