]> granicus.if.org Git - curl/commitdiff
examples: Wait recommended 100ms when no file descriptors are ready
authorJay Satiro <raysatiro@yahoo.com>
Mon, 17 Nov 2014 07:26:03 +0000 (02:26 -0500)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 19 Nov 2014 12:34:05 +0000 (13:34 +0100)
Prior to this change when no file descriptors were ready on platforms
other than Windows the multi examples would sleep whatever was in
timeout, which may or may not have been less than the minimum
recommended value [1] of 100ms.

[1]: http://curl.haxx.se/libcurl/c/curl_multi_fdset.html

docs/examples/fopen.c
docs/examples/imap-multi.c
docs/examples/multi-app.c
docs/examples/multi-debugcallback.c
docs/examples/multi-double.c
docs/examples/multi-post.c
docs/examples/multi-single.c
docs/examples/pop3-multi.c
docs/examples/smtp-multi.c

index c26c0de04ca2d460ec1271ce54ed3a1f08aa56db..3d2a81773348727eb92f5bdd8bcaa97483c59f3e 100644 (file)
@@ -168,20 +168,24 @@ static int fill_buffer(URL_FILE *file, size_t want)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index c8c67ff87bac455f204e7793399654256adb9e0f..c7dc13071338f99e7546763f3ffc90c573ef9197 100644 (file)
@@ -120,20 +120,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index bf0f11ad5bbd02c0410f99fa4dd6b63a3033e7b0..b8258975e708af4a6a5dcbbed4bbc03da995be20 100644 (file)
@@ -109,20 +109,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index 31dec5472a2d91f1efc27b1b19955c6059547c85..5fb86bea131ab089caf850a2b416635a146b7971 100644 (file)
@@ -183,20 +183,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index df0922a1c9fb299150e77f881d1027f094937aa4..0d8d0de4fad0da47e60c73a6b9a791716745fbb2 100644 (file)
@@ -98,20 +98,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index a6cc8683cd2297ffbfd190244c86bcc2a10d5bd0..f511d66fd0c064be805ffdb85b58a52942fe0575 100644 (file)
@@ -119,20 +119,24 @@ int main(void)
       }
 
       /* On success the value of maxfd is guaranteed to be >= -1. We call
-         select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-         select(0, ...), which is basically equal to sleeping the timeout. On
-         Windows we can't sleep via select without a dummy socket and instead
-         we Sleep() for 100ms which is the minimum suggested value in the
+         select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+         no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+         to sleep 100ms, which is the minimum suggested value in the
          curl_multi_fdset() doc. */
 
-#ifdef _WIN32
       if(maxfd == -1) {
+#ifdef _WIN32
         Sleep(100);
         rc = 0;
-      }
-      else
+#else
+        /* Portable sleep for platforms other than Windows. */
+        struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+        rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-      {
+      }
+      else {
+        /* Note that on some platforms 'timeout' may be modified by select().
+           If you need access to the original value save a copy beforehand. */
         rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
       }
 
index 3d80c655fc788b3ba7a720985b7dbe9cdad8d450..1c62f1b26bdd2d7e2f82737c9009dafff78b9fce 100644 (file)
@@ -96,20 +96,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index 42142f95410c999968dcafd478b29b48be32b75a..435308623adb6c4e26b94927040a9454b522a944 100644 (file)
@@ -120,20 +120,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }
 
index 998f69e3f51ad83c429725ad03025864eb2bc4b4..4098c7d189a44d8172cde55c557eb2080cc8fc2f 100644 (file)
@@ -187,20 +187,24 @@ int main(void)
     }
 
     /* On success the value of maxfd is guaranteed to be >= -1. We call
-       select(maxfd + 1, ...); specially in case of (maxfd == -1) we call
-       select(0, ...), which is basically equal to sleeping the timeout. On
-       Windows we can't sleep via select without a dummy socket and instead
-       we Sleep() for 100ms which is the minimum suggested value in the
+       select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
+       no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
+       to sleep 100ms, which is the minimum suggested value in the
        curl_multi_fdset() doc. */
 
-#ifdef _WIN32
     if(maxfd == -1) {
+#ifdef _WIN32
       Sleep(100);
       rc = 0;
-    }
-    else
+#else
+      /* Portable sleep for platforms other than Windows. */
+      struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
+      rc = select(0, NULL, NULL, NULL, &wait);
 #endif
-    {
+    }
+    else {
+      /* Note that on some platforms 'timeout' may be modified by select().
+         If you need access to the original value save a copy beforehand. */
       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
     }