harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r545748 - in /harmony/enhanced/classlib/trunk/modules: luni/src/main/native/luni/unix/OSNetworkSystemLinux.c portlib/src/main/native/include/unix/hysock.h portlib/src/main/native/port/unix/hysock.c
Date Sat, 09 Jun 2007 14:05:34 GMT
Author: ayza
Date: Sat Jun  9 07:05:33 2007
New Revision: 545748

URL: http://svn.apache.org/viewvc?view=rev&rev=545748
Log:
Reworked patch from HARMONY-4077 ([classlib][portlib] socket related functions incorrectly
work in socket > FD_SETSIZE) was applied

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/unix/hysock.h
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?view=diff&rev=545748&r1=545747&r2=545748
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Sat Jun  9 07:05:33 2007
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 #include <netinet/in.h>
 #endif
+#include <sys/poll.h>
 #include <netinet/in_systm.h>
 #include<netinet/ip.h>
 #include<netinet/ip_icmp.h>
@@ -37,27 +38,18 @@
 unsigned short ip_checksum(unsigned short * buffer, int size);
 void set_icmp_packet(struct icmp * icmp_hdr, int packet_size);
 
-//Alternative Select function
+// Alternative Select function
 int
 selectRead (JNIEnv * env,hysocket_t hysocketP, I_32 uSecTime, BOOLEAN accept){
   PORT_ACCESS_FROM_ENV (env);
-  hytimeval_struct timeP;
-  hyfdset_t fdset_read;
   I_32 result = 0;
-  I_32 size = 0;
-  if (0 <= uSecTime)
-    hysock_timeval_init (0, uSecTime, &timeP);
-
-  fdset_read = hymem_allocate_memory(sizeof (struct hyfdset_struct));
-  FD_ZERO (&fdset_read->handle);
-  FD_SET (hysocketP->sock, &fdset_read->handle);
-  size =hysocketP->sock + 1;
-
-  if (0 <= uSecTime)
-    result = hysock_select (size, fdset_read, NULL, NULL,&timeP);
-  else
-    result = hysock_select (size, fdset_read, NULL, NULL,NULL);
-  hymem_free_memory(fdset_read);
+  struct pollfd my_pollfd;
+
+  my_pollfd.fd = hysocketP->sock;
+  my_pollfd.events = POLLIN | POLLPRI;
+  my_pollfd.revents = 0;
+  result = poll (&my_pollfd, 1, TO_MILLIS(0, uSecTime));
+  
   return result;
 }
 
@@ -67,8 +59,7 @@
   struct icmp * send_buf = 0;
   struct ip * recv_buf = 0;
   int result,ret=UNREACHABLE;
-  struct timeval timeP;
-  fd_set * fdset_read = NULL;
+  struct pollfd my_pollfd;
   int sockadd_size = sizeof (source);
   jbyte host[HYSOCK_INADDR6_LEN];
   U_32 length =  (*env)->GetArrayLength (env,address);
@@ -103,7 +94,8 @@
   send_buf = (struct icmp*)malloc(sizeof(char)*ICMP_SIZE);
   recv_buf = (struct ip*)malloc(sizeof(char)*PACKET_SIZE);
   if (NULL == send_buf || NULL == recv_buf){
-	  return NOPRIVILEGE;
+	  ret = NOPRIVILEGE;
+      goto cleanup;
   }
   set_icmp_packet(send_buf, ICMP_SIZE);
 
@@ -111,15 +103,16 @@
             (struct sockaddr*)&dest, sizeof(dest))){
             goto cleanup;
   }
-  //set select timeout, change millisecond to usec
-  memset (&timeP, 0, sizeof (struct timeval));    
-  timeP.tv_sec = timeout/1000;
-  timeP.tv_usec = timeout%1000*1000;
-  result = select (sock+1, fdset_read, NULL, NULL,&timeP);
-  fdset_read = (fd_set *)malloc(sizeof (fd_set));
-  FD_ZERO (fdset_read);
-  FD_SET (sock, fdset_read);
-  result = select (sock+1, fdset_read, NULL, NULL,&timeP);
+
+  //don't ask what is it - just kinda sleep
+  my_pollfd.fd = 0;
+  my_pollfd.events = 0;
+  result = poll(&my_pollfd, 1, timeout);
+
+  my_pollfd.fd = sock;
+  my_pollfd.events = POLLIN | POLLPRI;
+  result = poll(&my_pollfd, 1, timeout);
+
   if (SOCKET_ERROR == result || 0 == result){
   	goto cleanup;
   }  
