You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/01/11 22:51:21 UTC

svn commit: r495393 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/Socket.java main/java/org/apache/harmony/luni/net/PlainSocketImpl.java test/java/tests/api/java/net/SocketTest.java

Author: tellison
Date: Thu Jan 11 13:51:20 2007
New Revision: 495393

URL: http://svn.apache.org/viewvc?view=rev&rev=495393
Log:
Apply patch HARMONY-2930 ([classlib][luni]java.net.Socket cann't bind the local address when constructed with proxy)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/SocketTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java?view=diff&rev=495393&r1=495392&r2=495393
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java Thu Jan 11 13:51:20 2007
@@ -855,9 +855,7 @@
 
         synchronized (this) {
             try {
-                if (!NetUtil.usingSocks(proxy)) {
-                    impl.bind(addr, port);
-                }
+                impl.bind(addr, port);
                 isBound = true;
             } catch (IOException e) {
                 impl.close();

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java?view=diff&rev=495393&r1=495392&r2=495393
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java Thu Jan 11 13:51:20 2007
@@ -154,10 +154,6 @@
 
     @Override
     protected void bind(InetAddress anAddr, int aPort) throws IOException {
-        if (NetUtil.usingSocks(proxy)) {
-            socksBind();
-            return;
-        }
         netImpl.bind(fd, aPort, anAddr);
         // PlainSocketImpl2.socketBindImpl2(fd, aPort, anAddr);
         address = anAddr;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/SocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/SocketTest.java?view=diff&rev=495393&r1=495392&r2=495393
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/SocketTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/SocketTest.java Thu Jan 11 13:51:20 2007
@@ -1172,6 +1172,27 @@
 		theSocket.close();
 	}
 
+    /**
+     * @tests java.net.Socket#bind(java.net.SocketAddress)
+     */
+    public void test_bindLjava_net_SocketAddress_Proxy() throws IOException {
+        //The Proxy will not impact on the bind operation.It can be assigned with any address.
+        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 0));
+        Socket socket = new Socket(proxy);
+
+        try {
+            InetAddress address = InetAddress.getByName("localhost");
+            int port = 0;
+            socket.bind(new InetSocketAddress(address, port));
+            
+            assertEquals(address, socket.getLocalAddress());
+            assertTrue(port!=socket.getLocalPort());
+
+        } finally {
+            socket.close();
+        }
+    }
+
 	/**
 	 * @tests java.net.Socket#connect(java.net.SocketAddress)
 	 */