diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-05-03 22:10:54 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-05-03 22:10:54 +0000 |
commit | a5c51c33862580674c997be91dc705c2cf000a36 (patch) | |
tree | c753cc06a095988bd75d84f4a93b7ccc870cb143 /lib/unicorn/http_request.rb | |
parent | 80079f0d94498c87293b79376935645ee13b0972 (diff) | |
download | unicorn-a5c51c33862580674c997be91dc705c2cf000a36.tar.gz |
readpartial is actually as low-level as sysread is, except it's less likely to throw exceptions and won't change the blocking/non-blocking status of a file descriptor (we explicitly enable blocking I/O)
Diffstat (limited to 'lib/unicorn/http_request.rb')
-rw-r--r-- | lib/unicorn/http_request.rb | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index a51e029..e786d79 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -76,15 +76,15 @@ module Unicorn TCPSocket === socket ? socket.peeraddr.last : LOCALHOST # short circuit the common case with small GET requests first - PARSER.execute(PARAMS, read_socket(socket)) and + PARSER.execute(PARAMS, socket.readpartial(Const::CHUNK_SIZE, BUFFER)) and return handle_body(socket) - data = BUFFER.dup # read_socket will clobber BUFFER + data = BUFFER.dup # socket.readpartial will clobber BUFFER # 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 - data << read_socket(socket) + data << socket.readpartial(Const::CHUNK_SIZE, BUFFER) PARSER.execute(PARAMS, data) and return handle_body(socket) end while true rescue HttpParserError => e @@ -141,7 +141,7 @@ module Unicorn def read_body(socket, remain, body) while remain > 0 # writes always write the requested amount on a POSIX filesystem - remain -= body.syswrite(read_socket(socket)) + remain -= body.syswrite(socket.readpartial(Const::CHUNK_SIZE, BUFFER)) end rescue Object => e @logger.error "Error reading HTTP body: #{e.inspect}" @@ -153,14 +153,5 @@ module Unicorn raise e end - # read(2) on "slow" devices like sockets can be interrupted by signals - def read_socket(socket) - begin - socket.sysread(Const::CHUNK_SIZE, BUFFER) - rescue Errno::EINTR - retry - end - end - end end |