about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-05 23:34:39 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-05 23:37:44 +0000
commitd4c898a4adc6cb6c3a20a648ae6b9b6a226066a6 (patch)
tree6c38ba546dce2ecdca0d54cf87d4396fedcd6ad6
parent80f9987581014d694b8eb67bba0d5c408b7d0f98 (diff)
downloadunicorn-d4c898a4adc6cb6c3a20a648ae6b9b6a226066a6.tar.gz
This provides the kgio_read! method which is like readpartial,
only significantly cheaper when a client disconnects on us.
-rw-r--r--lib/unicorn/http_request.rb4
-rwxr-xr-xscript/isolate_for_tests2
-rw-r--r--test/unit/test_request.rb4
-rw-r--r--unicorn.gemspec2
4 files changed, 8 insertions, 4 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index 7519170..13e9900 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -64,11 +64,11 @@ class Unicorn::HttpRequest
     @env[REMOTE_ADDR] = socket.kgio_addr
 
     # short circuit the common case with small GET requests first
-    if @parser.headers(@env, socket.readpartial(16384, @buf)).nil?
+    if @parser.headers(@env, socket.kgio_read!(16384, @buf)).nil?
       # Parser is not done, queue up more data to read and continue parsing
       # an Exception thrown from the PARSER will throw us out of the loop
       begin
-        @buf << socket.readpartial(16384)
+        @buf << socket.kgio_read!(16384)
       end while @parser.headers(@env, @buf).nil?
     end
     @env[RACK_INPUT] = 0 == @parser.content_length ?
diff --git a/script/isolate_for_tests b/script/isolate_for_tests
index ac856a0..7b2ee77 100755
--- a/script/isolate_for_tests
+++ b/script/isolate_for_tests
@@ -17,7 +17,7 @@ opts = {
 pid = fork do
   Isolate.now!(opts) do
     gem 'sqlite3-ruby', '1.2.5'
-    gem 'kgio', '1.1.0'
+    gem 'kgio', '1.2.0'
     gem 'rack', '1.1.0'
   end
 end
diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb
index 5ac511f..67ac1b9 100644
--- a/test/unit/test_request.rb
+++ b/test/unit/test_request.rb
@@ -11,6 +11,7 @@ class RequestTest < Test::Unit::TestCase
 
   class MockRequest < StringIO
     alias_method :readpartial, :sysread
+    alias_method :kgio_read!, :sysread
     alias_method :read_nonblock, :sysread
     def kgio_addr
       '127.0.0.1'
@@ -167,6 +168,9 @@ class RequestTest < Test::Unit::TestCase
       readpartial(*args)
     rescue EOFError
     end
+    def client.kgio_read!(*args)
+      readpartial(*args)
+    end
     client.syswrite(
       "PUT / HTTP/1.1\r\n" \
       "Host: foo\r\n" \
diff --git a/unicorn.gemspec b/unicorn.gemspec
index cb155e9..a2eaa6e 100644
--- a/unicorn.gemspec
+++ b/unicorn.gemspec
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
   # commented out.  Nevertheless, upgrading to Rails 2.3.4 or later is
   # *strongly* recommended for security reasons.
   s.add_dependency(%q<rack>)
-  s.add_dependency(%q<kgio>, '~> 1.1.0')
+  s.add_dependency(%q<kgio>, '~> 1.2.0')
 
   s.add_development_dependency('isolate', '~> 2.0.2')