about summary refs log tree commit homepage
path: root/lib/mongrel.rb
diff options
context:
space:
mode:
authorzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-05-14 23:42:19 +0000
committerzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-05-14 23:42:19 +0000
commitc6eaee2caa2318a009e91372afec6704c290fd22 (patch)
treec93b985baa58ae63c55dab757139b5f94d815e56 /lib/mongrel.rb
parentbe6f59478e1545f63ac7a265b7cb02e8df66f5ba (diff)
downloadunicorn-c6eaee2caa2318a009e91372afec6704c290fd22.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@180 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib/mongrel.rb')
-rw-r--r--lib/mongrel.rb24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 6063baa..edf5d4d 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -377,7 +377,7 @@ module Mongrel
         if @socket.respond_to? :sendfile
           @socket.sendfile(f)
         else
-          while chunk = f.read(Const::CHUNK_SIZE)
+          while chunk = f.read(Const::CHUNK_SIZE) and chunk.length > 0
             @socket.write(chunk)
           end
         end
@@ -467,12 +467,16 @@ module Mongrel
       begin
         parser = HttpParser.new
         params = {}
-
+        
         data = client.readpartial(Const::CHUNK_SIZE)
-
-        while true
-          nread = parser.execute(params, data)
-
+        nparsed = 0
+        
+        # Assumption: nparsed will always be less since data will get filled with more
+        # after each parsing.  If it doesn't get more then there was a problem
+        # with the read operation on the client socket.
+        while nparsed < data.length
+          nparsed = parser.execute(params, data, nparsed)
+          
           if parser.finished?
             script_name, path_info, handlers = @classifier.resolve(params[Const::REQUEST_URI])
 
@@ -481,7 +485,7 @@ module Mongrel
               params[Const::SCRIPT_NAME] = script_name
               params[Const::REMOTE_ADDR] = params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last
               
-              request = HttpRequest.new(params, data[nread ... data.length] || "", client)
+              request = HttpRequest.new(params, data[nparsed ... data.length] || "", client)
               
               # in the case of large file uploads the user could close the socket, so skip those requests
               break if request.body == nil
@@ -503,14 +507,10 @@ module Mongrel
           
             break #done
           else
-            # gotta stream and read again until we can get the parser to be character safe
-            # TODO: make this more efficient since this means we're parsing a lot repeatedly
+            data << client.readpartial(Const::CHUNK_SIZE)
             if data.length >= Const::MAX_HEADER
               raise HttpParserError.new("HEADER is longer than allowed, aborting client early.")
             end
-            
-            parser.reset
-            data << client.readpartial(Const::CHUNK_SIZE)
           end
         end
       rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF