commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1083955 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/ftp/FTP.java
Date Mon, 21 Mar 2011 21:02:04 GMT
Author: sebb
Date: Mon Mar 21 21:02:04 2011
New Revision: 1083955

URL: http://svn.apache.org/viewvc?rev=1083955&view=rev
Log:
NET-385 FTP does not apply timeout to initial responses

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1083955&r1=1083954&r2=1083955&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Mon Mar 21 21:02:04 2011
@@ -57,6 +57,9 @@ The <action> type attribute can be add,u
 
     <body>
         <release version="3.0" date="TBA" description="TBA">
+            <action issue="NET-385" dev="sebb" type="update">
+            FTP does not apply timeout to initial responses.
+            </action>
             <action issue="NET-384" dev="sebb" type="update">
             KeyManagerUtils - the KeyManager is not efficient.
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java?rev=1083955&r1=1083954&r2=1083955&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java Mon Mar 21
21:02:04 2011
@@ -25,6 +25,7 @@ import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.SocketException;
+import java.net.SocketTimeoutException;
 import java.util.ArrayList;
 
 import org.apache.commons.net.MalformedServerReplyException;
@@ -375,10 +376,22 @@ public class FTP extends SocketClient
             new BufferedReader(new InputStreamReader(_input_, getControlEncoding()));
         _controlOutput_ =
             new BufferedWriter(new OutputStreamWriter(_output_, getControlEncoding()));
-        __getReply();
-        // If we received code 120, we have to fetch completion reply.
-        if (FTPReply.isPositivePreliminary(_replyCode))
-            __getReply();
+        if (connectTimeout > 0) { // NET-385
+            int original = _socket_.getSoTimeout();
+            _socket_.setSoTimeout(connectTimeout); 
+            try {
+                __getReply();
+                // If we received code 120, we have to fetch completion reply.
+                if (FTPReply.isPositivePreliminary(_replyCode))
+                    __getReply();
+            } catch (SocketTimeoutException e) {
+                IOException ioe = new IOException("Timed out waiting for initial connect
reply");
+                ioe.initCause(e);
+                throw ioe;
+            } finally {
+                _socket_.setSoTimeout(original);
+            }
+        }
     }
 
 



Mime
View raw message