diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-09 06:52:08 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-09 06:52:08 +0000 |
commit | 2c820137ad23bc160caae02e9197a80640c8c370 (patch) | |
tree | 87ea9fa49eccada304f1dfd117f89b1e91df2f75 | |
parent | 13b755bd8038a3d3009818bc56056218e99fe5b9 (diff) |
* lib/webrick/server.rb (WEBrick::GenericServer#start): should
restore @token if accept failure. suggested by Dominique Brezinski.
[ruby-core:04518]
I forgot it in my last commit ;)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | lib/webrick/server.rb | 34 |
2 files changed, 30 insertions, 14 deletions
@@ -1,3 +1,9 @@ +Wed Mar 9 15:46:35 2005 GOTOU Yuuzou <gotoyuzo@notwork.org> + + * lib/webrick/server.rb (WEBrick::GenericServer#start): should + restore @token if accept failure. suggested by Dominique Brezinski. + [ruby-core:04518] + Wed Mar 9 13:37:57 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * ext/tk/sample/tktextio.rb: fix bug of handling 'end' position. @@ -26,10 +32,6 @@ Tue Mar 8 01:27:00 2005 NARUSE, Yui <naruse@ruby-lang.org> Mon Mar 7 21:35:02 2005 GOTOU Yuuzou <gotoyuzo@notwork.org> - * lib/webrick/server.rb (WEBrick::GenericServer#start): should - restore @token if accept failure. suggested by Dominique Brezinski. - [ruby-core:04518] - * sample/webrick/httpsd.rb: fix typo in comment. suggested by Kazuhiko Shiozaki. diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index faa32a5db4..87a33ffaa1 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -88,17 +88,15 @@ module WEBrick if svrs = IO.select(@listeners, nil, nil, 2.0) svrs[0].each{|svr| @tokens.pop # blocks while no token is there. - sock = svr.accept - sock.sync = true - Utils::set_close_on_exec(sock) - th = start_thread(sock, &block) - th[:WEBrickThread] = true - thgroup.add(th) + if sock = accept_client(svr) + th = start_thread(sock, &block) + th[:WEBrickThread] = true + thgroup.add(th) + else + @tokens.push(nil) + end } end - rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPROTO => ex - # TCP connection was established but RST segment was sent - # from peer before calling TCPServer#accept. rescue Errno::EBADF, IOError => ex # if the listening socket was closed in GenericServer#shutdown, # IO::select raise it. @@ -140,6 +138,22 @@ module WEBrick private + def accept_client(svr) + sock = nil + begin + sock = svr.accept + sock.sync = true + Utils::set_close_on_exec(sock) + rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPROTO => ex + # TCP connection was established but RST segment was sent + # from peer before calling TCPServer#accept. + rescue Exception => ex + msg = "#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}" + @logger.error msg + end + return sock + end + def start_thread(sock, &block) Thread.start{ begin @@ -161,6 +175,7 @@ module WEBrick rescue Exception => ex @logger.error ex ensure + @tokens.push(nil) Thread.current[:WEBrickSocket] = nil if addr @logger.debug "close: #{addr[3]}:#{addr[1]}" @@ -169,7 +184,6 @@ module WEBrick end sock.close end - @tokens.push(nil) } end |