[前][次][番号順一覧][スレッド一覧]

ruby-changes:36147

From: akr <ko1@a...>
Date: Sat, 1 Nov 2014 23:53:38 +0900 (JST)
Subject: [ruby-changes:36147] akr:r48228 (trunk): start_server refined.

akr	2014-11-01 23:53:32 +0900 (Sat, 01 Nov 2014)

  New Revision: 48228

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48228

  Log:
    start_server refined.

  Modified files:
    trunk/test/openssl/utils.rb
Index: test/openssl/utils.rb
===================================================================
--- test/openssl/utils.rb	(revision 48227)
+++ test/openssl/utils.rb	(revision 48228)
@@ -267,63 +267,59 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L267
 
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]