ruby-changes:36143
From: akr <ko1@a...>
Date: Sat, 1 Nov 2014 20:41:39 +0900 (JST)
Subject: [ruby-changes:36143] akr:r48224 (trunk): * test/openssl/utils.rb (start_server, server_loop): Use a
akr 2014-11-01 20:41:30 +0900 (Sat, 01 Nov 2014) New Revision: 48224 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48224 Log: * test/openssl/utils.rb (start_server, server_loop): Use a pipe to stop server instead of shutdown/close a listening socket. Modified files: trunk/ChangeLog trunk/test/openssl/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48223) +++ ChangeLog (revision 48224) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Nov 1 20:40:18 2014 Tanaka Akira <akr@f...> + + * test/openssl/utils.rb (start_server, server_loop): Use a + pipe to stop server instead of shutdown/close a listening socket. + Sat Nov 1 19:24:59 2014 Tanaka Akira <akr@f...> * test/ruby/envutil.rb (assert_join_threads): New assertion to Index: test/openssl/utils.rb =================================================================== --- test/openssl/utils.rb (revision 48223) +++ test/openssl/utils.rb (revision 48224) @@ -240,10 +240,14 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L240 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+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L290 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+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L306 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+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L319 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/