From c7070bdc480332a73e2d6bcc5095d9d0cf40d03a Mon Sep 17 00:00:00 2001 From: gotoyuzo Date: Thu, 14 Jul 2005 23:00:22 +0000 Subject: [PATCH] * lib/webrick/server.rb (WEBrick::GenericServer#accept_client): sockets should be non-blocking mode. [ruby-dev:26405] * lib/webrick/utils.rb (WEBrick::Utils.set_non_blocking): new method. * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#read_chunked): should call sock.read repeatedly until the preferred size data is obtained. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ lib/webrick/httprequest.rb | 7 ++++++- lib/webrick/server.rb | 1 + lib/webrick/utils.rb | 8 ++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ca742938cf..57996a5efc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Jul 15 07:58:56 2005 GOTOU Yuuzou + + * lib/webrick/server.rb (WEBrick::GenericServer#accept_client): + sockets should be non-blocking mode. [ruby-dev:26405] + + * lib/webrick/utils.rb (WEBrick::Utils.set_non_blocking): new method. + + * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#read_chunked): + should call sock.read repeatedly until the preferred size data + is obtained. + Thu Jul 14 18:27:16 2005 Hirokazu Yamamoto * win32/win32.c (rb_w32_strerror): should return correct message diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index 508374adf6..a9f0c51f9d 100644 --- a/lib/webrick/httprequest.rb +++ b/lib/webrick/httprequest.rb @@ -306,7 +306,12 @@ module WEBrick def read_chunked(socket, block) chunk_size, = read_chunk_size(socket) while chunk_size > 0 - data = read_data(socket, chunk_size) # read chunk-data + data = "" + while data.size < chunk_size + tmp = read_data(socket, chunk_size-data.size) # read chunk-data + break unless tmp + data << tmp + end if data.nil? || data.size != chunk_size raise BadRequest, "bad chunk data size." end diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index 46575734c1..16dbd46f98 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -146,6 +146,7 @@ module WEBrick begin sock = svr.accept sock.sync = true + Utils::set_non_blocking(sock) Utils::set_close_on_exec(sock) rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPROTO => ex # TCP connection was established but RST segment was sent diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index 7283704c1d..cf9da6f2ce 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -18,6 +18,14 @@ end module WEBrick module Utils + def set_non_blocking(io) + flag = File::NONBLOCK + if defined?(Fcntl::F_GETFL) + flag |= io.fcntl(Fcntl::F_GETFL) + end + io.fcntl(Fcntl::F_SETFL, flag) + end + module_function :set_non_blocking def set_close_on_exec(io) if defined?(Fcntl::FD_CLOEXEC)