new_file: delay keepalive sockopts until read
authorEric Wong <normalperson@yhbt.net>
Wed, 24 Oct 2012 08:13:13 +0000 (24 08:13 +0000)
committerEric Wong <normalperson@yhbt.net>
Wed, 24 Oct 2012 08:19:36 +0000 (24 08:19 +0000)
We don't need to set socket keepalive until we've successfully
written the request out and are awaiting a response.

lib/mogilefs/http_file.rb
lib/mogilefs/new_file/common.rb
lib/mogilefs/new_file/stream.rb

index c96e695..85b4578 100644 (file)
@@ -95,7 +95,6 @@ class MogileFS::HTTPFile < StringIO
   # returns file size if the socket finished writing
   def upload(devid, uri) # :nodoc:
     sock = MogileFS::Socket.tcp(uri.host, uri.port)
-    set_socket_options(sock)
     file_size = length
 
     if @streaming_io
index 9b6511d..1d2b1a0 100644 (file)
@@ -21,6 +21,7 @@ module MogileFS::NewFile::Common
   def read_response(sock)
     tout = @opts[:new_file_max_time] || 3600.0
     start_time = @opts[:start_time] and tout -= Time.now - start_time
+    set_socket_options(sock)
     case line = sock.timed_read(23, "", tout > 0.0 ? tout : 0)
     when %r{^HTTP/\d\.\d\s+(2\d\d)\s} # success!
     when nil
index b2253f0..32bd339 100644 (file)
@@ -18,7 +18,6 @@ class MogileFS::NewFile::Stream
       begin
         uri = URI.parse(path)
         sock = MogileFS::Socket.tcp(uri.host, uri.port)
-        set_socket_options(sock)
         start_sock(sock, uri) # raise on errors
         @to_io = sock
         @uri = uri