summaryrefslogtreecommitdiffstats
path: root/0006-curl-7.21.7-3445fa2.patch
blob: fe9cf744d79b47714fc3245e5d852dc7a8ad1dd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
From 3445fa2e3f28b359a3acd2a884f4e119b11e0a57 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Fri, 26 Aug 2011 11:10:58 +0200
Subject: [PATCH] tests: break busy loops in tests 502, 555, and 573

---
 tests/libtest/lib502.c |   23 +++++++++++++++++++++--
 tests/libtest/lib555.c |   23 +++++++++++++++++++++--
 tests/libtest/lib573.c |   23 +++++++++++++++++++++--
 3 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/tests/libtest/lib502.c b/tests/libtest/lib502.c
index 9ade12a..9040b2b 100644
--- a/tests/libtest/lib502.c
+++ b/tests/libtest/lib502.c
@@ -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;
   }
diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c
index c675015..1e73a5a 100644
--- a/tests/libtest/lib555.c
+++ b/tests/libtest/lib555.c
@@ -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;
   }
diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c
index 4661858..b5fafe1 100644
--- a/tests/libtest/lib573.c
+++ b/tests/libtest/lib573.c
@@ -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;
   }
-- 
1.7.4.4