harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r479548 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/MulticastSocket.java test/java/tests/api/java/net/MulticastSocketTest.java
Date Mon, 27 Nov 2006 08:47:25 GMT
Author: liangyx
Date: Mon Nov 27 00:47:24 2006
New Revision: 479548

URL: http://svn.apache.org/viewvc?view=rev&rev=479548
Log:
apply patch for HARMONY-2274 ([classlib][net]MulticastSocket.setLoopbackMode set wrong value)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java?view=diff&rev=479548&r1=479547&r2=479548
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
Mon Nov 27 00:47:24 2006
@@ -608,7 +608,7 @@
 	 */
 	public boolean getLoopbackMode() throws SocketException {
 		checkClosedAndBind(false);
-		return ((Boolean) impl.getOption(SocketOptions.IP_MULTICAST_LOOP))
+		return !((Boolean) impl.getOption(SocketOptions.IP_MULTICAST_LOOP))
 				.booleanValue();
 	}
 
@@ -625,7 +625,7 @@
 	 */
 	public void setLoopbackMode(boolean loop) throws SocketException {
 		checkClosedAndBind(false);
-		impl.setOption(SocketOptions.IP_MULTICAST_LOOP, loop ? Boolean.TRUE
-				: Boolean.FALSE);
+		impl.setOption(SocketOptions.IP_MULTICAST_LOOP, loop ? Boolean.FALSE
+				: Boolean.TRUE);
 	}
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java?view=diff&rev=479548&r1=479547&r2=479548
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/MulticastSocketTest.java
Mon Nov 27 00:47:24 2006
@@ -990,7 +990,47 @@
 			handleException(e, SO_USELOOPBACK);
 		}
 	}
+    
+    /**
+     * @tests java.net.MulticastSocket#setLoopbackMode(boolean)
+     */
+    public void test_setLoopbackModeSendReceive() throws IOException{
+        final String ADDRESS = "224.1.2.3";
+        final int PORT = 6789;
+        final String message = "Hello, world!";
 
+        // test send receive
+        MulticastSocket socket = null;
+        try {
+            // open a multicast socket
+            socket = new MulticastSocket(PORT);
+            socket.setLoopbackMode(false); // false indecates doing loop back
+            socket.joinGroup(InetAddress.getByName(ADDRESS));
+
+            // send the datagram
+            byte[] sendData = message.getBytes();
+            DatagramPacket sendDatagram = new DatagramPacket(sendData, 0,
+                    sendData.length, new InetSocketAddress(InetAddress
+                            .getByName(ADDRESS), PORT));
+            socket.send(sendDatagram);
+
+            // receive the datagram
+            byte[] recvData = new byte[100];
+            DatagramPacket recvDatagram = new DatagramPacket(recvData,
+                    recvData.length);
+            socket.setSoTimeout(5000); // prevent eternal block in
+            // socket.receive()
+            socket.receive(recvDatagram);
+            String recvMessage = new String(recvData, 0, recvDatagram
+                    .getLength());
+            assertEquals(message, recvMessage);
+        }finally {
+            if (socket != null)
+                socket.close();
+        }
+    }
+    
+    
 	/**
 	 * @tests java.net.MulticastSocket#setReuseAddress(boolean)
 	 */



Mime
View raw message