[Mongrel] recv vs. read in HTTPRequest#read_socket

Erik Hetzner erik.hetzner at ucop.edu
Mon Feb 5 17:16:44 EST 2007


Hello all,

The following change to Mongrel::HttpRequest:

def read_socket(len)
  if !@socket.closed?
    data = @socket.recv(len) # <--- formerly @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

seems to work for me, and vastly improves the speed of the body
processing (quick tests reveal that using IO#read takes about 1 min 40
secs. and using Socket#recv takes about 9 secs on an 8.5 mb file). I
have been having trouble discovering the difference between read &
recv (I am not a socket developer by any means). Can anybody tell me
what sort of safety one loses by doing this with recv instead of read?
Thanks.

best,
Erik Hetzner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20070205/29ccc59c/attachment.bin 


More information about the Mongrel-users mailing list