You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2007/12/12 09:07:02 UTC

svn commit: r603507 - /tomcat/connectors/trunk/jk/native/common/jk_connect.c

Author: rjung
Date: Wed Dec 12 00:07:02 2007
New Revision: 603507

URL: http://svn.apache.org/viewvc?rev=603507&view=rev
Log:
Use the existing macros JK_IS_SOCKET_ERROR(x)
and JK_GET_SOCKET_ERRNO() were appropriate.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_connect.c

Modified: tomcat/connectors/trunk/jk/native/common/jk_connect.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_connect.c?rev=603507&r1=603506&r2=603507&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_connect.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_connect.c Wed Dec 12 00:07:02 2007
@@ -60,8 +60,8 @@
 
 /** Set socket to blocking
  * @param sd  socket to manipulate
- * @return    errno: fcntl returns -1 /0 ! WIN32 0/
- *            pseudo errno: ioctlsocket returns SOCKET_ERROR /0 WIN32 0/
+ * @return    errno: fcntl returns -1 (!WIN32)
+ *            pseudo errno: ioctlsocket returns SOCKET_ERROR (WIN32)
  *            0: success
  */
 static int soblock(jk_sock_t sd)
@@ -85,8 +85,8 @@
     }
 #else
     u_long on = 0;
-    if (ioctlsocket(sd, FIONBIO, &on) == SOCKET_ERROR) {
-        errno = WSAGetLastError() - WSABASEERR;
+    if (JK_IS_SOCKET_ERROR(ioctlsocket(sd, FIONBIO, &on))) {
+        JK_GET_SOCKET_ERRNO();
         return errno;
     }
 #endif /* WIN32 */
@@ -95,8 +95,8 @@
 
 /** Set socket to non-blocking
  * @param sd  socket to manipulate
- * @return    errno: fcntl returns -1 /0 ! WIN32 0/
- *            pseudo errno: ioctlsocket returns SOCKET_ERROR /0 WIN32 0/
+ * @return    errno: fcntl returns -1 (!WIN32)
+ *            pseudo errno: ioctlsocket returns SOCKET_ERROR (WIN32)
  *            0: success
  */
 static int sononblock(jk_sock_t sd)
@@ -119,8 +119,8 @@
     }
 #else
     u_long on = 1;
