]> granicus.if.org Git - curl/commitdiff
tests: break busy loops in tests 502, 555, and 573
authorKamil Dudka <kdudka@redhat.com>
Fri, 26 Aug 2011 09:10:58 +0000 (11:10 +0200)
committerKamil Dudka <kdudka@redhat.com>
Mon, 29 Aug 2011 13:14:39 +0000 (15:14 +0200)
tests/libtest/lib502.c
tests/libtest/lib555.c
tests/libtest/lib573.c

index 9ade12afb4d6eaed85b845e76c21f7b68d4a80d7..9040b2be32c2be690402d56711aaaa91775046e4 100644 (file)
@@ -73,6 +73,10 @@ int test(char *URL)
   mp_start = tutil_tvnow();
 
   while (running) {
+    static struct timeval timeout = /* 100 ms */ { 0, 100000L };
+    fd_set fdread, fdwrite, fdexcep;
+    int maxfd = -1;
+
     res = (int)curl_multi_perform(m, &running);
     if (tutil_tvdiff(tutil_tvnow(), mp_start) >
         MULTI_PERFORM_HANG_TIMEOUT) {
@@ -83,11 +87,26 @@ int test(char *URL)
       fprintf(stderr, "nothing left running.\n");
       break;
     }
+
+    FD_ZERO(&fdread);
+    FD_ZERO(&fdwrite);
+    FD_ZERO(&fdexcep);
+    curl_multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+    /* In a real-world program you OF COURSE check the return code of the
+       function calls.  On success, the value of maxfd is guaranteed to be
+       greater or equal than -1.  We call select(maxfd + 1, ...), specially in
+       case of (maxfd == -1), we call select(0, ...), which is basically equal
+       to sleep. */
+
+    if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) {
+      res = ~CURLM_OK;
+      break;
+    }
   }
 
   if (mp_timedout) {
-    if (mp_timedout) fprintf(stderr, "mp_timedout\n");
-    fprintf(stderr, "ABORTING TEST, since it seems "
+    fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems "
             "that it would have run forever.\n");
     res = TEST_ERR_RUNS_FOREVER;
   }
index c6750152129682167080ce0dd55785128c059831..1e73a5a2ec407492384edca27e2d9fee05adbff9 100644 (file)
@@ -135,6 +135,10 @@ int test(char *URL)
   mp_start = tutil_tvnow();
 
   while (running) {
+    static struct timeval timeout = /* 100 ms */ { 0, 100000L };
+    fd_set fdread, fdwrite, fdexcep;
+    int maxfd = -1;
+
     res = (int)curl_multi_perform(m, &running);
     if (tutil_tvdiff(tutil_tvnow(), mp_start) >
         MULTI_PERFORM_HANG_TIMEOUT) {
@@ -148,11 +152,26 @@ int test(char *URL)
       fprintf(stderr, "nothing left running.\n");
       break;
     }
+
+    FD_ZERO(&fdread);
+    FD_ZERO(&fdwrite);
+    FD_ZERO(&fdexcep);
+    curl_multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+    /* In a real-world program you OF COURSE check the return code of the
+       function calls.  On success, the value of maxfd is guaranteed to be
+       greater or equal than -1.  We call select(maxfd + 1, ...), specially in
+       case of (maxfd == -1), we call select(0, ...), which is basically equal
+       to sleep. */
+
+    if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) {
+      res = ~CURLM_OK;
+      break;
+    }
   }
 
   if (mp_timedout) {
-    if (mp_timedout) fprintf(stderr, "mp_timedout\n");
-    fprintf(stderr, "ABORTING TEST, since it seems "
+    fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems "
             "that it would have run forever.\n");
     res = TEST_ERR_RUNS_FOREVER;
   }
index 46618584450a3e580c4c3dd4d8a61bb0c392e0a4..b5fafe16e4c380aaa67475fee3bef479f7144cdb 100644 (file)
@@ -76,6 +76,10 @@ int test(char *URL)
   mp_start = tutil_tvnow();
 
   while (running) {
+    static struct timeval timeout = /* 100 ms */ { 0, 100000L };
+    fd_set fdread, fdwrite, fdexcep;
+    int maxfd = -1;
+
     res = (int)curl_multi_perform(m, &running);
     if (tutil_tvdiff(tutil_tvnow(), mp_start) >
         MULTI_PERFORM_HANG_TIMEOUT) {
@@ -86,11 +90,26 @@ int test(char *URL)
       fprintf(stderr, "nothing left running.\n");
       break;
     }
+
+    FD_ZERO(&fdread);
+    FD_ZERO(&fdwrite);
+    FD_ZERO(&fdexcep);
+    curl_multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+    /* In a real-world program you OF COURSE check the return code of the
+       function calls.  On success, the value of maxfd is guaranteed to be
+       greater or equal than -1.  We call select(maxfd + 1, ...), specially in
+       case of (maxfd == -1), we call select(0, ...), which is basically equal
+       to sleep. */
+
+    if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) {
+      res = ~CURLM_OK;
+      break;
+    }
   }
 
   if (mp_timedout) {
-    if (mp_timedout) fprintf(stderr, "mp_timedout\n");
-    fprintf(stderr, "ABORTING TEST, since it seems "
+    fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems "
             "that it would have run forever.\n");
     res = TEST_ERR_RUNS_FOREVER;
   }