@@ -141,9 +134,15 @@
   }
   ret = REACHABLE;
 cleanup:
-  free(fdset_read);
-  free(send_buf);
-  free(recv_buf);
+
+  if (send_buf != NULL) {
+      free(send_buf);
+  }
+
+  if (recv_buf != NULL) {
+      free(recv_buf);
+  }
+
   return ret;
 }
 
@@ -188,85 +187,65 @@
   (JNIEnv * env, jclass	thisClz, jobjectArray readFDArray, jobjectArray	writeFDArray,
    jint	countReadC, jint countWriteC, jintArray	outFlags, jlong	timeout){
   PORT_ACCESS_FROM_ENV (env);
-  hytimeval_struct timeP;	
   I_32 result =	0;		
-  I_32 size = 0;		
-  jobject gotFD;		
-  hyfdset_t fdset_read,fdset_write;
   hysocket_t hysocketP;		
   jboolean isCopy ;
   jint *flagArray;
   int val;
-  U_32 time_sec = (U_32)timeout/1000;
-  U_32 time_msec = (U_32)(timeout%1000)*1000;
+  struct pollfd * my_pollfds;
+  int n_pollfds;
+  jobject gotFD;
 
-  fdset_read = hymem_allocate_memory(sizeof (struct hyfdset_struct));
-  fdset_write =	hymem_allocate_memory(sizeof (struct hyfdset_struct));
-  
-  FD_ZERO (&fdset_read->handle);
-  FD_ZERO (&fdset_write->handle);
-  for (val = 0; val<countReadC; val++){
-	  gotFD	= (*env)->GetObjectArrayElement(env,readFDArray,val);
+  n_pollfds = countReadC + countWriteC;
+
+  my_pollfds = hymem_allocate_memory(sizeof(struct pollfd) * n_pollfds);
+  if (my_pollfds == NULL) {
+      return HYPORT_ERROR_SYSTEMFULL;
+  }
+
+  for (val=0; val<countReadC; val++) {
+	  gotFD	= (*env)->GetObjectArrayElement(env, readFDArray, val);
 	  hysocketP = getJavaIoFileDescriptorContentsAsAPointer	(env, gotFD);
-	  /*No difference between ipv4 and ipv6 as in windows*/
-		FD_SET (hysocketP->sock, &fdset_read->handle);
-		if (0 >	(size -	hysocketP->sock))
-			size = hysocketP->sock;		
-	}
-  for (val = 0; val<countWriteC; val++){
-	  gotFD	= (*env)->GetObjectArrayElement(env,writeFDArray,val);
+
+      my_pollfds[val].fd = hysocketP->sock;
+      my_pollfds[val].events = POLLIN | POLLPRI;
+      my_pollfds[val].revents = 0;
+  }
+
+  for (val=0; val<countWriteC; val++) {
+	  gotFD	= (*env)->GetObjectArrayElement(env, writeFDArray, val);
 	  hysocketP = getJavaIoFileDescriptorContentsAsAPointer	(env, gotFD);
-	  /*No difference between ipv4 and ipv6 as in windows*/
-	  FD_SET (hysocketP->sock, &fdset_write->handle);	
-		if (0 >	(size -	hysocketP->sock))
-			size = hysocketP->sock;	
-	}
-  /* the size is the max_fd + 1	*/
-  size =size + 1;
-
-  if (0	> size)	
-    {
-      result = HYPORT_ERROR_SOCKET_FDSET_SIZEBAD;
-    }
-  else
-    {
-      /* only set when timeout >= 0 (non-block)*/
-      if (0 <= timeout){
-		hysock_timeval_init (time_sec, time_msec, &timeP);
-		result = hysock_select (size, fdset_read, fdset_write, NULL,&timeP);
-      }	
-      else{
-		result = hysock_select (size, fdset_read, fdset_write, NULL,NULL);
-      }	
-    }
-    
-  if (0	< result){
-	  /*output the reslut to a int array*/
+
+      my_pollfds[countReadC + val].fd = hysocketP->sock;
+      my_pollfds[countReadC + val].events = POLLOUT;
+      my_pollfds[countReadC + val].revents = 0;
+  }
+
+  result = poll(my_pollfds, n_pollfds, timeout);
+
+  if (result > 0) {
+	  /* output result to int array */
 	  flagArray = (*env)->GetIntArrayElements(env,outFlags,	&isCopy);
-	  for (val=0;val<countReadC;val++){
-		gotFD =	(*env)->GetObjectArrayElement(env,readFDArray,val);
-		hysocketP = getJavaIoFileDescriptorContentsAsAPointer (env, gotFD);
-		if (FD_ISSET(hysocketP->sock,&fdset_read->handle))
-			flagArray[val] = SOCKET_OP_READ;
-		else
-			flagArray[val] = SOCKET_OP_NONE;
-
-	 }
-		
-	  for (val=0;val<countWriteC;val++){
-		gotFD =	(*env)->GetObjectArrayElement(env,writeFDArray,val);
-		hysocketP = getJavaIoFileDescriptorContentsAsAPointer (env, gotFD);
-		if (FD_ISSET(hysocketP->sock,&fdset_write->handle))
-			flagArray[val+countReadC] = SOCKET_OP_WRITE;
-		else
-			flagArray[val+countReadC] = SOCKET_OP_NONE;
-
-		}
-	(*env)->ReleaseIntArrayElements(env,outFlags, flagArray, 0); 
-  }
-  hymem_free_memory(fdset_write);
-  hymem_free_memory(fdset_read);
-  /* return both correct and error result, let java code handle	the exception*/
+	  for (val=0; val<countReadC; val++) {
+          if (my_pollfds[val].revents & (POLLIN | POLLPRI)) {
+              flagArray[val] = SOCKET_OP_READ;
+          } else {
+              flagArray[val] = SOCKET_OP_NONE;
+          }
+      }
+
+	  for (val=0; val<countWriteC; val++) {
+          if (my_pollfds[val+countReadC].revents & POLLOUT) {
+              flagArray[val+countReadC] = SOCKET_OP_WRITE;
+          } else {
+              flagArray[val+countReadC] = SOCKET_OP_NONE;
+          }
+      }
+      (*env)->ReleaseIntArrayElements(env, outFlags, flagArray, 0);
+  }
+  hymem_free_memory(my_pollfds);
+  
+  /* return both correct and error result, let java code handle	exceptions */
   return result;
 };
 

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/unix/hysock.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/unix/hysock.h?view=diff&rev=545748&r1=545747&r2=545748
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/unix/hysock.h
(original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/include/unix/hysock.h
Sat Jun  9 07:05:33 2007
@@ -60,6 +60,8 @@
 #define NO_R (defined(MACOSX))
 /* OTHER_R: everything else */
 #define OTHER_R ((!HOSTENT_DATA_R)&&(!GLIBC_R)&&(!ORIGINAL_R)&&(!NO_R))
+/* Converts (seconds, microseconds) to milliseconds */
+#define TO_MILLIS(sec, microsec) (sec * 1000 + (microsec + 999) / 1000)
 /* os types */
 typedef int OSSOCKET;           /* as returned by socket() */
 typedef struct sockaddr_in OSSOCKADDR;  /* as used by bind() and friends */

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c?view=diff&rev=545748&r1=545747&r2=545748
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c (original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/unix/hysock.c Sat
Jun  9 07:05:33 2007
@@ -2,7 +2,7 @@
  *  Licensed to the Apache Software Foundation (ASF) under one or more
  *  contributor license agreements.  See the NOTICE file distributed with
  *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  The ASF licenses this file to You under the Apache License, Version 2.0 
  *  (the "License"); you may not use this file except in compliance with
  *  the License.  You may obtain a copy of the License at
  *
@@ -33,6 +33,7 @@
 
 #include <errno.h>
 #include <sys/types.h>
+#include <sys/poll.h>
 #include <sys/socket.h>
 #include <netinet/in.h>         /* for struct in_addr */
 #include <arpa/inet.h>          /* for inet_addr */
@@ -100,16 +101,6 @@
 
 #define VALIDATE_ALLOCATIONS 1
 
-/* needed for connect_with_timeout */
-typedef struct selectFDSet_struct
-{
-  int nfds;
-  int sock;
-  fd_set writeSet;
-  fd_set readSet;
-  fd_set exceptionSet;
-} selectFDSet_struct;
-
 #define CDEV_CURRENT_FUNCTION _prototypes_private
 
 I_32 platformSocketOption (I_32 portableSocketOption);
@@ -2571,6 +2562,11 @@
     I_32 rc = 0;
     I_32 result = 0;
 
+    if (nfds >= FD_SETSIZE) {
+        rc = portLibrary->error_set_last_error(portLibrary, errno, 
+                                               HYPORT_ERROR_SOCKET_UNIX_EINVAL);
+        return -1;
+    }
     result = select (nfds, 
                         readfds == NULL ? NULL : &readfds->handle,
                         writefds == NULL ? NULL : &writefds->handle,
@@ -2609,7 +2605,6 @@
  * The portable version of a read operation is a blocking call (will wait indefinitely for
data).
  * This function should be called prior to a read operation, to provide a read timeout.
  * If the result is 1, the caller is guaranteed to be able to complete a read on the socket
without blocking.
- * The actual contents of the fdset are not available for inspection (as provided in the
more general 'select' function).
  * The timeout is specified in seconds and microseconds.
  * If the timeout is 0, skip this function (and thus the caller of a subsequent read operation
may block).
  *
@@ -2628,42 +2623,40 @@
 hysock_select_read (struct HyPortLibrary * portLibrary, hysocket_t hysocketP,
                     I_32 secTime, I_32 uSecTime, BOOLEAN accept)
 {
-  hytimeval_struct timeP;
-  I_32 result = 0;
-  I_32 size = 0, flags = 0;
-  PortlibPTBuffers_t ptBuffers;
+  // Current implementation uses poll() system routine since select()
+  // has issues if fd_num is greater than FD_SETSIZE. See HARMONY-4077.
 
-  ptBuffers = hyport_tls_get (portLibrary);
-  if (NULL == ptBuffers)
-    {
-      return HYPORT_ERROR_SOCKET_SYSTEMFULL;
-    }
-
-/* The max fdset size per process is always expected to be less than a 32bit integer value.
- * Is this valid on a 64bit platform?
- */
-
-  /* Removed check for zero timeout */
+  int poll_timeout;
+  I_32 result = 0;
+  I_32 rc = 0;
+  struct pollfd my_pollfd;
 
-  result = hysock_fdset_init (portLibrary, hysocketP);
-  if (0 != result)
-    {
-      return result;
-    }
+  my_pollfd.fd = SOCKET_CAST(hysocketP);
+  my_pollfd.events = POLLIN | POLLPRI;
+  my_pollfd.revents = 0;
+  poll_timeout = TO_MILLIS(secTime, uSecTime);
+
+  result = poll(&my_pollfd, 1, poll_timeout);
+
+  if (result == -1) {
+      HYSOCKDEBUG ("<poll failed, err=%d>\n", errno);
+
+      if (errno == EINTR) {
+          rc = portLibrary->error_set_last_error(portLibrary, errno, 
+                                                 HYPORT_ERROR_SOCKET_INTERRUPTED);
+      } else {
+          rc = portLibrary->error_set_last_error(portLibrary, errno,
+                                                 HYPORT_ERROR_SOCKET_OPFAILED);
+      }
+  } else {
+      if (result || poll_timeout == 0) {
+      	  rc = result;
+      } else {
+          rc = HYPORT_ERROR_SOCKET_TIMEOUT;
+      }
+  }
 
-  hysock_timeval_init (portLibrary, secTime, uSecTime, &timeP);
-  size = hysock_fdset_size (portLibrary, hysocketP);
-  if (0 > size)
-    {
-      result = HYPORT_ERROR_SOCKET_FDSET_SIZEBAD;
-    }
-  else
-    {
-      result =
-        hysock_select (portLibrary, size, ptBuffers->fdset, NULL, NULL,
-                       &timeP);
-    }
-  return result;
+  return rc;
 }
 
 #undef CDEV_CURRENT_FUNCTION
@@ -4923,7 +4916,10 @@
 #if (defined(HAS_RTNETLINK))
   struct sockaddr_nl address;
   U_32 receiveLength;
+  struct pollfd my_pollfd;
   socklen_t addressLength = sizeof (address);
+  int result;
+
   for (;;)
     {
       /* check if we are done */
@@ -4943,24 +4939,17 @@
 
     /* 
      * if the remainingLength is 0 then there was no messages available in the existing data

-     * so read another datagram containing messages we first use a select to make sure we

+     * so read another datagram containing messages we first use a poll to make sure we 
      * don't block forever if for some reason there is no netlink message to read 
      */
      
       if (netlinkContext->remainingLength == 0)
         {
-          fd_set waitSockets;
-          struct timeval waitTime;
-          waitTime.tv_sec = NETLINK_READTIMEOUT_SECS;
-          waitTime.tv_usec = 0;
-          FD_ZERO (&waitSockets);
-          FD_SET (netlinkContext->netlinkSocketHandle, &waitSockets);
-                     
-          if (select
-              (netlinkContext->netlinkSocketHandle + 1, &waitSockets, NULL,
-               NULL, &waitTime) > 0)
-            {
-                
+          my_pollfd.fd = netlinkContext->netlinkSocketHandle;
+          my_pollfd.events = POLLIN | POLLPRI;
+          my_pollfd.revents = 0;
+
+          if (poll(&my_pollfd, 1, NETLINK_READTIMEOUT_SECS * 1000) > 0) {
                 struct sockaddr_nl nladdr;
                 struct msghdr msg;
                 struct iovec iov;
@@ -5127,38 +5116,12 @@
                              U_32 step, U_8 ** context)
 {
   I_32 rc = 0;
-  struct timeval passedTimeout;
   int errorVal;
   int errorValLen = sizeof (int);
+  struct pollfd my_pollfd;
 
   if (HY_PORT_SOCKET_STEP_START == step)
     {
-      /* initialize the context to a known state */
-      if (NULL != context)
-        {
-          *context = NULL;
-        }
-      else
-        {
-          /* this should never happen but just in case */
-          return HYPORT_ERROR_SOCKET_NORECOVERY;
-        }
-
-      /* we will be looping checking for when we are connected so allocate the descriptor
sets that we will use */
-      *context =
-        (U_8 *) portLibrary->mem_allocate_memory (portLibrary,
-                                                  sizeof (struct
-                                                          selectFDSet_struct));
-#if (defined(VALIDATE_ALLOCATIONS))
-      if (NULL == *context)
-        {
-          return HYPORT_ERROR_SOCKET_NOBUFFERS;
-        }
-#endif
-
-      ((struct selectFDSet_struct *) *context)->sock = SOCKET_CAST (sock);
-      ((struct selectFDSet_struct *) *context)->nfds = SOCKET_CAST (sock) + 1;
-
       /* set the socket to non-blocking */
       rc = hysock_set_nonblocking (portLibrary, sock, TRUE);
       if (0 != rc)
@@ -5166,14 +5129,13 @@
           return rc;
         }
 
-      rc =
-        connect (SOCKET_CAST (sock), (struct sockaddr *) &addr->addr,
-                 sizeof (addr->addr));
+      rc = connect
+          (SOCKET_CAST (sock), (struct sockaddr *) &addr->addr,
+           sizeof (addr->addr));
       if (rc < 0)
         {
           rc = errno;
-          switch (rc)
-            {
+          switch (rc) {
             case HYPORT_ERROR_SOCKET_UNIX_EINTR:
               return HYPORT_ERROR_SOCKET_ALREADYBOUND;
             case HYPORT_ERROR_SOCKET_UNIX_EAGAIN:
@@ -5186,54 +5148,32 @@
           return rc;
         }
 
-      /* we connected right off the bat so just return */
-      return rc;
+        /* we connected right off the bat so just return */
+        return rc;
 
-    }
-  else if (HY_PORT_SOCKET_STEP_CHECK == step)
-    {
+      }
+    else if (HY_PORT_SOCKET_STEP_CHECK == step)
+      {
       /* now check if we have connected yet */
 
       /* set the timeout value to be used. Because on some unix platforms we don't get notified
when a socket
          is closed we only sleep for 100ms at a time */
-      passedTimeout.tv_sec = 0;
-      if (timeout > 100)
-        {
-          passedTimeout.tv_usec = 100 * 1000;
-        }
-      else if ((I_32)timeout >= 0)
-        {
-          passedTimeout.tv_usec = timeout * 1000;
-        }
+      timeout = timeout > 100 ? 100 : timeout;
 
       /* initialize the FD sets for the select */
-      FD_ZERO (&(((struct selectFDSet_struct *) *context)->exceptionSet));
-      FD_ZERO (&(((struct selectFDSet_struct *) *context)->writeSet));
-      FD_ZERO (&(((struct selectFDSet_struct *) *context)->readSet));
-      FD_SET (((struct selectFDSet_struct *) *context)->sock,
-              &(((struct selectFDSet_struct *) *context)->writeSet));
-      FD_SET (((struct selectFDSet_struct *) *context)->sock,
-              &(((struct selectFDSet_struct *) *context)->readSet));
-      FD_SET (((struct selectFDSet_struct *) *context)->sock,
-              &(((struct selectFDSet_struct *) *context)->exceptionSet));
-      rc =
-        select (((struct selectFDSet_struct *) *context)->nfds,
-                &(((struct selectFDSet_struct *) *context)->readSet),
-                &(((struct selectFDSet_struct *) *context)->writeSet),
-                &(((struct selectFDSet_struct *) *context)->exceptionSet),
-                (I_32)timeout >= 0 ? &passedTimeout : NULL);
+      my_pollfd.fd = SOCKET_CAST(sock);
+      my_pollfd.events = POLLIN | POLLPRI | POLLOUT;
+      my_pollfd.revents = 0;
 
+      rc = poll(&my_pollfd, 1, timeout);
+      
       /* if there is at least one descriptor ready to be checked */
       if (0 < rc)
         {
           /* if the descriptor is in the write set then we have connected or failed */
-          if (FD_ISSET
-              (((struct selectFDSet_struct *) *context)->sock,
-               &(((struct selectFDSet_struct *) *context)->writeSet)))
-            {
-              if (!FD_ISSET
-                  (((struct selectFDSet_struct *) *context)->sock,
-                   &(((struct selectFDSet_struct *) *context)->readSet)))
+
+          if (my_pollfd.revents & POLLOUT) {
+              if (!(my_pollfd.revents & (POLLIN | POLLPRI)))
                 {
                   /* ok we have connected ok */
                   return 0;
@@ -5241,39 +5181,28 @@
               else
                 {
                   /* ok we have more work to do to figure it out */
-                  if (getsockopt
-                      (((struct selectFDSet_struct *) *context)->sock,
-                       SOL_SOCKET, SO_ERROR, (char *) &errorVal,
-                       &errorValLen) >= 0)
-                    {
-                        return errorVal ? findError(errorVal):0; 
-                    }
-                  else
-                    {
+                  if (getsockopt (SOCKET_CAST(sock), SOL_SOCKET, SO_ERROR,
+                                  (char *) &errorVal, &errorValLen) >= 0) {
+                      return errorVal ? findError(errorVal):0; 
+                  } else {
                       rc = errno;
                       return portLibrary->error_set_last_error (portLibrary,
                                                                 rc,
-                                                                findError
-                                                                (rc));
-                    }
-                }
-            }
+                                                                findError(rc));
+                  }
+              }
+          }
 
           /* if the descriptor is in the exception set then the connect failed */
-          if (FD_ISSET
-              (((struct selectFDSet_struct *) *context)->sock,
-               &(((struct selectFDSet_struct *) *context)->exceptionSet)))
-            {
-              if (getsockopt
-                  (((struct selectFDSet_struct *) *context)->sock, SOL_SOCKET,
-                   SO_ERROR, (char *) &errorVal, &errorValLen) >= 0)
-                {
-                     return errorVal ? findError(errorVal):0; 
-                }
+          if (my_pollfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
+              if (getsockopt(SOCKET_CAST(sock), SOL_SOCKET, SO_ERROR,
+                             (char *) &errorVal, &errorValLen) >= 0) {
+                  return errorVal ? findError(errorVal):0; 
+              }
               rc = errno;
               return portLibrary->error_set_last_error (portLibrary, rc,
                                                         findError (rc));
-            }
+          }
 
         }
       else if (rc < 0)
@@ -5290,26 +5219,20 @@
           /* some other error occured so look it up and return */
           return portLibrary->error_set_last_error (portLibrary, rc,
                                                     findError (rc));
-        }
+      }
 
       /* if we get here the timeout expired or the connect had not yet completed
-         just indicate that the connect is not yet complete */
+         just indicate that the connect is not yet complete  */
       return HYPORT_ERROR_SOCKET_NOTCONNECTED;
     }
   else if (HY_PORT_SOCKET_STEP_DONE == step)
     {
-      /* we are done the connect or an error occured so clean up  */
-      if (sock != INVALID_SOCKET)
-        {
-          hysock_set_nonblocking (portLibrary, sock, FALSE);
-        }
-
-      /* free the memory for the FD set */
-      if ((context != NULL) && (*context != NULL))
-        {
-          portLibrary->mem_free_memory (portLibrary, *context);
-        }
-      return 0;
+        /* we are done the connect or an error occured so clean up  */
+        if (sock != INVALID_SOCKET)
+          {
+            hysock_set_nonblocking (portLibrary, sock, FALSE);
+          }
+        return 0;
     }
   return HYPORT_ERROR_SOCKET_ARGSINVALID;
 }



Mime
View raw message