harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r721444 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main: java/java/net/ java/org/apache/harmony/luni/net/ java/org/apache/harmony/luni/platform/ native/luni/shared/
Date Fri, 28 Nov 2008 12:08:31 GMT
Author: tellison
Date: Fri Nov 28 04:08:30 2008
New Revision: 721444

URL: http://svn.apache.org/viewvc?rev=721444&view=rev
Log:
Continued tidy-up of socket read and write functionality.
 - Switch callers from using sendStream() to write().  sendStream() will be removed as redundant.
 - Switch callers from using receiveStream() to read().  receiveStream() will be removed as
redundant.
 - Extend read() native to account for non-blocking sockets.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java?rev=721444&r1=721443&r2=721444&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java Fri
Nov 28 04:08:30 2008
@@ -274,7 +274,7 @@
             return this.netImpl.sendDatagram2(fd, buffer, offset, count, port,
                     address);
         }
-        return this.netImpl.sendStream(fd, buffer, offset, count);
+        return this.netImpl.write(fd, buffer, offset, count);
     }
 
     /**

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?rev=721444&r1=721443&r2=721444&view=diff
==============================================================================
--- 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
Fri Nov 28 04:08:30 2008
@@ -534,16 +534,16 @@
         if (shutdownInput) {
             return -1;
         }
-        try {
-            int read = netImpl.receiveStream(fd, buffer, offset, count,
-                    receiveTimeout);
-            if (read == -1) {
-                shutdownInput = true;
-            }
-            return read;
-        } catch (InterruptedIOException e) {
-            throw new SocketTimeoutException(e.getMessage());
+        int read = netImpl.read(fd, buffer, offset, count, receiveTimeout);
+        // Return of zero bytes for a blocking socket means a timeout occurred
+        if (read == 0) {
+            throw new SocketTimeoutException();
         }
+        // Return of -1 indicates the peer was closed
+        if (read == -1) {
+            shutdownInput = true;
+        }
+        return read;
     }
 
     int write(byte[] buffer, int offset, int count) throws IOException {
@@ -551,6 +551,6 @@
             return netImpl.sendDatagram2(fd, buffer, offset, count, port,
                     address);
         }
-        return netImpl.sendStream(fd, buffer, offset, count);
+        return netImpl.write(fd, buffer, offset, count);
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java?rev=721444&r1=721443&r2=721444&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
Fri Nov 28 04:08:30 2008
@@ -228,6 +228,11 @@
     /**
      * Read available bytes from the given file descriptor into a byte array.
      * 
+     * The read has an optional timeout parameter, which if non-zero is the
+     * length of time that the read will wait on a select call to see if any
+     * bytes are available for reading. If the timeout expires the method
+     * returns zero to indicate no bytes were read.
+     * 
      * @param fd
      *            the socket file descriptor to read
      * @param data
@@ -238,7 +243,9 @@
      * @param count
      *            the maximum number of bytes to read
      * @param timeout
-     *            the length of time to wait for the bytes, in milliseconds
+     *            the length of time to wait for the bytes, in milliseconds; or
+     *            zero to indicate no timeout applied. When there is no timeout
+     *            applied the read may block based upon socket options.
      * @return number of bytes read, or zero if there were no bytes available
      *         before the timeout occurred, or -1 to indicate the socket is
      *         closed
@@ -314,11 +321,13 @@
      *            the max number of bytes to receive
      * @param timeout
      *            the max time the read operation should block waiting for data
-     * @return int the actual number of bytes read
+     * @return the actual number of bytes read
      * @throws IOException
      * @throws SocketException
      *             if an error occurs while reading
+     * @deprecated use {@link #read(FileDescriptor, byte[], int, int, int)}
      */
+    @Deprecated
     public native int receiveStream(FileDescriptor aFD, byte[] data,
             int offset, int count, int timeout) throws IOException;
 
@@ -482,7 +491,9 @@
      * @throws IOException
      * @throws SocketException
      *             if an error occurs while writing
