harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r966504 - in /harmony/enhanced/java/trunk/classlib/modules: luni/src/main/native/luni/unix/ luni/src/main/native/luni/windows/ nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/
Date Thu, 22 Jul 2010 05:19:53 GMT
Author: regisxu
Date: Thu Jul 22 05:19:53 2010
New Revision: 966504

URL: http://svn.apache.org/viewvc?rev=966504&view=rev
Log:
Apply patch for HARMONY-6595: [classlib][nio]java.nio.channels.SocketChannel.write() throws
SocketException in non-blocking mode

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
    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/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=966504&r1=966503&r2=966504&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Thu Jul 22 05:19:53 2010
@@ -802,8 +802,7 @@ Java_org_apache_harmony_luni_platform_OS
   result = writev(SOCKET_CAST (socketP), vect, length);
 
   if (0 > result) {
-    /* TOFIX? man write(2) on linux implies we should check EWOULDBLOCK too */
-    if (errno != EAGAIN) {
+    if (errno != EAGAIN && errno != EWOULDBLOCK) {
       throwJavaNetSocketException(env, result);
     }
     result = 0;

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c?rev=966504&r1=966503&r2=966504&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
Thu Jul 22 05:19:53 2010
@@ -448,7 +448,7 @@ Java_org_apache_harmony_luni_platform_OS
   jlong result = 0;
   LPWSABUF vect;
   int i;
-  jint sentBytes;
+  jint sentBytes = 0;
   jint rc;
   jclass byteBufferClass;
 
@@ -521,7 +521,9 @@ Java_org_apache_harmony_luni_platform_OS
 
   if (SOCKET_ERROR == result) {
     rc = WSAGetLastError ();
-    throwJavaNetSocketException(env, rc);
+    if (rc != WSATRY_AGAIN && rc != WSAEWOULDBLOCK) {
+        throwJavaNetSocketException(env, rc);
+    }
     result = 0;
   }
 

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=966504&r1=966503&r2=966504&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
Thu Jul 22 05:19:53 2010
@@ -2805,6 +2805,46 @@ public class SocketChannelTest extends T
 
     /**
      * @tests java.nio.channels.SocketChannel#write(ByteBuffer[])
+     * 
+     * In non-blocking mode, the native system call will return EAGAIN/EWOULDBLOCK error
+     * code on Linux/Unix and return WSATRY_AGAIN/WSAEWOULDBLOCK error code on Windows.
+     * These error code means try again but not fatal error, so we should not throw exception.
+     */
+    public void test_write$NonBlockingException() throws Exception {
+        ServerSocketChannel ssc = ServerSocketChannel.open();
+        ssc.configureBlocking(false);
+        ssc.socket().bind(null);
+        SocketChannel sc = SocketChannel.open();
+        sc.configureBlocking(false);
+        boolean connected = sc.connect(ssc.socket().getLocalSocketAddress());
+        SocketChannel sock = ssc.accept();
+        if (!connected) {
+            sc.finishConnect();
+        }
+
+        try {
+            for (int i = 0; i < 100; i++) {
+                ByteBuffer buf1 = ByteBuffer.allocate(10);
+                sc.socket().setSendBufferSize(512);
+                int bufSize = sc.socket().getSendBufferSize();
+                ByteBuffer buf2 = ByteBuffer.allocate(bufSize * 10);
+
+                ByteBuffer[] sent = new ByteBuffer[2];
+                sent[0] = buf1;
+                sent[1] = buf2;
+
+                sc.write(sent);
+            }
+        } finally {
+            ssc.close();
+            sc.close();
+            sock.close();
+        }
+
+    }
+
+    /**
+     * @tests java.nio.channels.SocketChannel#write(ByteBuffer[])
      */
     public void test_write$LByteBuffer2() throws IOException {
         // Set-up



Mime
View raw message