Index: curl/lib/select.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/select.c,v
retrieving revision 1.41
diff -u -r1.41 select.c
--- curl/lib/select.c	16 Apr 2007 16:34:08 -0000	1.41
+++ curl/lib/select.c	18 Apr 2007 16:28:48 -0000
@@ -187,8 +187,10 @@
     return r;
   }
 
-  pending_ms = timeout_ms;
-  initial_tv = curlx_tvnow();
+  if (timeout_ms > 0) {
+    pending_ms = timeout_ms;
+    initial_tv = curlx_tvnow();
+  }
 
 #ifdef HAVE_POLL_FINE
 
@@ -206,13 +208,23 @@
     num++;
   }
 
-  do {
-    if (timeout_ms < 0)
-      pending_ms = -1;
-    r = poll(pfd, num, pending_ms);
-  } while ((r == -1) && (error = SOCKERRNO) &&
-           (error != EINVAL) && error_not_EINTR &&
-           ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
+  if (timeout_ms > 0) {
+    do {
+      r = poll(pfd, num, pending_ms);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && error_not_EINTR &&
+             ((pending_ms = timeout_ms - elapsed_ms) > 0));
+  }
+  else {
+    do {
+      if (timeout_ms < 0)
+        pending_ms = -1;
+      else
+        pending_ms = 0;
+      r = poll(pfd, num, pending_ms);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && error_not_EINTR);
+  }
 
   if (r < 0)
     return -1;
@@ -261,15 +273,25 @@
 
   ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
 
-  do {
-    if (ptimeout) {
+  if (timeout_ms > 0) {
+    do {
       pending_tv.tv_sec = pending_ms / 1000;
       pending_tv.tv_usec = (pending_ms % 1000) * 1000;
-    }
-    r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
-  } while ((r == -1) && (error = SOCKERRNO) &&
-           (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
-           ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
+      r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
+             ((pending_ms = timeout_ms - elapsed_ms) > 0));
+  }
+  else {
+    do {
+      if (!timeout_ms) {
+        pending_tv.tv_sec = 0;
+        pending_tv.tv_usec = 0;
+      }
+      r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && (error != EBADF) && error_not_EINTR);
+  }
 
   if (r < 0)
     return -1;
@@ -342,18 +364,30 @@
     return r;
   }
 
-  pending_ms = timeout_ms;
-  initial_tv = curlx_tvnow();
+  if (timeout_ms > 0) {
+    pending_ms = timeout_ms;
+    initial_tv = curlx_tvnow();
+  }
 
 #ifdef HAVE_POLL_FINE
 
-  do {
-    if (timeout_ms < 0)
-      pending_ms = -1;
-    r = poll(ufds, nfds, pending_ms);
-  } while ((r == -1) && (error = SOCKERRNO) &&
-           (error != EINVAL) && error_not_EINTR &&
-           ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
+  if (timeout_ms > 0) {
+    do {
+      r = poll(ufds, nfds, pending_ms);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && error_not_EINTR &&
+             ((pending_ms = timeout_ms - elapsed_ms) > 0));
+  }
+  else {
+    do {
+      if (timeout_ms < 0)
+        pending_ms = -1;
+      else
+        pending_ms = 0;
+      r = poll(ufds, nfds, pending_ms);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && error_not_EINTR);
+  }
 
 #else  /* HAVE_POLL_FINE */
 
@@ -382,15 +416,25 @@
 
   ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
 
-  do {
-    if (ptimeout) {
+  if (timeout_ms > 0) {
+    do {
       pending_tv.tv_sec = pending_ms / 1000;
       pending_tv.tv_usec = (pending_ms % 1000) * 1000;
-    }
-    r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
-  } while ((r == -1) && (error = SOCKERRNO) &&
-           (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
-           ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
+      r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
+             ((pending_ms = timeout_ms - elapsed_ms) > 0));
+  }
+  else {
+    do {
+      if (!timeout_ms) {
+        pending_tv.tv_sec = 0;
+        pending_tv.tv_usec = 0;
+      }
+      r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && (error != EBADF) && error_not_EINTR);
+  }
 
   if (r < 0)
     return -1;
@@ -479,8 +523,10 @@
     return r;
   }
 
-  pending_ms = timeout_ms;
-  initial_tv = curlx_tvnow();
+  if (timeout_ms > 0) {
+    pending_ms = timeout_ms;
+    initial_tv = curlx_tvnow();
+  }
 
 #ifdef HAVE_POLL_FINE
 
@@ -525,13 +571,23 @@
     }
   }
 
-  do {
-    if (timeout_ms < 0)
-      pending_ms = -1;
-    r = poll(poll_fds, poll_nfds, pending_ms);
-  } while ((r == -1) && (error = SOCKERRNO) &&
-           (error != EINVAL) && error_not_EINTR &&
-           ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
+  if (timeout_ms > 0) {
+    do {
+      r = poll(poll_fds, poll_nfds, pending_ms);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && error_not_EINTR &&
+             ((pending_ms = timeout_ms - elapsed_ms) > 0));
+  }
+  else {
+    do {
+      if (timeout_ms < 0)
+        pending_ms = -1;
+      else
+        pending_ms = 0;
+      r = poll(poll_fds, poll_nfds, pending_ms);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && error_not_EINTR);
+  }
 
   if (r < 0)
     ret = -1;
@@ -580,15 +636,25 @@
 
   ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
 
-  do {
-    if (ptimeout) {
+  if (timeout_ms > 0) {
+    do {
       pending_tv.tv_sec = pending_ms / 1000;
       pending_tv.tv_usec = (pending_ms % 1000) * 1000;
-    }
-    r = select(nfds, fds_read, fds_write, fds_excep, ptimeout);
-  } while ((r == -1) && (error = SOCKERRNO) &&
-           (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
-           ((timeout_ms < 0) || ((pending_ms = timeout_ms - elapsed_ms) > 0)));
+      r = select(nfds, fds_read, fds_write, fds_excep, ptimeout);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && (error != EBADF) && error_not_EINTR &&
+             ((pending_ms = timeout_ms - elapsed_ms) > 0));
+  }
+  else {
+    do {
+      if (!timeout_ms) {
+        pending_tv.tv_sec = 0;
+        pending_tv.tv_usec = 0;
+      }
+      r = select(nfds, fds_read, fds_write, fds_excep, ptimeout);
+    } while ((r == -1) && (error = SOCKERRNO) &&
+             (error != EINVAL) && (error != EBADF) && error_not_EINTR);
+  }
 
   if (r < 0)
     ret = -1;
