harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r418741 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
Date Mon, 03 Jul 2006 10:57:11 GMT
Author: tellison
Date: Mon Jul  3 03:57:09 2006
New Revision: 418741

URL: http://svn.apache.org/viewvc?rev=418741&view=rev
Log:
Apply patch HARMONY-701 ([classlib][nio] java.nio.channels.DatagramChannel.send(ByteBuffer,
SocketAddress) sends data incorrectly if the position of ByteBuffer is not zero)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java?rev=418741&r1=418740&r2=418741&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
Mon Jul  3 03:57:09 2006
@@ -346,22 +346,24 @@
 
         try {
             begin();
-
             byte[] array;
-            // FIXME enhence the performance
+            int length = source.remaining();
+            int oldposition = source.position();
+            int start;
             if (source.hasArray()) {
                 array = source.array();
+                start = oldposition;
             } else {
-                array = new byte[source.remaining()];
+                array = new byte[length];
                 source.get(array);
-            }
-            DatagramPacket pack = new DatagramPacket(array, array.length, isa);
-
+                start = 0;
+            }            
             synchronized (writeLock) {
-                sendCount = networkSystem.sendDatagram(fd, pack.getData(), 0,
-                        pack.getLength(), isa.getPort(), false, trafficClass,
-                        isa.getAddress());
+                sendCount = networkSystem.sendDatagram(fd, array, start,
+                        length, isa.getPort(), false, trafficClass, isa
+                                .getAddress());
             }
+            source.position(oldposition + sendCount);            
             return sendCount;
         } finally {
             end(sendCount >= 0);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java?rev=418741&r1=418740&r2=418741&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java
Mon Jul  3 03:57:09 2006
@@ -2417,7 +2417,23 @@
         sourceBuf.position(postion);
         assertEquals(CAPACITY_NORMAL - postion, dc.write(sourceBuf));
     }
-    
+
+    public void test_send_LBuffer_LSocketAddress_PositonNotZero()
+            throws Exception {
+        // regression test for Harmony-701
+        int CAPACITY_NORMAL = 256;
+        int postion = 16;
+        DatagramChannel dc = DatagramChannel.open();
+        byte[] sourceArray = new byte[CAPACITY_NORMAL];
+        // send ByteBuffer whose position is not zero
+        ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
+        sourceBuf.position(postion);
+        int ret = dc.send(sourceBuf, localAddr1);
+        // assert send (256 - 16) bytes  
+        assertEquals(CAPACITY_NORMAL - postion, ret);
+        // assert the position of ByteBuffer has been set
+        assertEquals(CAPACITY_NORMAL, sourceBuf.position());
+    }
 
     // -------------------------------------------------------------------
     // Mock class for security test.



Mime
View raw message