[前][次][番号順一覧][スレッド一覧]

ruby-changes:34101

From: akr <ko1@a...>
Date: Wed, 28 May 2014 00:15:21 +0900 (JST)
Subject: [ruby-changes:34101] akr:r46182 (trunk): * lib/net/ftp.rb (transfercmd): Close TCP server socket even if an

akr	2014-05-28 00:14:59 +0900 (Wed, 28 May 2014)

  New Revision: 46182

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46182

  Log:
    * lib/net/ftp.rb (transfercmd): Close TCP server socket even if an
      exception occur.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46181)
+++ ChangeLog	(revision 46182)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed May 28 00:06:18 2014  Tanaka Akira  <akr@f...>
+
+	* lib/net/ftp.rb (transfercmd): Close TCP server socket even if an
+	  exception occur.
+
 Tue May 27 23:50:07 2014  Tanaka Akira  <akr@f...>
 
 	* lib/cgi/core.rb: Use Tempfile#close(true) instead of Tempfile#unlink
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 46181)
+++ lib/net/ftp.rb	(revision 46182)
@@ -420,23 +420,26 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L420
         end
       else
         sock = makeport
-        if @resume and rest_offset
-          resp = sendcmd("REST " + rest_offset.to_s)
-          if resp[0] != ?3
+        begin
+          if @resume and rest_offset
+            resp = sendcmd("REST " + rest_offset.to_s)
+            if resp[0] != ?3
+              raise FTPReplyError, resp
+            end
+          end
+          resp = sendcmd(cmd)
+          # skip 2XX for some ftp servers
+          resp = getresp if resp[0] == ?2
+          if resp[0] != ?1
             raise FTPReplyError, resp
           end
+          conn = BufferedSocket.new(sock.accept)
+          conn.read_timeout = @read_timeout
+          sock.shutdown(Socket::SHUT_WR) rescue nil
+          sock.read rescue nil
+        ensure
+          sock.close
         end
-        resp = sendcmd(cmd)
-        # skip 2XX for some ftp servers
-        resp = getresp if resp[0] == ?2
-        if resp[0] != ?1
-          raise FTPReplyError, resp
-        end
-        conn = BufferedSocket.new(sock.accept)
-        conn.read_timeout = @read_timeout
-        sock.shutdown(Socket::SHUT_WR) rescue nil
-        sock.read rescue nil
-        sock.close
       end
       return conn
     end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]