aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2014-11-17 02:26:03 -0500
committerDaniel Stenberg <daniel@haxx.se>2014-11-19 13:34:05 +0100
commitcb13fad733e38cb8fbc1919e70d11d3c8b88ec52 (patch)
tree32f84311d803ac97404afb3bb3779abd329f2102 /docs
parent9406ab91a2deffc09ad7951c7addc4153eb16df4 (diff)
examples: Wait recommended 100ms when no file descriptors are ready
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
Diffstat (limited to 'docs')
-rw-r--r--docs/examples/fopen.c20
-rw-r--r--docs/examples/imap-multi.c20
-rw-r--r--docs/examples/multi-app.c20
-rw-r--r--docs/examples/multi-debugcallback.c20
-rw-r--r--docs/examples/multi-double.c20
-rw-r--r--docs/examples/multi-post.c20
-rw-r--r--docs/examples/multi-single.c20
-rw-r--r--docs/examples/pop3-multi.c20
-rw-r--r--docs/examples/smtp-multi.c20
9 files changed, 108 insertions, 72 deletions
diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c
index c26c0de04..3d2a81773 100644
--- a/docs/examples/fopen.c
+++ b/docs/examples/fopen.c
@@ -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);
}
diff --git a/docs/examples/imap-multi.c b/docs/examples/imap-multi.c
index c8c67ff87..c7dc13071 100644
--- a/docs/examples/imap-multi.c
+++ b/docs/examples/imap-multi.c
@@ -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);
}
diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c
index bf0f11ad5..b8258975e 100644
--- a/docs/examples/multi-app.c
+++ b/docs/examples/multi-app.c
@@ -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);
}
diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c
index 31dec5472..5fb86bea1 100644
--- a/docs/examples/multi-debugcallback.c
+++ b/docs/examples/multi-debugcallback.c
@@ -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);
}
diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c
index df0922a1c..0d8d0de4f 100644
--- a/docs/examples/multi-double.c
+++ b/docs/examples/multi-double.c
@@ -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);
}
diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c
index a6cc8683c..f511d66fd 100644
--- a/docs/examples/multi-post.c
+++ b/docs/examples/multi-post.c
@@ -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);
}
diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c
index 3d80c655f..1c62f1b26 100644
--- a/docs/examples/multi-single.c
+++ b/docs/examples/multi-single.c
@@ -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);
}
diff --git a/docs/examples/pop3-multi.c b/docs/examples/pop3-multi.c
index 42142f954..435308623 100644
--- a/docs/examples/pop3-multi.c
+++ b/docs/examples/pop3-multi.c
@@ -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);
}
diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c
index 998f69e3f..4098c7d18 100644
--- a/docs/examples/smtp-multi.c
+++ b/docs/examples/smtp-multi.c
@@ -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);
}