summaryrefslogtreecommitdiff
path: root/test/openssl/utils.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-01 14:53:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-01 14:53:32 +0000
commit88c37cdcc3d2947345a043c76524af7f1067e980 (patch)
treea05b790d2a1fff0bbce74ca4574474ed50cd02d7 /test/openssl/utils.rb
parent3ec72f078c207f53348809d304ba37ba5f915629 (diff)
start_server refined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/openssl/utils.rb')
-rw-r--r--test/openssl/utils.rb88
1 files changed, 42 insertions, 46 deletions
diff --git a/test/openssl/utils.rb b/test/openssl/utils.rb
index f878845354c..6a92e040c5f 100644
--- a/test/openssl/utils.rb
+++ b/test/openssl/utils.rb
@@ -267,63 +267,59 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
def start_server(port0, verify_mode, start_immediately, args = {}, &block)
IO.pipe {|stop_pipe_r, stop_pipe_w|
+ ctx_proc = args[:ctx_proc]
+ server_proc = args[:server_proc]
+ ignore_ssl_accept_error = args.fetch(:ignore_ssl_accept_error, true)
+ server_proc ||= method(:readwrite_loop)
+
+ store = OpenSSL::X509::Store.new
+ store.add_cert(@ca_cert)
+ store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.cert_store = store
+ #ctx.extra_chain_cert = [ ca_cert ]
+ ctx.cert = @svr_cert
+ ctx.key = @svr_key
+ ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
+ ctx.verify_mode = verify_mode
+ ctx_proc.call(ctx) if ctx_proc
+
+ Socket.do_not_reverse_lookup = true
+ tcps = nil
+ port = port0
begin
- ctx_proc = args[:ctx_proc]
- server_proc = args[:server_proc]
- ignore_ssl_accept_error = args.fetch(:ignore_ssl_accept_error, true)
- server_proc ||= method(:readwrite_loop)
- threads = []
-
- store = OpenSSL::X509::Store.new
- store.add_cert(@ca_cert)
- store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.cert_store = store
- #ctx.extra_chain_cert = [ ca_cert ]
- ctx.cert = @svr_cert
- ctx.key = @svr_key
- ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
- ctx.verify_mode = verify_mode
- ctx_proc.call(ctx) if ctx_proc
-
- Socket.do_not_reverse_lookup = true
- tcps = nil
- port = port0
- begin
- tcps = TCPServer.new("127.0.0.1", port)
- rescue Errno::EADDRINUSE
- port += 1
- retry
- end
+ tcps = TCPServer.new("127.0.0.1", port)
+ rescue Errno::EADDRINUSE
+ port += 1
+ retry
+ end
- ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
- ssls.start_immediately = start_immediately
+ ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
+ ssls.start_immediately = start_immediately
- begin
- server = Thread.new do
+ threads = []
+ begin
+ server = Thread.new do
+ begin
server_loop(ctx, ssls, stop_pipe_r, ignore_ssl_accept_error, server_proc, threads)
+ ensure
+ tcps.close
end
- threads.unshift server
+ end
+ threads.unshift server
- $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG
+ $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG
- th = Thread.new do
- begin
- block.call(server, port.to_i)
- ensure
- stop_pipe_w.close
- end
- end
+ client = Thread.new do
begin
- th.join
- rescue Exception
- threads.unshift th
+ block.call(server, port.to_i)
+ ensure
+ stop_pipe_w.close
end
- ensure
- assert_join_threads(threads)
end
+ threads.unshift client
ensure
- tcps.close if tcps
+ assert_join_threads(threads)
end
}
end