]> granicus.if.org Git - curl/commitdiff
don't retry select() call upon unrecoverable error EBADF
authorYang Tse <yangsita@gmail.com>
Tue, 27 Mar 2007 15:22:49 +0000 (15:22 +0000)
committerYang Tse <yangsita@gmail.com>
Tue, 27 Mar 2007 15:22:49 +0000 (15:22 +0000)
lib/select.c

index 27f85fac8f0ff39724370e55cf6ab177dee8c53b..161a62161679941aaa988d0eb5d10632f6e30fd3 100644 (file)
@@ -52,6 +52,8 @@
 #include "select.h"
 
 #ifdef USE_WINSOCK
+#  undef  EBADF
+#  define EBADF  WSAEBADF
 #  undef  EINTR
 #  define EINTR  WSAEINTR
 #  undef  EINVAL
@@ -77,9 +79,9 @@
 #define elapsed_ms  (int)curlx_tvdiff(curlx_tvnow(), initial_tv)
 
 #ifdef CURL_ACKNOWLEDGE_EINTR
-#define sockerrno_not_EINTR  (SOCKERRNO != EINTR)
+#define error_not_EINTR  (error != EINTR)
 #else
-#define sockerrno_not_EINTR  (1)
+#define error_not_EINTR  (1)
 #endif
 
 /*
@@ -110,6 +112,7 @@ static int wait_ms(int timeout_ms)
 #endif
   struct timeval initial_tv;
   int pending_ms;
+  int error;
 #endif
   int r = 0;
 
@@ -134,7 +137,8 @@ static int wait_ms(int timeout_ms)
     pending_tv.tv_usec = (pending_ms % 1000) * 1000;
     r = select(0, NULL, NULL, NULL, &pending_tv);
 #endif /* HAVE_POLL_FINE */
-  } while ((r == -1) && (SOCKERRNO != EINVAL) && sockerrno_not_EINTR &&
+  } while ((r == -1) && (error = SOCKERRNO) &&
+           (error != EINVAL) && error_not_EINTR &&
            ((pending_ms = timeout_ms - elapsed_ms) > 0));
 #endif /* USE_WINSOCK */
   if (r)
@@ -175,6 +179,7 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd, int timeout_m
 #endif
   struct timeval initial_tv;
   int pending_ms;
+  int error;
   int r;
   int ret;
 
@@ -206,7 +211,8 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd, int timeout_m
     if (timeout_ms < 0)
       pending_ms = -1;
     r = poll(pfd, num, pending_ms);
-  } while ((r == -1) && (SOCKERRNO != EINVAL) && sockerrno_not_EINTR &&
+  } while ((r == -1) && (error = SOCKERRNO) &&
+           (error != EINVAL) && error_not_EINTR &&
            ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
 
   if (r < 0)
@@ -269,7 +275,8 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd, int timeout_m
       pending_tv.tv_usec = (pending_ms % 1000) * 1000;
     }
     r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
-  } while ((r == -1) && (SOCKERRNO != EINVAL) && sockerrno_not_EINTR &&
+  } while ((r == -1) && (error = SOCKERRNO) &&
+           (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
            ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
 
   if (r < 0)
@@ -327,6 +334,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
   bool fds_none = TRUE;
   unsigned int i;
   int pending_ms;
+  int error;
   int r;
 
   if (ufds) {
@@ -351,7 +359,8 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
     if (timeout_ms < 0)
       pending_ms = -1;
     r = poll(ufds, nfds, pending_ms);
-  } while ((r == -1) && (SOCKERRNO != EINVAL) && sockerrno_not_EINTR &&
+  } while ((r == -1) && (error = SOCKERRNO) &&
+           (error != EINVAL) && error_not_EINTR &&
            ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
 
 #else  /* HAVE_POLL_FINE */
@@ -386,7 +395,8 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
       pending_tv.tv_usec = (pending_ms % 1000) * 1000;
     }
     r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
-  } while ((r == -1) && (SOCKERRNO != EINVAL) && sockerrno_not_EINTR &&
+  } while ((r == -1) && (error = SOCKERRNO) &&
+           (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
            ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
 
   if (r < 0)