diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-08-26 03:05:05 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-08-26 03:05:05 +0000 |
commit | e1d9c729c172853bc54d75b59c3a95500fd8cc98 (patch) | |
tree | 60fce2f00c401acfbaa2280bc355c6fa5a26b9a9 /lib/mongrel.rb | |
parent | 45036848258cb5635e68880aa26e52a4b3e88b43 (diff) | |
download | unicorn-e1d9c729c172853bc54d75b59c3a95500fd8cc98.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@335 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib/mongrel.rb')
-rw-r--r-- | lib/mongrel.rb | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb index ca4ea12..8d0c57c 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -228,15 +228,13 @@ module Mongrel def read_body(remain, total, dispatcher) begin # write the odd sized chunk first - remain -= @body.write(@socket.read(remain % Const::CHUNK_SIZE)) + + remain -= @body.write(read_socket(remain % Const::CHUNK_SIZE)) dispatcher.request_progress(params, remain, total) if dispatcher # then stream out nothing but perfectly sized chunks until remain <= 0 or @socket.closed? - data = @socket.read(Const::CHUNK_SIZE) - # have to do it this way since @socket.eof? causes it to block - raise "Socket closed or read failure" if not data or data.length != Const::CHUNK_SIZE - remain -= @body.write(data) + remain -= @body.write(read_socket(Const::CHUNK_SIZE)) # ASSUME: we are writing to a disk and these writes always write the requested amount dispatcher.request_progress(params, remain, total) if dispatcher end @@ -250,6 +248,20 @@ module Mongrel end end + def read_socket(len) + if !@socket.closed? + data = @socket.read(len) + if !data + raise "Socket read return nil" + elsif data.length != len + raise "Socket read returned insufficient data: #{data.length}" + else + data + end + else + raise "Socket already closed when reading." + end + end # Performs URI escaping so that you can construct proper # query strings faster. Use this rather than the cgi.rb @@ -386,8 +398,9 @@ module Mongrel elsif @header_sent raise "You have already sent the request headers." else - @header.out.rewind - @body.rewind + @header.out.truncate(0) + @body.close + @body = StringIO.new end end @@ -587,7 +600,7 @@ module Mongrel end end rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF - # ignored + client.close rescue Object rescue HttpParserError if $mongrel_debug_client STDERR.puts "#{Time.now}: BAD CLIENT (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #$!" |