about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-07 23:17:41 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-07 23:17:41 +0000
commit9bcff8f08dc084b880ef978c890a2706a1bbb304 (patch)
tree5b8d48eb8fbdf3465cbfaff2461bcf2046a6326b
parenta603d3231683096085841ae6f0ba96eeb27171a3 (diff)
downloadmogilefs-client-9bcff8f08dc084b880ef978c890a2706a1bbb304.tar.gz
We won't redefine the "new" singleton method since that
conflicts with existing usage.
-rw-r--r--lib/mogilefs/http_reader.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/mogilefs/http_reader.rb b/lib/mogilefs/http_reader.rb
index d3f57f7..47c893a 100644
--- a/lib/mogilefs/http_reader.rb
+++ b/lib/mogilefs/http_reader.rb
@@ -23,7 +23,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
     errors = nil
     paths.each do |path|
       begin
-        sock = new(path, http_method, timeout) and return sock
+        sock = try(path, http_method, timeout) and return sock
       rescue => e
         errors ||= []
         errors << "#{path} failed with #{e.message} (#{e.class})"
@@ -35,7 +35,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
 
   # given a path, this returns a readable socket with ready data from the
   # body of the response.
-  def self.new(path, http_method, timeout)
+  def self.try(path, http_method, timeout)
     uri = URI.parse(path)
     sock = tcp(uri.host, uri.port, timeout)
     buf = "#{http_method} #{uri.request_uri} HTTP/1.0\r\n\r\n" # no chunking
@@ -66,7 +66,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
     raise MogileFS::InvalidResponseError,
           "#{http_method} on #{uri} returned: #{head.inspect}", []
   rescue
-    sock.close unless sock.closed?
+    sock.close if sock && ! sock.closed?
     raise
   end
 end