[kaffe] CVS kaffe (kaz): libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_

Kaffe CVS cvs-commits at kaffe.org
Sun Jan 28 05:57:13 PST 2007


PatchSet 7469 
Date: 2007/01/28 13:56:21
Author: kaz
Branch: HEAD
Tag: (none) 
Log:
2007-01-28  Ito Kazumitsu  <kaz at maczuka.gcd.org>

	* libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_
VMChannel.c,
	libraries/javalib/external/classpath/native/jni/java-nio/javanio.c:
	Copied from GNU Classpath. Some bugs have been fixed.

Members: 
	ChangeLog:1.4969->1.4970 
	libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c:1.7->1.8 
	libraries/javalib/external/classpath/native/jni/java-nio/javanio.c:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4969 kaffe/ChangeLog:1.4970
--- kaffe/ChangeLog:1.4969	Sat Jan 20 03:53:27 2007
+++ kaffe/ChangeLog	Sun Jan 28 13:56:21 2007
@@ -1,3 +1,9 @@
+2007-01-28  Ito Kazumitsu  <kaz at maczuka.gcd.org>
+
+	* libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c,
+	libraries/javalib/external/classpath/native/jni/java-nio/javanio.c:
+	Copied from GNU Classpath. Some bugs have been fixed.
+
 2007-01-20  Ito Kazumitsu  <kaz at maczuka.gcd.org>
 
 	* libraries/javalib/external/classpath/java/text/DecimalFormat.java,
Index: kaffe/libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c
diff -u kaffe/libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c:1.7 kaffe/libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c:1.8
--- kaffe/libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c:1.7	Fri Jan  5 20:23:29 2007
+++ kaffe/libraries/javalib/external/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c	Sun Jan 28 13:56:22 2007
@@ -372,6 +372,19 @@
     }  
 }
 
+/* Return true if fd is in non-blocking mode. */
+static jboolean
+is_non_blocking_fd(jint fd)
+{
+  int opts;
+  opts = fcntl(fd, F_GETFL);
+  if (opts == -1)
+    {
+      /* Assume blocking on error. */
+      return 0;
+    }
+  return (opts & O_NONBLOCK) != 0;
+}
 
 JNIEXPORT jint JNICALL 
 Java_gnu_java_nio_VMChannel_read__ILjava_nio_ByteBuffer_2 (JNIEnv *env,
@@ -418,8 +431,21 @@
   else if (result == -1)
     {
       buf.count = 0;
-      if (errno == EAGAIN) /* Non-blocking */
-        result = 0;
+      if (errno == EAGAIN)
+        {
+          if (is_non_blocking_fd(fd))
+            {
+              /* Non-blocking */
+              result = 0;
+            }
+          else
+            {
+              /* Read timeout on a socket with SO_RCVTIMEO != 0. */
+              JCL_release_buffer(env, &buf, bbuf, JNI_ABORT);
+              JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "read timed out");
+              return -1;
+            }
+        }
       else if (errno == EBADF) /* Bad fd */
         {
           JCL_release_buffer(env, &buf, bbuf, JNI_ABORT);
@@ -580,8 +606,21 @@
   /* Handle the response */
   if (result < 0)
     {
-      if (errno == EAGAIN) /* Non blocking */
-        result = 0;
+      if (errno == EAGAIN)
+        {
+          if (is_non_blocking_fd(fd))
+            {
+              /* Non-blocking */
+              result = 0;
+            }
+          else
+            {
+              /* Read timeout on a socket with SO_RCVTIMEO != 0. */
+              JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read);
+              JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "read timed out");
+              return -1;
+            }
+        }
       else if (errno == EBADF) /* Bad fd */
         {
           JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read);
@@ -943,7 +982,17 @@
   errno = tmp_errno;
 
   if (-1 == ret)
-    JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+    {
+      if (errno == EAGAIN && !is_non_blocking_fd(fd))
+        {
+          /* Read timeout on a socket with SO_RCVTIMEO != 0. */
+          JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "read timed out");
+        }
+      else
+        JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+      return -1;
+    }
+  
   if (0 == ret)
     return -1;
 
@@ -1103,6 +1152,7 @@
       if (EINPROGRESS == errno)
         {
           fd_set wrfds;
+          FD_ZERO(&wrfds);
           FD_SET(fd, &wrfds);
           ret = cpnio_select (fd + 1, NULL, &wrfds, NULL, &timeo);
           if (ret == -1)
@@ -1227,6 +1277,7 @@
       if (EINPROGRESS == errno)
         {
           fd_set wrfds;
+          FD_ZERO(&wrfds);
           FD_SET(fd, &wrfds);
           ret = cpnio_select (fd + 1, NULL, &wrfds, NULL, &timeo);
           if (ret == -1)
@@ -1450,6 +1501,10 @@
           case EWOULDBLOCK:
 #endif
           case EAGAIN:
+            if (!is_non_blocking_fd(fd))
+              {
+                JCL_ThrowException(env, SOCKET_TIMEOUT_EXCEPTION, "Accept timed out");
+              }
             /* Socket in non-blocking mode and no pending connection. */
             return -1;
           default:
Index: kaffe/libraries/javalib/external/classpath/native/jni/java-nio/javanio.c
diff -u kaffe/libraries/javalib/external/classpath/native/jni/java-nio/javanio.c:1.1 kaffe/libraries/javalib/external/classpath/native/jni/java-nio/javanio.c:1.2
--- kaffe/libraries/javalib/external/classpath/native/jni/java-nio/javanio.c:1.1	Fri Jan  5 15:03:09 2007
+++ kaffe/libraries/javalib/external/classpath/native/jni/java-nio/javanio.c	Sun Jan 28 13:56:22 2007
@@ -44,6 +44,7 @@
 #include <sys/types.h>
 #include <sys/fcntl.h>
 #include <sys/socket.h>
+#include <sys/select.h>
 #include <sys/uio.h>
 #include <unistd.h>
 
@@ -86,6 +87,25 @@
 CPNIO_EXPORT int
 cpnio_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
 {
+  fd_set rset;
+  struct timeval tv;
+  socklen_t tvlen = sizeof(tv);
+  int ret;
+
+  tv.tv_sec = 0;
+  tv.tv_usec = 0;
+  getsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &tvlen);
+  if (tv.tv_sec > 0 || tv.tv_usec > 0)
+    {
+      FD_ZERO(&rset);
+      FD_SET(fd,&rset);
+      ret = select (fd+1,&rset,NULL,NULL,&tv);
+      if (ret == 0)
+        {
+          errno = EAGAIN;
+          return -1;
+        }
+    }
   return accept (fd, addr, addrlen);
 }
 




More information about the kaffe mailing list