Author: mturk
Date: Fri Jun 24 06:33:00 2011
New Revision: 1139165

URL: http://svn.apache.org/viewvc?rev=1139165&view=rev
Log:
Check for socket error in case select returns ENOTSOCK

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/pollset.c
    commons/sandbox/runtime/trunk/src/main/native/shared/select.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h?rev=1139165&r1=1139164&r2=1139165&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h Fri Jun 
24 06:33:00 2011
@@ -199,6 +199,9 @@
 #include <langinfo.h>
 #endif
 
+#include <signal.h>
+#include <setjmp.h>
+
 #if defined(WIN32)
 /* Add MSVCRT specific includes
  */
@@ -210,8 +213,6 @@
 #else
 /* Add POSIX specific includes
  */
-# include <signal.h>
-# include <setjmp.h>
 # if HAVE_UCONTEXT_H
 #  include <ucontext.h>
 # endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1139165&r1=1139164&r2=1139165&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Fri Jun 24 
06:33:00 2011
@@ -98,7 +98,7 @@ ACR_NET_EXPORT(jint, Poll, wait0)(JNI_ST
     for (;;) {
         ns = poll(pfd, nevents, timeout);
         if (ns == -1 && errno == EINTR) {
-            if (timeout >= 0) {
+            if (timeout > 0) {
                 timeout = tmx - AcrTimeMilliseconds();
                 if (timeout <= 0) {
                     ns = 0;
@@ -144,7 +144,7 @@ ACR_NET_EXPORT(jshort, Poll, wait1)(JNI_
     for (;;) {
         ns = poll(&pfd, 1, timeout);
         if (ns == -1 && errno == EINTR) {
-            if (timeout >= 0) {
+            if (timeout > 0) {
                 timeout = tmx - AcrTimeMilliseconds();
                 if (timeout <= 0) {
                     ns = 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pollset.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pollset.c?rev=1139165&r1=1139164&r2=1139165&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/pollset.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pollset.c Fri Jun 24 
06:33:00 2011
@@ -277,7 +277,7 @@ ACR_NET_EXPORT(jint, PollSelector, wait0
     for (;;) {
         ns = poll(ps->fdset, ps->used, timeout);
         if (ns == -1 && errno == EINTR) {
-            if (timeout >= 0) {
+            if (timeout > 0) {
                 timeout = tmx - AcrTimeMilliseconds();
                 if (timeout <= 0) {
                     ns = 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/select.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/select.c?rev=1139165&r1=1139164&r2=1139165&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/select.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/select.c Fri Jun 24 
06:33:00 2011
@@ -33,7 +33,7 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
     acr_time_t tmx = 0;
 #endif
     acr_fd_t  *fd;
-    struct timeval  tv;
+    struct timeval  tv = { 0, 0 };
     struct timeval *tp = 0;
     fd_set rdset, wrset, exset;
     jshort *pevents;
@@ -76,9 +76,10 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
             nmax = fd->u.f;
     }
     RELEASE_CRITICAL(events, pevents);
-    if (timeout > 0) {
+    if (timeout >= 0) {
 #if !defined(WINDOWS)
-        tmx = AcrTimeNow() +  AcrTimeFromMsec(timeout);
+        if (timeout > 0)
+            tmx = AcrTimeNow() +  AcrTimeFromMsec(timeout);
 #endif
         tp  = &tv;
     }
@@ -91,7 +92,7 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
         ns = select(nmax + 1, &rdset, &wrset, &exset, tp);
 #if !defined(WINDOWS)
         if (ns == -1 && errno == EINTR) {
-            if (timeout >= 0) {
+            if (timeout > 0) {
                 timeout = tmx - AcrTimeNow();
                 if (timeout <= 0) {
                     ns = 0;
@@ -104,8 +105,32 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
         break;
     }
     if (ns == -1) {
-        ACR_THROW_NET_ERRNO();
+        int err = ACR_GET_NETOS_ERROR();
+#if defined(WINDOWS)
+        if (err == WSAENOTSOCK)
+            int optval;
+            int optlen = ISIZEOF(optval);
+
+            ns = 0;
+            pevents = JARRAY_CRITICAL(jshort, revents);
+            for (i = 0; i < nevents; i++) {
+                fd = J2P(pfdset[i], acr_fd_t *);
+                if (getsockopt(fd->u.s, SOL_SOCKET, SO_TYPE, (char *)&optval, 
&optlen) == -1) {
+                    if (WSAGetLastError() == WSAENOTSOCK) {
+                        pevents[i] = ACR_OP_ERROR | ACR_OP_NVAL;
+                        ns++;
+                    }
+                }            
+            }
+            RELEASE_CRITICAL(revents, pevents);
+            if (ns != 0) {
+                RELEASE_CRITICAL(fdset, pfdset);
+                return ns;
+            }
+        }
+#endif
         RELEASE_CRITICAL(fdset,  pfdset);
+        ACR_THROW_NET_ERROR(err);
         return 0;
     }
     pevents = JARRAY_CRITICAL(jshort, revents);
@@ -152,14 +177,14 @@ ACR_NET_EXPORT(jshort, Select, wait1)(JN
     if (events & ~(ACR_OP_INP | ACR_OP_OUT)) {
         FD_SET(fd->u.s, &exset);
     }    
-    if (timeout > 0) {
+    if (timeout >= 0) {
 #if !defined(WINDOWS)
         tmx = AcrTimeNow() +  AcrTimeFromMsec(timeout);
 #endif
         tp  = &tv;
     }
     for (;;) {
-        if (timeout > 0) {
+        if (timeout >= 0) {
             acr_time_t us = AcrTimeFromMsec(timeout);
             tv.tv_sec  = (long)AcrTimeSec(us);
             tv.tv_usec = (long)AcrTimeUsec(us);
@@ -180,7 +205,19 @@ ACR_NET_EXPORT(jshort, Select, wait1)(JN
         break;
     }
     if (ns == -1) {
-        ACR_THROW_NET_ERRNO();
+        int err = ACR_GET_NETOS_ERROR();
+#if defined(WINDOWS)
+        if (err == WSAENOTSOCK)
+            int optval;
+            int optlen = ISIZEOF(optval);
+
+            if (getsockopt(fd->u.s, SOL_SOCKET, SO_TYPE, (char *)&optval, 
&optlen) == -1) {
+                if (WSAGetLastError() == WSAENOTSOCK)
+                    return ACR_OP_ERROR | ACR_OP_NVAL;
+            }
+        }
+#endif
+        ACR_THROW_NET_ERROR(err);
         return 0;
     }
     else {


Reply via email to