diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-05-03 21:11:21 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-05-03 21:11:21 +0000 |
commit | 80079f0d94498c87293b79376935645ee13b0972 (patch) | |
tree | cef09b0b1401c4db732ffa0ccd7388b960847066 /lib/unicorn/http_response.rb | |
parent | 1eddd7ee690f967c913d8c14505f4db994876568 (diff) | |
download | unicorn-80079f0d94498c87293b79376935645ee13b0972.tar.gz |
Simpler code on our end can be just a tick faster because syscalls are still not as cheap as normal functions and this still manages to play well with our lack of keepalive support as closing the socket will flush it immediately.
Diffstat (limited to 'lib/unicorn/http_response.rb')
-rw-r--r-- | lib/unicorn/http_response.rb | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index 5480b5d..a9b5f2b 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -49,30 +49,16 @@ module Unicorn # so don't worry or care about them. # Date is required by HTTP/1.1 as long as our clock can be trusted. # Some broken clients require a "Status" header so we accomodate them - socket_write(socket, - "HTTP/1.1 #{status}\r\n" \ + socket.write("HTTP/1.1 #{status}\r\n" \ "Date: #{Time.now.httpdate}\r\n" \ "Status: #{status}\r\n" \ "Connection: close\r\n" \ "#{OUT.join(EMPTY)}\r\n") - body.each { |chunk| socket_write(socket, chunk) } - socket.close # uncorks the socket immediately + body.each { |chunk| socket.write(chunk) } + socket.close # flushes and uncorks the socket immediately ensure body.respond_to?(:close) and body.close rescue nil end - private - - # write(2) can return short on slow devices like sockets as well - # as fail with EINTR if a signal was caught. - def self.socket_write(socket, buffer) - begin - written = socket.syswrite(buffer) - return written if written == buffer.length - buffer = buffer[written..-1] - rescue Errno::EINTR - end while true - end - end end |