From: GOTOU Yuuzou Date: 2004-11-23T09:19:23+09:00 Subject: Re: fast shutdown of webrick Hi, In message <41A26F33.4030303@email.byu.edu>, `Jamis Buck ' wrote: > I *suspect* that this has something to do with the browser keeping the > connection to WEBrick alive. Perhaps WEBrick can't shut down as long as > there is an active connection, and it has to wait for that connection to > time out? Can anyone comment on how feasible this might be? The attached patch adds a hook to wait till a request arrives. But I don't know whether "io/wait" is usable on every platform. BTW, the keep-alive feature is disabled when the following parameter is given. :HTTPVersion => WEBrick::HTTPVersion.new("1.0") -- gotoyuzo Index: lib/webrick/httpserver.rb =================================================================== RCS file: /var/cvs/src/ruby/lib/webrick/httpserver.rb,v retrieving revision 1.8 diff -u -p -F^[^A-Za-z0-9_+-]*\(class\|module\|def\)[^A-Za-z0-9_+-] -r1.8 httpserver.rb --- lib/webrick/httpserver.rb 21 Mar 2004 13:17:24 -0000 1.8 +++ lib/webrick/httpserver.rb 22 Nov 2004 23:47:05 -0000 @@ -15,6 +15,7 @@ require 'webrick/httprequest' require 'webrick/httpresponse' require 'webrick/httpservlet' require 'webrick/accesslog' +require 'io/wait' module WEBrick class HTTPServerError < ServerError; end @@ -46,6 +47,13 @@ def run(sock) req = HTTPRequest.new(@config) server = self begin + timeout = @config[:RequestTimeout] + while timeout > 0 + break if sock.wait(0.5) + timeout = 0 if @status != :Running + timeout -= 0.5 + end + raise HTTPStatus::EOFError if timeout <= 0 req.parse(sock) res.request_method = req.request_method res.request_uri = req.request_uri