summaryrefslogtreecommitdiff
path: root/lib/webrick/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/webrick/server.rb')
-rw-r--r--lib/webrick/server.rb33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 5ada88ac73..1d87cdae70 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -172,8 +172,13 @@ module WEBrick
begin
while @status == :Running
begin
- if svrs = IO.select([shutdown_pipe[0], *@listeners], nil, nil, 2.0)
- if svrs[0].include? shutdown_pipe[0]
+ sp = shutdown_pipe[0]
+ if svrs = IO.select([sp, *@listeners], nil, nil, 2.0)
+ if svrs[0].include? sp
+ # swallow shutdown pipe
+ buf = String.new
+ nil while String ===
+ sp.read_nonblock([sp.nread, 8].max, buf, exception: false)
break
end
svrs[0].each{|svr|
@@ -221,6 +226,8 @@ module WEBrick
if @status == :Running
@status = :Shutdown
end
+
+ alarm_shutdown_pipe {|f| f.write_nonblock("\0")}
end
##
@@ -230,15 +237,7 @@ module WEBrick
def shutdown
stop
- 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
+ alarm_shutdown_pipe {|f| f.close}
end
##
@@ -343,6 +342,18 @@ module WEBrick
}
end
+ def alarm_shutdown_pipe
+ _, pipe = @shutdown_pipe # another thread may modify @shutdown_pipe.
+ if pipe
+ if !pipe.closed?
+ begin
+ yield pipe
+ rescue IOError # closed by another thread.
+ end
+ end
+ end
+ end
+
def cleanup_listener
@listeners.each{|s|
if @logger.debug?