aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-06-27 21:35:17 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-06-27 21:35:17 +0000
commit9ca688c8e71c9b3313ceeaf1f4037341befd3c0c (patch)
treed3633960506f30c6b3cb939564a6e016af5f1d2e
parent8edbe262d90ff0bb860becea58a39b7e6eaa2ebc (diff)
James Bursa's improvement
-rw-r--r--docs/examples/10-at-a-time.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c
index 41c2f4883..29c7f08d9 100644
--- a/docs/examples/10-at-a-time.c
+++ b/docs/examples/10-at-a-time.c
@@ -13,7 +13,10 @@
* Written by Michael Wallner
*/
+#include <errno.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <curl/multi.h>
static const char *urls[] = {
@@ -106,6 +109,10 @@ int main(void)
cm = curl_multi_init();
+ /* we can optionally limit the total amount of connections this multi handle
+ uses */
+ curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, MAX);
+
for (C = 0; C < MAX; ++C) {
init(cm, C);
}
@@ -123,20 +130,24 @@ int main(void)
return EXIT_FAILURE;
}
- /* In a real-world program you OF COURSE check the return that maxfd is
- bigger than -1 so that the call to select() below makes sense! */
-
if (curl_multi_timeout(cm, &L)) {
fprintf(stderr, "E: curl_multi_timeout\n");
return EXIT_FAILURE;
}
-
- T.tv_sec = L/1000;
- T.tv_usec = (L%1000)*1000;
-
- if (0 > select(M+1, &R, &W, &E, &T)) {
- fprintf(stderr, "E: select\n");
- return EXIT_FAILURE;
+ if (L == -1)
+ L = 100;
+
+ if (M == -1) {
+ sleep(L / 1000);
+ } else {
+ T.tv_sec = L/1000;
+ T.tv_usec = (L%1000)*1000;
+
+ if (0 > select(M+1, &R, &W, &E, &T)) {
+ fprintf(stderr, "E: select(%i,,,,%li): %i: %s\n",
+ M+1, L, errno, strerror(errno));
+ return EXIT_FAILURE;
+ }
}
}