-    if (ioctlsocket(sd, FIONBIO, &on) == SOCKET_ERROR) {
-        errno = WSAGetLastError() - WSABASEERR;
+    if (JK_IS_SOCKET_ERROR(ioctlsocket(sd, FIONBIO, &on))) {
+        JK_GET_SOCKET_ERRNO();
         return errno;
     }
 #endif /* WIN32 */
@@ -148,7 +148,7 @@
 
     if ((rc = sononblock(sock)))
         return -1;
-    if (connect(sock, addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
+    if (JK_IS_SOCKET_ERROR(connect(sock, addr, sizeof(struct sockaddr_in)))) {
         struct timeval tv;
         fd_set wfdset, efdset;
 
@@ -166,7 +166,7 @@
         tv.tv_sec  = timeout;
         tv.tv_usec = 0;
         rc = select((int)sock + 1, NULL, &wfdset, &efdset, &tv);
-        if (rc == SOCKET_ERROR || rc == 0) {
+        if (JK_IS_SOCKET_ERROR(rc) || rc == 0) {
             rc = WSAGetLastError();
             soblock(sock);
             WSASetLastError(rc);
@@ -517,8 +517,8 @@
 #endif
     ret = nb_connect(sock, (struct sockaddr *)addr, timeout, l);
 #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
-    if (ret == SOCKET_ERROR) {
-        errno = WSAGetLastError() - WSABASEERR;
+    if (JK_IS_SOCKET_ERROR(ret)) {
+        JK_GET_SOCKET_ERRNO();
     }
 #endif /* WIN32 */
 
@@ -542,19 +542,20 @@
 /** Close the socket
  * @param s         socket to close
  * @param l         logger
- * @return          -1: some kind of error occured /0 ! WIN32 0/
- *                  SOCKET_ERROR: some kind of error occured  /0 WIN32 0/
+ * @return          -1: some kind of error occured (!WIN32)
+ *                  SOCKET_ERROR: some kind of error occured  (WIN32)
  *                  0: success
  */
 int jk_close_socket(jk_sock_t s, jk_logger_t *l)
 {
-    if (IS_VALID_SOCKET(s))
+    if (!IS_VALID_SOCKET(s))
+        return -1;
+
 #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
-        return closesocket(s) ? -1 : 0;
+    return closesocket(s) ? -1 : 0;
 #else
-        return close(s);
+    return close(s);
 #endif
-    return -1;
 }
 
 #ifndef MAX_SECS_TO_LINGER
@@ -574,8 +575,8 @@
  * @param s         socket to close
  * @param l         logger
  * @return          -1: socket to close is invalid
- *                  -1: some kind of error occured /0 ! WIN32 0/
- *                  SOCKET_ERROR: some kind of error occured  /0 WIN32 0/
+ *                  -1: some kind of error occured (!WIN32)
+ *                  SOCKET_ERROR: some kind of error occured  (WIN32)
  *                  0: success
  */
 int jk_shutdown_socket(jk_sock_t s, jk_logger_t *l)
@@ -614,13 +615,12 @@
             do {
 #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
                 rc = recv(s, &dummy[0], sizeof(dummy), 0);
-                /* Assuming SOCKET_ERROR is -1 on NETWARE too */
-                if (rc == SOCKET_ERROR)
-                    errno = WSAGetLastError() - WSABASEERR;
+                if (JK_IS_SOCKET_ERROR(rc))
+                    JK_GET_SOCKET_ERRNO();
 #else
                 rc = read(s, &dummy[0], sizeof(dummy));
 #endif
-            } while (rc == -1 && (errno == EINTR || errno == EAGAIN));
+            } while (JK_IS_SOCKET_ERROR(rc) && (errno == EINTR || errno == EAGAIN));
 
             if (rc <= 0)
                 break;
@@ -638,8 +638,8 @@
  * @param b   buffer containing the data
  * @param len length to send
  * @param l   logger
- * @return    negative errno: write returns a fatal -1 /0 ! WIN32 0/
- *            negative pseudo errno: send returns SOCKET_ERROR /0 WIN32 0/
+ * @return    negative errno: write returns a fatal -1 (!WIN32)
+ *            negative pseudo errno: send returns SOCKET_ERROR (WIN32)
  *            JK_SOCKET_EOF: no bytes could be sent
  *            >0: success, total size send
  * @bug       this fails on Unixes if len is too big for the underlying
@@ -655,14 +655,14 @@
 #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
             wr = send(sd, (const char*)(b + sent),
                       len - sent, 0);
-            if (wr == SOCKET_ERROR)
-                errno = WSAGetLastError() - WSABASEERR;
+            if (JK_IS_SOCKET_ERROR(wr))
+                JK_GET_SOCKET_ERRNO();
 #else
             wr = write(sd, b + sent, len - sent);
 #endif
-        } while (wr == -1 && (errno == EINTR || errno == EAGAIN));
+        } while (JK_IS_SOCKET_ERROR(wr) && (errno == EINTR || errno == EAGAIN));
 
-        if (wr == -1)
+        if (JK_IS_SOCKET_ERROR(wr))
             return (errno > 0) ? -errno : errno;
         else if (wr == 0)
             return JK_SOCKET_EOF;
@@ -677,8 +677,8 @@
  * @param b   buffer to store the data
  * @param len length to receive
  * @param l   logger
- * @return    negative errno: read returns a fatal -1 /0 ! WIN32 0/
- *            negative pseudo errno: recv returns SOCKET_ERROR /0 WIN32 0/
+ * @return    negative errno: read returns a fatal -1 (!WIN32)
+ *            negative pseudo errno: recv returns SOCKET_ERROR (WIN32)
  *            JK_SOCKET_EOF: no bytes could be read
  *            >0: success, total size received
  */
@@ -692,15 +692,14 @@
 #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
             rd = recv(sd, (char *)b + rdlen,
                       len - rdlen, 0);
-            /* Assuming SOCKET_ERROR is -1 on NETWARE too */
-            if (rd == SOCKET_ERROR)
-                errno = WSAGetLastError() - WSABASEERR;
+            if (JK_IS_SOCKET_ERROR(rd))
+                JK_GET_SOCKET_ERRNO();
 #else
             rd = read(sd, (char *)b + rdlen, len - rdlen);
 #endif
-        } while (rd == -1 && (errno == EINTR || errno == EAGAIN));
+        } while (JK_IS_SOCKET_ERROR(rd) && (errno == EINTR || errno == EAGAIN));
 
-        if (rd == -1)
+        if (JK_IS_SOCKET_ERROR(rd))
             return (errno > 0) ? -errno : errno;
         else if (rd == 0)
             return JK_SOCKET_EOF;
@@ -748,13 +747,11 @@
 
     do {
         rc = select((int)sock + 1, &fd, NULL, NULL, &tv);
-#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
-        errno = WSAGetLastError() - WSABASEERR;
-#endif
+        JK_GET_SOCKET_ERRNO();
         /* Wait one microsecond on next select, if EINTR */
         tv.tv_sec  = 0;
         tv.tv_usec = 1;
-    } while (rc == -1 && errno == EINTR);
+    } while (JK_IS_SOCKET_ERROR(rc) && errno == EINTR);
 
     if (rc == 0) {
         /* If we get a timeout, then we are still connected */
@@ -767,10 +764,10 @@
             if (WSAGetLastError() == 0)
                 errno = 0;
             else
-                errno = WSAGetLastError() - WSABASEERR;
+                JK_GET_SOCKET_ERRNO();
             return nr == 0 ? JK_FALSE : JK_TRUE;
         }
-        errno = WSAGetLastError() - WSABASEERR;
+        JK_GET_SOCKET_ERRNO();
 #else
         int nr;
         if (ioctl(sock, FIONREAD, (void*)&nr) == 0) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org