From a7c425cbf32f70b53caa178f1f16cec168ecb456 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 1 Nov 2014 11:41:30 +0000 Subject: * test/openssl/utils.rb (start_server, server_loop): Use a pipe to stop server instead of shutdown/close a listening socket. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/openssl/utils.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'test/openssl/utils.rb') diff --git a/test/openssl/utils.rb b/test/openssl/utils.rb index 4df14056e4..42a119309e 100644 --- a/test/openssl/utils.rb +++ b/test/openssl/utils.rb @@ -240,10 +240,14 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC ssl.close rescue nil end - def server_loop(ctx, ssls, server_proc, threads) + def server_loop(ctx, ssls, stop_pipe_r, server_proc, threads) loop do ssl = nil begin + readable, = IO.select([ssls, stop_pipe_r]) + if readable.include? stop_pipe_r + return + end ssl = ssls.accept rescue OpenSSL::SSL::SSLError retry @@ -286,13 +290,15 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC retry end + stop_pipe_r, stop_pipe_w = IO.pipe + ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx) ssls.start_immediately = start_immediately begin server = Thread.new do Thread.current.abort_on_exception = true - server_loop(ctx, ssls, server_proc, threads) + server_loop(ctx, ssls, stop_pipe_r, server_proc, threads) end $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG @@ -300,14 +306,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC block.call(server, port.to_i) ensure begin - begin - tcps.shutdown - rescue Errno::ENOTCONN - # when `Errno::ENOTCONN: Socket is not connected' on some platforms, - # call #close instead of #shutdown. - tcps.close - tcps = nil - end if (tcps) + stop_pipe_w.close if (server) server.join(5) if server.alive? @@ -320,9 +319,9 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC end end ensure - threads.each {|th| - th.join - } + stop_pipe_r.close if !stop_pipe_r.closed? + stop_pipe_w.close if !stop_pipe_w.closed? + assert_join_threads(threads) end def starttls(ssl) -- cgit v1.2.3