harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r417714 - 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 Wed, 28 Jun 2006 10:21:50 GMT
Author: gharley
Date: Wed Jun 28 03:21:48 2006
New Revision: 417714

URL: http://svn.apache.org/viewvc?rev=417714&view=rev
Log:
HARMONY 683 : DatagramChannel.write fails to write ByteBuffer whose position 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=417714&r1=417713&r2=417714&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
Wed Jun 28 03:21:48 2006
@@ -501,6 +501,7 @@
                 for (int val = offset; val < length; val++) {
                     writeBuf.put(sources[val]);
                 }
+                writeBuf.flip();
                 return writeImpl(writeBuf);
             }
         }
@@ -513,20 +514,23 @@
     private int writeImpl(ByteBuffer buf) throws IOException {
         // the return value
         int result = 0;
-
         try {
-            begin();
+            begin();            
             byte[] array;
-            // FIXME enhence the perform
+            int length = buf.remaining();
+            int oldposition = buf.position();
+            int start;
             if (buf.hasArray()) {
-                array = buf.array();
+                array = buf.array();  
+                start = oldposition;
             } else {
-                array = new byte[buf.remaining()];
+                array = new byte[length];
                 buf.get(array);
+                start = 0;
             }
-            DatagramPacket pack = new DatagramPacket(array, array.length);
-            result = networkSystem.sendConnectedDatagram(fd, pack.getData(), 0,
-                    pack.getLength(), isBound);
+            result = networkSystem.sendConnectedDatagram(fd, array, start,
+                    length, isBound);
+            buf.position(oldposition + result);
             return result;
         } finally {
             end(result > 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=417714&r1=417713&r2=417714&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
Wed Jun 28 03:21:48 2006
@@ -2404,8 +2404,20 @@
         // read
         ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
         assertEquals(0, this.channel2.read(targetBuf));
-
     }
+    
+    public void test_write_LBuffer_positioned() throws Exception {
+        // Regression test for Harmony-683
+        int postion = 16;
+        DatagramChannel dc = DatagramChannel.open();
+        byte[] sourceArray = new byte[CAPACITY_NORMAL];        
+        dc.connect(localAddr1);
+        // write
+        ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
+        sourceBuf.position(postion);
+        assertEquals(CAPACITY_NORMAL - postion, dc.write(sourceBuf));
+    }
+    
 
     // -------------------------------------------------------------------
     // Mock class for security test.



Mime
View raw message