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

ruby-changes:36274

From: akr <ko1@a...>
Date: Mon, 10 Nov 2014 12:46:30 +0900 (JST)
Subject: [ruby-changes:36274] akr:r48355 (trunk): * lib/webrick/server.rb: Less instance variables.

akr	2014-11-10 12:46:22 +0900 (Mon, 10 Nov 2014)

  New Revision: 48355

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

  Log:
    * lib/webrick/server.rb: Less instance variables.

  Modified files:
    trunk/ChangeLog
    trunk/lib/webrick/server.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48354)
+++ ChangeLog	(revision 48355)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Nov 10 12:44:39 2014  Tanaka Akira  <akr@f...>
+
+	* lib/webrick/server.rb: Less instance variables.
+
 Mon Nov 10 12:19:43 2014  Tanaka Akira  <akr@f...>
 
 	* lib/webrick/server.rb (shutdown): Use close() on @shutdown_pipe_w to
Index: lib/webrick/server.rb
===================================================================
--- lib/webrick/server.rb	(revision 48354)
+++ lib/webrick/server.rb	(revision 48355)
@@ -106,7 +106,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L106
       @logger.info("ruby #{rubyv}")
 
       @listeners = []
-      @shutdown_pipe_r = @shutdown_pipe_w = nil
+      @shutdown_pipe = nil
       unless @config[:DoNotListen]
         if @config[:Listen]
           warn(":Listen option is deprecated; use GenericServer#listen")
@@ -115,7 +115,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L115
         if @config[:Port] == 0
           @config[:Port] = @listeners[0].addr[1]
         end
-        @shutdown_pipe_r, @shutdown_pipe_w = IO.pipe
+        @shutdown_pipe = IO.pipe
       end
     end
 
@@ -164,13 +164,15 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L164
           "#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
         call_callback(:StartCallback)
 
+        shutdown_pipe = @shutdown_pipe
+
         thgroup = ThreadGroup.new
         @status = :Running
         begin
           while @status == :Running
             begin
-              if svrs = IO.select([@shutdown_pipe_r, *@listeners], nil, nil, 2.0)
-                if svrs[0].include? @shutdown_pipe_r
+              if svrs = IO.select([shutdown_pipe[0], *@listeners], nil, nil, 2.0)
+                if svrs[0].include? shutdown_pipe[0]
                   break
                 end
                 svrs[0].each{|svr|
@@ -197,7 +199,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L199
             end
           end
         ensure
-          cleanup_shutdown_pipe
+          cleanup_shutdown_pipe(shutdown_pipe)
           cleanup_listener
           @status = :Shutdown
           @logger.info "going to shutdown ..."
@@ -225,11 +227,13 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L227
     def shutdown
       stop
 
-      shutdown_pipe_w = @shutdown_pipe_w # another thread may modify @shutdown_pipe_w.
-      if shutdown_pipe_w && !shutdown_pipe_w.closed?
-        begin
-          shutdown_pipe_w.close
-        rescue IOError # closed by another thread.
+      shutdown_pipe = @shutdown_pipe # another thread may modify @shutdown_pipe.
+      if shutdown_pipe
+        if !shutdown_pipe[1].closed?
+          begin
+            shutdown_pipe[1].close
+          rescue IOError # closed by another thread.
+          end
         end
       end
     end
@@ -317,13 +321,16 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L321
       end
     end
 
-    def cleanup_shutdown_pipe
-      @shutdown_pipe_r.close
-      begin
-        @shutdown_pipe_w.close
-      rescue IOError # another thread closed @shutdown_pipe_w.
-      end
-      @shutdown_pipe_r = @shutdown_pipe_w = nil
+    def cleanup_shutdown_pipe(shutdown_pipe)
+      @shutdown_pipe = nil
+      shutdown_pipe.each {|io|
+        if !io.closed?
+          begin
+            io.close
+          rescue IOError # another thread closed io.
+          end
+        end
+      }
     end
 
     def cleanup_listener

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

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