harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r819939 - in /harmony/enhanced/classlib/trunk/modules/nio/src: main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Date Tue, 29 Sep 2009 13:29:55 GMT
Author: tellison
Date: Tue Sep 29 13:29:55 2009
New Revision: 819939

URL: http://svn.apache.org/viewvc?rev=819939&view=rev
Log:
Apply slightly modified patch for HARMONY-6343 ([classlib][nio]SocketChannel.connect() can
return true in non-blocking mode)

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/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

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=819939&r1=819938&r2=819939&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
Tue Sep 29 13:29:55 2009
@@ -299,11 +299,11 @@
         // set the connected address.
         connectAddress = inetSocketAddress;
         synchronized (this) {
-            if (isBlocking()) {
-                status = (finished ? SOCKET_STATUS_CONNECTED
-                        : SOCKET_STATUS_UNCONNECTED);
+            if (finished) {
+                status = SOCKET_STATUS_CONNECTED;
             } else {
-                status = SOCKET_STATUS_PENDING;
+                status = isBlocking() ? SOCKET_STATUS_UNCONNECTED
+                        : SOCKET_STATUS_PENDING;
             }
         }
         return finished;

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?rev=819939&r1=819938&r2=819939&view=diff
==============================================================================
--- 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
Tue Sep 29 13:29:55 2009
@@ -299,15 +299,19 @@
     public void testSocket_NonBlock_BasicStatusAfterConnect() throws Exception {
         assertFalse(this.channel1.isConnected());// not connected
         this.channel1.configureBlocking(false);
-        assertFalse(this.channel1.connect(localAddr1));
-        assertFalse(this.channel1.isConnected());
-        assertTrue(this.channel1.isConnectionPending());
-        Socket s1 = this.channel1.socket();
-        // status of not connected
-        assertSocketBeforeConnect(s1);
-        Socket s2 = this.channel1.socket();
-        // same
-        assertSame(s1, s2);
+        boolean connected = channel1.connect(localAddr1);
+        Socket s1 = null;
+        Socket s2 = null;
+        if (!connected) {
+            assertFalse(this.channel1.isConnected());
+            assertTrue(this.channel1.isConnectionPending());
+            s1 = this.channel1.socket();
+            // status of not connected
+            assertSocketBeforeConnect(s1);
+            s2 = this.channel1.socket();
+            // same
+            assertSame(s1, s2);
+        }
 
         if (tryFinish()) {
             assertTrue(this.channel1.isConnected());
@@ -338,22 +342,24 @@
             throws IOException {
         assertFalse(this.channel1.isConnected());// not connected
         this.channel1.configureBlocking(false);
-        assertFalse(this.channel1.connect(localAddr1));
-        assertFalse(this.channel1.isConnected());
-        assertTrue(this.channel1.isConnectionPending());
-        Socket s1 = this.channel1.socket();
-        // Action of not connected
-        assertSocketAction_NonBlock_BeforeConnect(s1);
-        Socket s2 = this.channel1.socket();
-        // same
-        assertSame(s1, s2);
+        boolean connected = channel1.connect(localAddr1);
+        if (!connected) {
+            assertFalse(this.channel1.isConnected());
+            assertTrue(this.channel1.isConnectionPending());
+            Socket s1 = this.channel1.socket();
+            // Action of not connected
+            assertSocketAction_NonBlock_BeforeConnect(s1);
+            Socket s2 = this.channel1.socket();
+            // same
+            assertSame(s1, s2);
+        }
     }
 
     public void testSocket_NonBlock_ActionsAfterConnectAfterFinish()
             throws Exception {
         assertFalse(this.channel1.isConnected());// not connected
         this.channel1.configureBlocking(false);
-        assertFalse(this.channel1.connect(localAddr1));
+        channel1.connect(localAddr1);
         if (tryFinish()) {
             Socket s1 = this.channel1.socket();
             assertSocketAction_NonBlock_AfterConnect(s1);
@@ -641,9 +647,10 @@
         this.channel1.configureBlocking(false);
         statusNotConnected_NotPending();
         // connect
-        assertFalse(this.channel1.connect(localAddr1));
-        statusNotConnected_Pending();
-
+        boolean connected = channel1.connect(localAddr1);
+        if (!connected) {
+            statusNotConnected_Pending();
+        }
         ensureServerClosed();
 
         tryFinish();
@@ -1051,37 +1058,38 @@
         this.channel1.configureBlocking(false);
         statusNotConnected_NotPending();
         // connect
-        assertFalse(this.channel1.connect(localAddr1));
-        statusNotConnected_Pending();
+        boolean connected = channel1.connect(localAddr1);
+        if (!connected) {
+            statusNotConnected_Pending();
 
-        try {
-            this.channel1.connect(localAddr1);
-            fail("Should throw a ConnectionPendingException here.");
-        } catch (ConnectionPendingException e) {
-            // OK.
-        }
-        statusNotConnected_Pending();
+            try {
+                this.channel1.connect(localAddr1);
+                fail("Should throw a ConnectionPendingException here.");
+            } catch (ConnectionPendingException e) {
+                // OK.
+            }
+            statusNotConnected_Pending();
 
-        // connect another addr
-        try {
-            this.channel1.connect(localAddr2);
-            fail("Should throw a ConnectionPendingException here.");
-        } catch (ConnectionPendingException e) {
-            // OK.
-        }
-        statusNotConnected_Pending();
+            // connect another addr
+            try {
+                this.channel1.connect(localAddr2);
+                fail("Should throw a ConnectionPendingException here.");
+            } catch (ConnectionPendingException e) {
+                // OK.
+            }
+            statusNotConnected_Pending();
 
-        // connect if server closed
-        ensureServerClosed();
+            // connect if server closed
+            ensureServerClosed();
 
-        try {
-            this.channel1.connect(localAddr1);
-            fail("Should throw a ConnectionPendingException here.");
-        } catch (ConnectionPendingException e) {
-            // OK.
+            try {
+                this.channel1.connect(localAddr1);
+                fail("Should throw a ConnectionPendingException here.");
+            } catch (ConnectionPendingException e) {
+                // OK.
+            }
+            statusNotConnected_Pending();
         }
-        statusNotConnected_Pending();
-
         tryFinish();
 
         this.channel1.close();
@@ -1196,9 +1204,10 @@
         }
         statusNotConnected_NotPending();
         // connect
-        assertFalse(this.channel1.connect(localAddr1));
-        statusNotConnected_Pending();
-
+        boolean connected = channel1.connect(localAddr1);
+        if (!connected) {
+            statusNotConnected_Pending();
+        }
         tryFinish();
 
         this.channel1.close();
@@ -1376,9 +1385,10 @@
         this.channel1.configureBlocking(false);
         statusNotConnected_NotPending();
         // connect
-        assertFalse(this.channel1.connect(localAddr1));
-        statusNotConnected_Pending();
-
+        boolean connected = channel1.connect(localAddr1);
+        if (!connected) {
+            statusNotConnected_Pending();
+        }
         tryFinish();
     }
 
@@ -1487,9 +1497,11 @@
         this.channel1.connect(localAddr1);
 
         assertFalse(this.channel1.isBlocking());
-        assertFalse(this.channel1.isConnected());
-        assertTrue(this.channel1.isConnectionPending());
-        assertTrue(this.channel1.isOpen());
+        boolean connected = channel1.isConnected();
+        if (!connected) {
+            assertTrue(this.channel1.isConnectionPending());
+            assertTrue(this.channel1.isOpen());
+        }
         if (tryFinish()) {
             assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
             assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));
@@ -1525,11 +1537,13 @@
         } catch (NoConnectionPendingException e) {
             // correct
         }
-        this.channel1.connect(localAddr1);
-        assertFalse(this.channel1.isBlocking());
-        assertFalse(this.channel1.isConnected());
-        assertTrue(this.channel1.isConnectionPending());
-        assertTrue(this.channel1.isOpen());
+        boolean connected = channel1.connect(localAddr1);
+        if (!connected) {
+            assertFalse(this.channel1.isBlocking());
+            assertFalse(this.channel1.isConnected());
+            assertTrue(this.channel1.isConnectionPending());
+            assertTrue(this.channel1.isOpen());
+        }
         this.server1.accept();
         if (tryFinish()) {
             assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
@@ -1979,10 +1993,12 @@
         } catch (NotYetConnectedException e) {
             // correct
         }
-        this.channel1.connect(localAddr1);
-        assertFalse(this.channel1.isBlocking());
-        assertTrue(this.channel1.isConnectionPending());
-        assertFalse(this.channel1.isConnected());
+        boolean connected = this.channel1.connect(localAddr1);
+        if (!connected) {
+            assertFalse(this.channel1.isBlocking());
+            assertTrue(this.channel1.isConnectionPending());
+            assertFalse(this.channel1.isConnected());
+        }
         if (tryFinish()) {
             assertEquals(0, this.channel1.read(readBuf));
         }
@@ -2013,10 +2029,12 @@
         } catch (NotYetConnectedException e) {
             // correct
         }
-        this.channel1.connect(localAddr1);
-        assertFalse(this.channel1.isBlocking());
-        assertTrue(this.channel1.isConnectionPending());
-        assertFalse(this.channel1.isConnected());
+        boolean connected = this.channel1.connect(localAddr1);
+        if (!connected) {
+            assertFalse(this.channel1.isBlocking());
+            assertTrue(this.channel1.isConnectionPending());
+            assertFalse(this.channel1.isConnected());
+        }
         if (tryFinish()) {
             assertEquals(0, this.channel1.read(readBuf));
         }
@@ -2117,10 +2135,12 @@
         } catch (NotYetConnectedException e) {
             // correct
         }
