diff options
| author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-14 23:00:22 +0000 |
|---|---|---|
| committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-14 23:00:22 +0000 |
| commit | 446e03f09762d01e5547acc7363e9892d84d311d (patch) | |
| tree | 1c48728f5855a463fb756f289c56b7f9228d0176 /lib | |
| parent | db15f1322e0fe7def39c65fff0eff61a50e35fad (diff) | |
| download | ruby-446e03f09762d01e5547acc7363e9892d84d311d.tar.gz ruby-446e03f09762d01e5547acc7363e9892d84d311d.tar.xz ruby-446e03f09762d01e5547acc7363e9892d84d311d.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/webrick/httprequest.rb | 7 | ||||
| -rw-r--r-- | lib/webrick/server.rb | 1 | ||||
| -rw-r--r-- | lib/webrick/utils.rb | 8 |
3 files changed, 15 insertions, 1 deletions
diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index 508374adf..a9f0c51f9 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 46575734c..16dbd46f9 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 7283704c1..cf9da6f2c 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) |
