mturk       2005/05/26 07:39:37

  Modified:    jk/native/common jk_connect.c
  Log:
  Add nonblocking detection for socket connections from pre 1.2.8
  for non winsock platform.
  Also check for EAGAIN while reading data.
  Thanks to Kresimir Kukulj and his intensive testing for transient errors.
  
  Revision  Changes    Path
  1.60      +34 -7     jakarta-tomcat-connectors/jk/native/common/jk_connect.c
  
  Index: jk_connect.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_connect.c,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- jk_connect.c      13 May 2005 08:23:11 -0000      1.59
  +++ jk_connect.c      26 May 2005 14:39:37 -0000      1.60
  @@ -552,7 +552,7 @@
   #else
               wr = write(sd, b + sent, len - sent);
   #endif
  -        } while (wr == -1 && errno == EINTR);
  +        } while (wr == -1 && (errno == EINTR || errno == EAGAIN));
   
           if (wr == -1)
               return (errno > 0) ? -errno : errno;
  @@ -587,7 +587,7 @@
   #else
               rd = read(sd, (char *)b + rdlen, len - rdlen);
   #endif
  -        } while (rd == -1 && errno == EINTR);
  +        } while (rd == -1 && (errno == EINTR || errno == EAGAIN));
   
           if (rd == -1)
               return (errno > 0) ? -errno : errno;
  @@ -615,6 +615,7 @@
       return buf;
   }
   
  +#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
   int jk_is_socket_connected(int sd)
   {
       fd_set fd;
  @@ -629,15 +630,41 @@
       tv.tv_usec = 1;
   
       /* If we get a timeout, then we are still connected */
  -    if ((rc = select(1, &fd, NULL, NULL, &tv)) == 0)
  +    if ((rc = select(1, &fd, NULL, NULL, &tv)) == 0) {
  +        errno = 0;
           return 1;
  +    }
       else {
  -#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
           if (rc == SOCKET_ERROR)
               errno = WSAGetLastError() - WSABASEERR;
           else
  -            errno = 0;
  -#endif
  +            errno = EOF;
           return 0;
       }
   }
  +#else
  +int jk_is_socket_connected(int sd)
  +{
  +    char test_buffer[1];
  +    int  rd;
  +    int  saved_errno;
  +
  +    errno = 0;
  +    /* Set socket to nonblocking */
  +    if (sononblock(sd) != 0)
  +        return 0;
  +    do {
  +        rd = read(sd, test_buffer, 1);
  +    } while (rd == -1 && errno == EINTR);
  +    saved_errno = errno;
  +    soblock(sd);
  +    if (rd == -1 && saved_errno == EWOULDBLOCK) {
  +    errno = 0;
  +        return 1;
  +    }
  +    else {
  +        errno = saved_errno ? saved_errno : EOF;
  +        return 0;
  +    }
  +}
  +#endif
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to