harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r944119 - in /harmony/enhanced/java/trunk/classlib/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 Fri, 14 May 2010 05:42:44 GMT
Author: regisxu
Date: Fri May 14 05:42:44 2010
New Revision: 944119

URL: http://svn.apache.org/viewvc?rev=944119&view=rev
Log:
SocketChannelImpl.SocketAdapter's remote address should be updated after channel connected

Modified:
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
    harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=944119&r1=944118&r2=944119&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
Fri May 14 05:42:44 2010
@@ -1006,6 +1006,47 @@ class SocketChannelImpl extends SocketCh
             return new SocketChannelInputStream(channel);
         }
 
+        @Override
+        public InetAddress getInetAddress() {
+            if (channel.connectAddress == null && super.getInetAddress() != null)
{
+                channel.connectAddress = new InetSocketAddress(super.getInetAddress(), super.getPort());
+            }
+            if (channel.connectAddress == null) {
+                return null;
+            }
+            return channel.connectAddress.getAddress();
+        }
+
+        @Override
+        public SocketAddress getRemoteSocketAddress() {
+            if (channel.connectAddress == null && super.getInetAddress() != null)
{
+                channel.connectAddress = new InetSocketAddress(super.getInetAddress(), super.getPort());
+            }
+            return channel.connectAddress;
+        }
+
+        @Override
+        public int getPort() {
+            if (channel.connectAddress == null && super.getInetAddress() != null)
{
+                channel.connectAddress = new InetSocketAddress(super.getInetAddress(), super.getPort());
+            }
+            if (channel.connectAddress == null) {
+                return 0;
+            }
+            return channel.connectAddress.getPort();
+        }
+
+        @Override
+        public int getLocalPort() {
+            if (!isBound()) {
+                return -1;
+            }
+            if (channel.localPort == 0 && super.getLocalPort() != -1) {
+                channel.localPort = super.getLocalPort();
+            }
+            return channel.localPort;
+        }
+
         /*
          * Checks whether the channel is open.
          */

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java?rev=944119&r1=944118&r2=944119&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
Fri May 14 05:42:44 2010
@@ -369,6 +369,63 @@ public class SocketChannelTest extends T
         }
     }
 
+    public void testSocket_getInetAddress() throws Exception {
+        Socket socket = channel1.socket();
+        assertNull(socket.getInetAddress());
+
+        channel1.connect(localAddr1);
+
+        assertNotNull(socket.getInetAddress());
+        assertEquals(localAddr1.getAddress(), socket.getInetAddress());
+    }
+
+    public void testSocket_getRemoteSocketAddress() throws Exception {
+        Socket socket = channel1.socket();
+        assertNull(socket.getRemoteSocketAddress());
+
+        channel1.connect(localAddr1);
+
+        assertNotNull(socket.getRemoteSocketAddress());
+        assertEquals(localAddr1, socket.getRemoteSocketAddress());
+    }
+
+    public void testSocket_getPort() throws Exception {
+        Socket socket = channel1.socket();
+        assertEquals(0, socket.getPort());
+
+        channel1.connect(localAddr1);
+
+        assertEquals(localAddr1.getPort(), socket.getPort());
+    }
+
+    public void testSocket_getLocalAddress() throws Exception {
+        Socket socket = channel1.socket();
+        assertNotNull(socket.getLocalAddress());
+
+        channel1.connect(localAddr1);
+
+        assertNotNull(socket.getLocalAddress());
+    }
+
+    public void testSocket_getLocalSocketAddress() throws Exception {
+        Socket socket = channel1.socket();
+        assertNull(socket.getLocalSocketAddress());
+
+        channel1.connect(localAddr1);
+
+        assertNotNull(socket.getLocalSocketAddress());
+    }
+
+    public void testSocket_getLocalPort() throws Exception {
+        Socket socket = channel1.socket();
+        assertEquals(-1, socket.getLocalPort());
+
+        channel1.connect(localAddr1);
+
+        assertTrue(-1 != socket.getLocalPort());
+        assertTrue(0 != socket.getLocalPort());
+    }
+
     private void assertSocketBeforeConnect(Socket s) throws IOException {
         assertFalse(s.isBound());
         assertFalse(s.isClosed());



Mime
View raw message