-        this.channel1.connect(localAddr1);
-        assertFalse(this.channel1.isBlocking());
-        assertTrue(this.channel1.isConnectionPending());
-        assertFalse(this.channel1.isConnected());
+        boolean connected = this.channel1.connect(localAddr1);
+        if (!connected) {
+            assertFalse(this.channel1.isBlocking());
+            assertTrue(this.channel1.isConnectionPending());
+            assertFalse(this.channel1.isConnected());
+        }
         if (tryFinish()) {
             assertEquals(0, this.channel1.read(readBuf, 0, 1));
             assertEquals(0, this.channel1.read(readBuf, 0, 2));
@@ -2156,10 +2176,12 @@
         } catch (NotYetConnectedException e) {
             // correct
         }
-        this.channel1.connect(localAddr1);
-        assertFalse(this.channel1.isBlocking());
-        assertTrue(this.channel1.isConnectionPending());
-        assertFalse(this.channel1.isConnected());
+        boolean connected = this.channel1.connect(localAddr1);
+        if (!connected) {
+            assertFalse(this.channel1.isBlocking());
+            assertTrue(this.channel1.isConnectionPending());
+            assertFalse(this.channel1.isConnected());
+        }
         if (tryFinish()) {
             assertEquals(0, this.channel1.read(readBuf, 0, 1));
             assertEquals(0, this.channel1.read(readBuf, 0, 2));



Mime
View raw message