Fix direct connect, which apparently happens on Solaris
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 7 May 2007 11:30:17 +0000 (11:30 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 7 May 2007 11:30:17 +0000 (11:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@535852 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/tribes/transport/nio/NioSender.java

index a536347..8a35ba7 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.catalina.tribes.transport.AbstractSender;
 import org.apache.catalina.tribes.transport.DataSender;
 import org.apache.catalina.tribes.RemoteProcessException;
 import java.io.EOFException;
+import java.net.*;
 
 /**
  * This class is NOT thread safe and should never be used with more than one thread at a time
@@ -85,21 +86,7 @@ public class NioSender extends AbstractSender implements DataSender{
         if ( !key.isValid() ) throw new IOException("Key is not valid, it must have been cancelled.");
         if ( key.isConnectable() ) {
             if ( socketChannel.finishConnect() ) {
-                //we connected, register ourselves for writing
-                setConnected(true);
-                connecting = false;
-                setRequestCount(0);
-                setConnectTime(System.currentTimeMillis());
-                socketChannel.socket().setSendBufferSize(getTxBufSize());
-                socketChannel.socket().setReceiveBufferSize(getRxBufSize());
-                socketChannel.socket().setSoTimeout((int)getTimeout());
-                socketChannel.socket().setSoLinger(false,0);
-                socketChannel.socket().setTcpNoDelay(getTcpNoDelay());
-                socketChannel.socket().setKeepAlive(getSoKeepAlive());
-                socketChannel.socket().setReuseAddress(getSoReuseAddress());
-                socketChannel.socket().setOOBInline(getOoBInline());
-                socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
-                socketChannel.socket().setTrafficClass(getSoTrafficClass());
+                completeConnect();
                 if ( current != null ) key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
                 return false;
             } else  { 
@@ -141,6 +128,24 @@ public class NioSender extends AbstractSender implements DataSender{
         }//end if
         return false;
     }
+
+    private void completeConnect() throws SocketException {
+        //we connected, register ourselves for writing
+        setConnected(true);
+        connecting = false;
+        setRequestCount(0);
+        setConnectTime(System.currentTimeMillis());
+        socketChannel.socket().setSendBufferSize(getTxBufSize());
+        socketChannel.socket().setReceiveBufferSize(getRxBufSize());
+        socketChannel.socket().setSoTimeout((int)getTimeout());
+        socketChannel.socket().setSoLinger(false,0);
+        socketChannel.socket().setTcpNoDelay(getTcpNoDelay());
+        socketChannel.socket().setKeepAlive(getSoKeepAlive());
+        socketChannel.socket().setReuseAddress(getSoReuseAddress());
+        socketChannel.socket().setOOBInline(getOoBInline());
+        socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
+        socketChannel.socket().setTrafficClass(getSoTrafficClass());
+    }
     
     
 
@@ -215,8 +220,12 @@ public class NioSender extends AbstractSender implements DataSender{
         if ( socketChannel != null ) throw new IOException("Socket channel has already been established. Connection might be in progress.");
         socketChannel = SocketChannel.open();
         socketChannel.configureBlocking(false);
-        socketChannel.connect(addr);
-        socketChannel.register(getSelector(),SelectionKey.OP_CONNECT,this);
+        if ( socketChannel.connect(addr) ) {
+            completeConnect();
+            socketChannel.register(getSelector(), SelectionKey.OP_WRITE, this);
+        } else {
+            socketChannel.register(getSelector(), SelectionKey.OP_CONNECT, this);
+        }
     }