+     * @deprecated use {@link #write(FileDescriptor, byte[], int, int)}
      */
+    @Deprecated
     public native int sendStream(FileDescriptor fd, byte[] data, int offset,
             int count) throws IOException;
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c?rev=721444&r1=721443&r2=721444&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
Fri Nov 28 04:08:30 2008
@@ -339,7 +339,7 @@
   /* Read directly into the byte array */
   result =
     Java_org_apache_harmony_luni_platform_OSNetworkSystem_readDirect
-    (env, thiz, fd, (jlong) (IDATA)message + offset, count, timeout);
+    (env, thiz, fd, (jlong) (IDATA)(message + offset), count, timeout);
 
   /* If the pointer was to a copy it needs to be released */
   if (isCopy == JNI_TRUE) {
@@ -361,32 +361,38 @@
  */
 JNIEXPORT jint JNICALL
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_readDirect
-  (JNIEnv * env, jobject thiz, jobject fileDescriptor, jlong address,
+  (JNIEnv * env, jobject thiz, jobject fd, jlong address,
    jint count, jint timeout)
 {
   PORT_ACCESS_FROM_ENV(env);
   hysocket_t hysocketP;
-  jbyte *message = (jbyte *) (IDATA)address;
+  U_8 *message = (U_8 *)(IDATA)address;
   I_32 result, localCount;
 
-  hysocketP = getJavaIoFileDescriptorContentsAsAPointer(env, fileDescriptor);
+  hysocketP = getJavaIoFileDescriptorContentsAsAPointer(env, fd);
 
-  /* Check and potentially wait to see if any bytes available */
-  result = selectRead(env, hysocketP, timeout * 1000, FALSE);
-  if (0 > result) {
-    if (result == HYPORT_ERROR_SOCKET_TIMEOUT) {
-      return (jint) 0;  // return zero bytes to indicate timeout
+  /* A non-zero timeout will first check, and potentially wait, to see if any
+   * bytes are available
+   */
+  if (timeout != 0) {
+    result = selectRead(env, hysocketP, timeout * 1000, FALSE);
+    if (0 > result) {
+      if (result == HYPORT_ERROR_SOCKET_TIMEOUT) {
+        return (jint) 0;  // return zero bytes to indicate timeout
+      }
+      throwJavaNetSocketException(env, result);
+      return (jint) 0;  // Unused, exception takes precedence
     }
-    throwJavaNetSocketException(env, result);
-    return (jint) 0;  // Unused, exception takes precedence
   }
 
   /* Limit size of read to 64k bytes */
   localCount = (count < 65536) ? count : 65536;
-
-  result =
-    hysock_read(hysocketP, (U_8 *) message, localCount, HYSOCK_NOFLAGS);
+  result = hysock_read(hysocketP, message, localCount, HYSOCK_NOFLAGS);
   if (0 > result) {
+    if (HYPORT_ERROR_SOCKET_WOULDBLOCK == result) {
+      /* We were asked to read on a nonblocking socket and there is no data available */
+      return (jint) 0;
+    }
     throwJavaNetSocketException(env, result);
     return (jint) 0;
   }
@@ -395,6 +401,7 @@
   return (0 == result) ? (jint) - 1 : (jint) result;
 }
 
+
 /*
  * Class:     org_apache_harmony_luni_platform_OSNetworkSystem
  * Method:    write
@@ -415,7 +422,7 @@
   /* Write directly from the byte array */
   result =
     Java_org_apache_harmony_luni_platform_OSNetworkSystem_writeDirect
-    (env, thiz, fd, (jlong)((IDATA) message + offset), count);
+    (env, thiz, fd, (jlong) (IDATA)(message + offset), count);
 
 
   /* If the pointer was to a copy it needs to be released */
@@ -1622,6 +1629,9 @@
   }
 }
 
+/*
+ * Deprecated.  Use Java_org_apache_harmony_luni_platform_OSNetworkSystem_read
+ */
 JNIEXPORT jint JNICALL
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_receiveStream
   (JNIEnv * env, jobject thiz, jobject fileDescriptor, jbyteArray data,
@@ -1682,9 +1692,7 @@
 
 
 /*
- * Class:     org_apache_harmony_luni_platform_OSNetworkSystem
- * Method:    sendStream
- * Signature: (Ljava/io/FileDescriptor;[BII)I
+ * Deprecated : use Java_org_apache_harmony_luni_platform_OSNetworkSystem_write
  */
 JNIEXPORT jint JNICALL
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_sendStream



Mime
View raw message