You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by li...@apache.org on 2007/02/09 11:03:34 UTC

svn commit: r505236 - in /harmony/enhanced/classlib/trunk/modules: nio/src/main/java/org/apache/harmony/nio/internal/ nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/ portlib/src/main/native/port/unix/ portlib/src/main/native/po...

Author: liangyx
Date: Fri Feb  9 02:03:33 2007
New Revision: 505236

URL: http://svn.apache.org/viewvc?view=rev&rev=505236
Log:
Apply patch for HARMONY-1947([classlib][luni] SocketChannel.finishConnect() is not working properly)

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java?view=diff&rev=505236&r1=505235&r2=505236
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java Fri Feb  9 02:03:33 2007
@@ -340,15 +340,10 @@
 
         try {
             begin();
-            if (isBlocking()) {
-                result = networkSystem.connect(fd, trafficClass, connectAddress
-                        .getAddress(), connectAddress.getPort());
-
-            } else {
-                result = networkSystem.connectWithTimeout(fd, 0, trafficClass,
-                        connectAddress.getAddress(), connectAddress.getPort(),
-                        HY_PORT_SOCKET_STEP_CHECK, connectContext);
-            }
+            result = networkSystem.connectWithTimeout(fd,
+                    isBlocking() ? -1 : 0, trafficClass, connectAddress
+                            .getAddress(), connectAddress.getPort(),
+                    HY_PORT_SOCKET_STEP_CHECK, connectContext);
             finished = (result == CONNECT_SUCCESS);
             isBound = finished;
             localAddress = networkSystem.getSocketLocalAddress(fd, false);

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java?view=diff&rev=505236&r1=505235&r2=505236
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java Fri Feb  9 02:03:33 2007
@@ -1706,6 +1706,43 @@
         tryFinish();
     }
 
+    /**
+     * Regression test for Harmony-1947.
+     */
+    public void test_finishConnect() throws Exception {
+        SocketAddress address = new InetSocketAddress("localhost", 2046);
+
+        ServerSocketChannel theServerChannel = ServerSocketChannel.open();
+        ServerSocket serversocket = theServerChannel.socket();
+        serversocket.setReuseAddress(true);
+        // Bind the socket
+        serversocket.bind(address);
+
+        boolean doneNonBlockingConnect = false;
+        // Loop so that we make sure we're definitely testing finishConnect()
+        while (!doneNonBlockingConnect) {
+            channel1 = SocketChannel.open();
+
+            // Set the SocketChannel to non-blocking so that connect(..) does
+            // not block
+            channel1.configureBlocking(false);
+            boolean connected = channel1.connect(address);
+            if (!connected) {
+                // Now set the SocketChannel back to blocking so that
+                // finishConnect() blocks.
+                channel1.configureBlocking(true);
+                doneNonBlockingConnect = channel1.finishConnect();
+            }
+            if (doneNonBlockingConnect) {
+                tryFinish();
+            }
+            channel1.close();
+        }
+        if (!serversocket.isClosed()) {
+            serversocket.close();
+        }
+    }
+    
     // -------------------------------------------------------------------
     // End of original tests. Test method for CFII with real data.
     // -------------------------------------------------------------------

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c?view=diff&rev=505236&r1=505235&r2=505236
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c (original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c Fri Feb  9 02:03:33 2007
@@ -5117,7 +5117,7 @@
  * @param[in] portLibrary The port library.
  * @param[in] sock pointer to the unconnected local socket.
  * @param[in] addr	pointer to the sockaddr, specifying remote host/port.
- * @param[in] timeout  timeout in milliseconds 
+ * @param[in] timeout  timeout in milliseconds. If timeout is negative, perform a block operation. 
  * @param[in,out] pointer to context pointer.  Filled in on first call and then to be passed into each subsequent call
  *
  * @return	0, if no errors occurred, otherwise the (negative) error code.
@@ -5202,7 +5202,7 @@
         {
           passedTimeout.tv_usec = 100 * 1000;
         }
-      else
+      else if ((I_32)timeout >= 0)
         {
           passedTimeout.tv_usec = timeout * 1000;
         }
@@ -5222,7 +5222,7 @@
                 &(((struct selectFDSet_struct *) *context)->readSet),
                 &(((struct selectFDSet_struct *) *context)->writeSet),
                 &(((struct selectFDSet_struct *) *context)->exceptionSet),
-                &passedTimeout);
+                (I_32)timeout >= 0 ? &passedTimeout : NULL);
 
       /* if there is at least one descriptor ready to be checked */
       if (0 < rc)

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c?view=diff&rev=505236&r1=505235&r2=505236
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c (original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c Fri Feb  9 02:03:33 2007
@@ -4863,7 +4863,7 @@
  * @param[in] portLibrary The port library.
  * @param[in] sock pointer to the unconnected local socket.
  * @param[in] addr	pointer to the sockaddr, specifying remote host/port.
- * @param[in] timeout  timeout in milliseconds 
+ * @param[in] timeout  timeout in milliseconds. If timeout is negative, perform a block operation. 
  * @param[in] step 
  * @param[in,out] context pointer to context pointer.  Filled in on first call and then to be passed into each subsequent call
  *
@@ -4962,8 +4962,10 @@
 
       /* set the timeout value to be used.  Just use the full timeout as windows should return from select 
          error if the socket has been returned  */
-      passedTimeout.tv_sec = timeout / 1000;
-      passedTimeout.tv_usec = (timeout - passedTimeout.tv_sec * 1000) * 1000;
+      if ((I_32) timeout >= 0) {
+          passedTimeout.tv_sec = timeout / 1000;
+          passedTimeout.tv_usec = (timeout - passedTimeout.tv_sec * 1000) * 1000;
+      }      
 
       /* initialize the FD sets for the select */
       FD_ZERO (&(((struct selectFDSet_struct *) *context)->exceptionSet));
@@ -4982,7 +4984,7 @@
 		   &(((struct selectFDSet_struct *) *context)->readSet),
 		   &(((struct selectFDSet_struct *) *context)->writeSet),
 		   &(((struct selectFDSet_struct *) *context)->exceptionSet),
-		   &passedTimeout);
+		   (I_32) timeout >= 0 ? &passedTimeout : NULL);
 
       /* if there is at least one descriptor ready to be checked */
       if (0 < rc)