aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2008-04-13 04:32:13 +0000
committerChristian Grothoff <christian@grothoff.org>2008-04-13 04:32:13 +0000
commit2055011f0498854c599f822cce063b2864bfdfb6 (patch)
tree4a85091d9036714accc3396e08740a0dba539901
parentffcd629d03138365e8c5813731341d1154b07b7f (diff)
downloadlibmicrohttpd-2055011f0498854c599f822cce063b2864bfdfb6.tar.gz
libmicrohttpd-2055011f0498854c599f822cce063b2864bfdfb6.zip
zzufing all tests
-rw-r--r--src/testzzuf/Makefile.am14
-rw-r--r--src/testzzuf/daemontest_get.c1
-rw-r--r--src/testzzuf/daemontest_get_chunked.c1
-rw-r--r--src/testzzuf/daemontest_large_put.c24
-rw-r--r--src/testzzuf/daemontest_long_header.c152
-rw-r--r--src/testzzuf/daemontest_post.c288
-rw-r--r--src/testzzuf/daemontest_post_loop.c386
-rw-r--r--src/testzzuf/daemontest_postform.c292
-rw-r--r--src/testzzuf/daemontest_put.c294
-rw-r--r--src/testzzuf/daemontest_put_chunked.c222
-rw-r--r--src/testzzuf/socat.c3
11 files changed, 631 insertions, 1046 deletions
diff --git a/src/testzzuf/Makefile.am b/src/testzzuf/Makefile.am
index 9e9d27a3..92e5a768 100644
--- a/src/testzzuf/Makefile.am
+++ b/src/testzzuf/Makefile.am
@@ -8,13 +8,11 @@ check_PROGRAMS = \
8 daemontest_get \ 8 daemontest_get \
9 daemontest_post \ 9 daemontest_post \
10 daemontest_postform \ 10 daemontest_postform \
11 daemontest_post_loop \
12 daemontest_put \ 11 daemontest_put \
13 daemontest_large_put \ 12 daemontest_large_put \
14 daemontest_get11 \ 13 daemontest_get11 \
15 daemontest_post11 \ 14 daemontest_post11 \
16 daemontest_postform11 \ 15 daemontest_postform11 \
17 daemontest_post_loop11 \
18 daemontest_put11 \ 16 daemontest_put11 \
19 daemontest_large_put11 \ 17 daemontest_large_put11 \
20 daemontest_long_header \ 18 daemontest_long_header \
@@ -47,12 +45,6 @@ daemontest_postform_LDADD = \
47 $(top_builddir)/src/daemon/libmicrohttpd.la \ 45 $(top_builddir)/src/daemon/libmicrohttpd.la \
48 @LIBCURL@ 46 @LIBCURL@
49 47
50daemontest_post_loop_SOURCES = \
51 daemontest_post_loop.c
52daemontest_post_loop_LDADD = \
53 $(top_builddir)/src/daemon/libmicrohttpd.la \
54 @LIBCURL@
55
56daemontest_put_SOURCES = \ 48daemontest_put_SOURCES = \
57 daemontest_put.c 49 daemontest_put.c
58daemontest_put_LDADD = \ 50daemontest_put_LDADD = \
@@ -83,12 +75,6 @@ daemontest_postform11_LDADD = \
83 $(top_builddir)/src/daemon/libmicrohttpd.la \ 75 $(top_builddir)/src/daemon/libmicrohttpd.la \
84 @LIBCURL@ 76 @LIBCURL@
85 77
86daemontest_post_loop11_SOURCES = \
87 daemontest_post_loop.c
88daemontest_post_loop11_LDADD = \
89 $(top_builddir)/src/daemon/libmicrohttpd.la \
90 @LIBCURL@
91
92daemontest_put11_SOURCES = \ 78daemontest_put11_SOURCES = \
93 daemontest_put.c 79 daemontest_put.c
94daemontest_put11_LDADD = \ 80daemontest_put11_LDADD = \
diff --git a/src/testzzuf/daemontest_get.c b/src/testzzuf/daemontest_get.c
index ac43f75e..5e4b2d28 100644
--- a/src/testzzuf/daemontest_get.c
+++ b/src/testzzuf/daemontest_get.c
@@ -218,7 +218,6 @@ testExternalGet ()
218 multi = curl_multi_init (); 218 multi = curl_multi_init ();
219 if (multi == NULL) 219 if (multi == NULL)
220 { 220 {
221 curl_easy_cleanup (c);
222 MHD_stop_daemon (d); 221 MHD_stop_daemon (d);
223 return 512; 222 return 512;
224 } 223 }
diff --git a/src/testzzuf/daemontest_get_chunked.c b/src/testzzuf/daemontest_get_chunked.c
index ca94beb0..cde1e46b 100644
--- a/src/testzzuf/daemontest_get_chunked.c
+++ b/src/testzzuf/daemontest_get_chunked.c
@@ -239,7 +239,6 @@ testExternalGet ()
239 multi = curl_multi_init (); 239 multi = curl_multi_init ();
240 if (multi == NULL) 240 if (multi == NULL)
241 { 241 {
242 curl_easy_cleanup (c);
243 MHD_stop_daemon (d); 242 MHD_stop_daemon (d);
244 return 512; 243 return 512;
245 } 244 }
diff --git a/src/testzzuf/daemontest_large_put.c b/src/testzzuf/daemontest_large_put.c
index ecba637b..2a80bdb4 100644
--- a/src/testzzuf/daemontest_large_put.c
+++ b/src/testzzuf/daemontest_large_put.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file daemontest_put.c 22 * @file daemontest_large_put.c
23 * @brief Testcase for libmicrohttpd PUT operations 23 * @brief Testcase for libmicrohttpd PUT operations
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
@@ -54,7 +54,7 @@ static int oneone;
54 * MHD default buffer limit and the test code is not 54 * MHD default buffer limit and the test code is not
55 * written for incremental upload processing... 55 * written for incremental upload processing...
56 */ 56 */
57#define PUT_SIZE (512 * 1024) 57#define PUT_SIZE (256 * 1024)
58 58
59static char *put_buffer; 59static char *put_buffer;
60 60
@@ -123,7 +123,6 @@ ahc_echo (void *cls,
123 } 123 }
124 else 124 else
125 { 125 {
126 printf ("Invalid upload data!\n");
127 return MHD_NO; 126 return MHD_NO;
128 } 127 }
129 *done = 1; 128 *done = 1;
@@ -151,8 +150,8 @@ testInternalPut ()
151 cbc.buf = buf; 150 cbc.buf = buf;
152 cbc.size = 2048; 151 cbc.size = 2048;
153 cbc.pos = 0; 152 cbc.pos = 0;
154 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 153 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
155 1080, 154 11080,
156 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 155 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
157 if (d == NULL) 156 if (d == NULL)
158 return 1; 157 return 1;
@@ -162,7 +161,7 @@ testInternalPut ()
162 fprintf (stderr, "."); 161 fprintf (stderr, ".");
163 162
164 c = curl_easy_init (); 163 c = curl_easy_init ();
165 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); 164 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
166 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 165 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
167 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 166 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
168 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 167 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -184,6 +183,7 @@ testInternalPut ()
184 curl_easy_cleanup (c); 183 curl_easy_cleanup (c);
185 } 184 }
186 fprintf (stderr, "\n"); 185 fprintf (stderr, "\n");
186 zzuf_socat_stop ();
187 MHD_stop_daemon (d); 187 MHD_stop_daemon (d);
188 return 0; 188 return 0;
189} 189}
@@ -202,14 +202,11 @@ testMultithreadedPut ()
202 cbc.buf = buf; 202 cbc.buf = buf;
203 cbc.size = 2048; 203 cbc.size = 2048;
204 cbc.pos = 0; 204 cbc.pos = 0;
205 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 205 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
206 11080, 206 11080,
207 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 207 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
208 if (d == NULL) 208 if (d == NULL)
209 { 209 return 16;
210 free (cbc.buf);
211 return 16;
212 }
213 zzuf_socat_start (); 210 zzuf_socat_start ();
214 for (i = 0; i < LOOP_COUNT; i++) 211 for (i = 0; i < LOOP_COUNT; i++)
215 { 212 {
@@ -268,7 +265,7 @@ testExternalPut ()
268 cbc.size = 2048; 265 cbc.size = 2048;
269 cbc.pos = 0; 266 cbc.pos = 0;
270 multi = NULL; 267 multi = NULL;
271 d = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG, 268 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
272 11080, 269 11080,
273 NULL, NULL, &ahc_echo, &done_flag, 270 NULL, NULL, &ahc_echo, &done_flag,
274 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 271 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
@@ -278,7 +275,6 @@ testExternalPut ()
278 multi = curl_multi_init (); 275 multi = curl_multi_init ();
279 if (multi == NULL) 276 if (multi == NULL)
280 { 277 {
281 curl_easy_cleanup (c);
282 MHD_stop_daemon (d); 278 MHD_stop_daemon (d);
283 return 512; 279 return 512;
284 } 280 }
@@ -319,7 +315,7 @@ testExternalPut ()
319 return 1024; 315 return 1024;
320 } 316 }
321 start = time (NULL); 317 start = time (NULL);
322 while ((time (NULL) - start < 5) && (multi != NULL)) 318 while ((time (NULL) - start < 5) && (c != NULL))
323 { 319 {
324 max = 0; 320 max = 0;
325 FD_ZERO (&rs); 321 FD_ZERO (&rs);
diff --git a/src/testzzuf/daemontest_long_header.c b/src/testzzuf/daemontest_long_header.c
index 385b9776..42bd1114 100644
--- a/src/testzzuf/daemontest_long_header.c
+++ b/src/testzzuf/daemontest_long_header.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007, 2008 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -35,6 +35,18 @@
35#include <unistd.h> 35#include <unistd.h>
36#endif 36#endif
37 37
38#include "socat.c"
39
40/**
41 * A larger loop count will run more random tests --
42 * which would be good, except that it may take too
43 * long for most user's patience. So this small
44 * value is the default.
45 */
46#define LOOP_COUNT 10
47
48#define CURL_TIMEOUT 50L
49
38/** 50/**
39 * We will set the memory available per connection to 51 * We will set the memory available per connection to
40 * half of this value, so the actual value does not have 52 * half of this value, so the actual value does not have
@@ -94,13 +106,13 @@ testLongUrlGet ()
94 char buf[2048]; 106 char buf[2048];
95 struct CBC cbc; 107 struct CBC cbc;
96 char *url; 108 char *url;
97 long code; 109 int i;
98 110
99 cbc.buf = buf; 111 cbc.buf = buf;
100 cbc.size = 2048; 112 cbc.size = 2048;
101 cbc.pos = 0; 113 cbc.pos = 0;
102 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , 114 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
103 1080, 115 11080,
104 &apc_all, 116 &apc_all,
105 NULL, 117 NULL,
106 &ahc_echo, 118 &ahc_echo,
@@ -109,44 +121,39 @@ testLongUrlGet ()
109 VERY_LONG / 2, MHD_OPTION_END); 121 VERY_LONG / 2, MHD_OPTION_END);
110 if (d == NULL) 122 if (d == NULL)
111 return 1; 123 return 1;
112 c = curl_easy_init (); 124 zzuf_socat_start ();
113 url = malloc (VERY_LONG); 125 for (i = 0; i < LOOP_COUNT; i++)
114 memset (url, 'a', VERY_LONG);
115 url[VERY_LONG - 1] = '\0';
116 memcpy (url, "http://localhost:1080/", strlen ("http://localhost:1080/"));
117 curl_easy_setopt (c, CURLOPT_URL, url);
118 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
119 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
120 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
121 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
122 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
123 if (oneone)
124 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
125 else
126 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
127 // NOTE: use of CONNECTTIMEOUT without also
128 // setting NOSIGNAL results in really weird
129 // crashes on my system!
130 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
131 if (CURLE_OK == curl_easy_perform (c))
132 { 126 {
127 fprintf (stderr, ".");
128
129 c = curl_easy_init ();
130 url = malloc (VERY_LONG);
131 memset (url, 'a', VERY_LONG);
132 url[VERY_LONG - 1] = '\0';
133 memcpy (url, "http://localhost:11081/",
134 strlen ("http://localhost:11081/"));
135 curl_easy_setopt (c, CURLOPT_URL, url);
136 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
137 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
138 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
139 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
140 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
141 if (oneone)
142 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
143 else
144 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
145 // NOTE: use of CONNECTTIMEOUT without also
146 // setting NOSIGNAL results in really weird
147 // crashes on my system!
148 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
149 curl_easy_perform (c);
133 curl_easy_cleanup (c); 150 curl_easy_cleanup (c);
134 MHD_stop_daemon (d);
135 free (url);
136 return 2;
137 } 151 }
138 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) 152 fprintf (stderr, "\n");
139 { 153 zzuf_socat_stop ();
140 curl_easy_cleanup (c); 154
141 MHD_stop_daemon (d);
142 free (url);
143 return 4;
144 }
145 curl_easy_cleanup (c);
146 MHD_stop_daemon (d); 155 MHD_stop_daemon (d);
147 free (url); 156 free (url);
148 if (code != MHD_HTTP_REQUEST_URI_TOO_LONG)
149 return 8;
150 return 0; 157 return 0;
151} 158}
152 159
@@ -159,8 +166,8 @@ testLongHeaderGet ()
159 char buf[2048]; 166 char buf[2048];
160 struct CBC cbc; 167 struct CBC cbc;
161 char *url; 168 char *url;
162 long code;
163 struct curl_slist *header = NULL; 169 struct curl_slist *header = NULL;
170 int i;
164 171
165 cbc.buf = buf; 172 cbc.buf = buf;
166 cbc.size = 2048; 173 cbc.size = 2048;
@@ -175,51 +182,44 @@ testLongHeaderGet ()
175 VERY_LONG / 2, MHD_OPTION_END); 182 VERY_LONG / 2, MHD_OPTION_END);
176 if (d == NULL) 183 if (d == NULL)
177 return 16; 184 return 16;
178 c = curl_easy_init (); 185 zzuf_socat_start ();
179 url = malloc (VERY_LONG); 186 for (i = 0; i < LOOP_COUNT; i++)
180 memset (url, 'a', VERY_LONG);
181 url[VERY_LONG - 1] = '\0';
182 url[VERY_LONG / 2] = ':';
183 url[VERY_LONG / 2 + 1] = ':';
184 header = curl_slist_append (header, url);
185
186 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
187 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world");
188 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
189 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
190 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
191 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
192 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
193 if (oneone)
194 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
195 else
196 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
197 // NOTE: use of CONNECTTIMEOUT without also
198 // setting NOSIGNAL results in really weird
199 // crashes on my system!
200 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
201 if (CURLE_OK == curl_easy_perform (c))
202 {
203 curl_easy_cleanup (c);
204 MHD_stop_daemon (d);
205 curl_slist_free_all (header);
206 free (url);
207 return 32;
208 }
209 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
210 { 187 {
188 fprintf (stderr, ".");
189
190
191 c = curl_easy_init ();
192 url = malloc (VERY_LONG);
193 memset (url, 'a', VERY_LONG);
194 url[VERY_LONG - 1] = '\0';
195 url[VERY_LONG / 2] = ':';
196 url[VERY_LONG / 2 + 1] = ':';
197 header = curl_slist_append (header, url);
198
199 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
200 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world");
201 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
202 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
203 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
204 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
206 if (oneone)
207 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
208 else
209 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
210 // NOTE: use of CONNECTTIMEOUT without also
211 // setting NOSIGNAL results in really weird
212 // crashes on my system!
213 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
214 curl_easy_perform (c);
211 curl_slist_free_all (header); 215 curl_slist_free_all (header);
212 curl_easy_cleanup (c); 216 curl_easy_cleanup (c);
213 MHD_stop_daemon (d);
214 free (url);
215 return 64;
216 } 217 }
217 curl_slist_free_all (header); 218 fprintf (stderr, "\n");
218 curl_easy_cleanup (c); 219 zzuf_socat_stop ();
220
219 MHD_stop_daemon (d); 221 MHD_stop_daemon (d);
220 free (url); 222 free (url);
221 if (code != MHD_HTTP_REQUEST_ENTITY_TOO_LARGE)
222 return 128;
223 return 0; 223 return 0;
224} 224}
225 225
diff --git a/src/testzzuf/daemontest_post.c b/src/testzzuf/daemontest_post.c
index 335377e6..690ab218 100644
--- a/src/testzzuf/daemontest_post.c
+++ b/src/testzzuf/daemontest_post.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007, 2008 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -35,6 +35,20 @@
35#include <unistd.h> 35#include <unistd.h>
36#endif 36#endif
37 37
38
39#include "socat.c"
40
41/**
42 * A larger loop count will run more random tests --
43 * which would be good, except that it may take too
44 * long for most user's patience. So this small
45 * value is the default.
46 */
47#define LOOP_COUNT 10
48
49#define CURL_TIMEOUT 50L
50
51
38#define POST_DATA "name=daniel&project=curl" 52#define POST_DATA "name=daniel&project=curl"
39 53
40static int oneone; 54static int oneone;
@@ -99,7 +113,6 @@ ahc_echo (void *cls,
99 113
100 if (0 != strcmp ("POST", method)) 114 if (0 != strcmp ("POST", method))
101 { 115 {
102 printf ("METHOD: %s\n", method);
103 return MHD_NO; /* unexpected method */ 116 return MHD_NO; /* unexpected method */
104 } 117 }
105 pp = *unused; 118 pp = *unused;
@@ -133,48 +146,45 @@ testInternalPost ()
133 CURL *c; 146 CURL *c;
134 char buf[2048]; 147 char buf[2048];
135 struct CBC cbc; 148 struct CBC cbc;
136 CURLcode errornum; 149 int i;
137 150
138 cbc.buf = buf; 151 cbc.buf = buf;
139 cbc.size = 2048; 152 cbc.size = 2048;
140 cbc.pos = 0; 153 cbc.pos = 0;
141 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 154 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
142 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 155 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
143 if (d == NULL) 156 if (d == NULL)
144 return 1; 157 return 1;
145 c = curl_easy_init (); 158 zzuf_socat_start ();
146 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); 159 for (i = 0; i < LOOP_COUNT; i++)
147 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
148 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
149 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
150 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
151 curl_easy_setopt (c, CURLOPT_POST, 1L);
152 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
153 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
154 if (oneone)
155 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
156 else
157 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
158 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
159 // NOTE: use of CONNECTTIMEOUT without also
160 // setting NOSIGNAL results in really weird
161 // crashes on my system!
162 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
163 if (CURLE_OK != (errornum = curl_easy_perform (c)))
164 { 160 {
165 fprintf (stderr, 161 fprintf (stderr, ".");
166 "curl_easy_perform failed: `%s'\n", 162
167 curl_easy_strerror (errornum)); 163 c = curl_easy_init ();
164 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
165 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
166 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
167 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
168 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
169 curl_easy_setopt (c, CURLOPT_POST, 1L);
170 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
171 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
172 if (oneone)
173 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
174 else
175 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
176 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
177 // NOTE: use of CONNECTTIMEOUT without also
178 // setting NOSIGNAL results in really weird
179 // crashes on my system!
180 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
181 curl_easy_perform (c);
168 curl_easy_cleanup (c); 182 curl_easy_cleanup (c);
169 MHD_stop_daemon (d);
170 return 2;
171 } 183 }
172 curl_easy_cleanup (c); 184 fprintf (stderr, "\n");
185 zzuf_socat_stop ();
173 MHD_stop_daemon (d); 186 MHD_stop_daemon (d);
174 if (cbc.pos != strlen ("/hello_world")) 187
175 return 4;
176 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
177 return 8;
178 return 0; 188 return 0;
179} 189}
180 190
@@ -185,48 +195,46 @@ testMultithreadedPost ()
185 CURL *c; 195 CURL *c;
186 char buf[2048]; 196 char buf[2048];
187 struct CBC cbc; 197 struct CBC cbc;
188 CURLcode errornum; 198 int i;
189 199
190 cbc.buf = buf; 200 cbc.buf = buf;
191 cbc.size = 2048; 201 cbc.size = 2048;
192 cbc.pos = 0; 202 cbc.pos = 0;
193 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 203 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
194 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 204 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
195 if (d == NULL) 205 if (d == NULL)
196 return 16; 206 return 16;
197 c = curl_easy_init (); 207
198 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); 208 zzuf_socat_start ();
199 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 209 for (i = 0; i < LOOP_COUNT; i++)
200 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
201 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
202 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
203 curl_easy_setopt (c, CURLOPT_POST, 1L);
204 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
205 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
206 if (oneone)
207 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
208 else
209 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
210 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
211 // NOTE: use of CONNECTTIMEOUT without also
212 // setting NOSIGNAL results in really weird
213 // crashes on my system!
214 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
215 if (CURLE_OK != (errornum = curl_easy_perform (c)))
216 { 210 {
217 fprintf (stderr, 211 fprintf (stderr, ".");
218 "curl_easy_perform failed: `%s'\n", 212
219 curl_easy_strerror (errornum)); 213 c = curl_easy_init ();
214 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
215 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
216 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
217 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
218 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
219 curl_easy_setopt (c, CURLOPT_POST, 1L);
220 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
221 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
222 if (oneone)
223 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
224 else
225 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
226 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
227 // NOTE: use of CONNECTTIMEOUT without also
228 // setting NOSIGNAL results in really weird
229 // crashes on my system!
230 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
231 curl_easy_perform (c);
220 curl_easy_cleanup (c); 232 curl_easy_cleanup (c);
221 MHD_stop_daemon (d);
222 return 32;
223 } 233 }
224 curl_easy_cleanup (c); 234 fprintf (stderr, "\n");
235 zzuf_socat_stop ();
236
225 MHD_stop_daemon (d); 237 MHD_stop_daemon (d);
226 if (cbc.pos != strlen ("/hello_world"))
227 return 64;
228 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
229 return 128;
230 return 0; 238 return 0;
231} 239}
232 240
@@ -245,114 +253,112 @@ testExternalPost ()
245 fd_set es; 253 fd_set es;
246 int max; 254 int max;
247 int running; 255 int running;
248 struct CURLMsg *msg;
249 time_t start; 256 time_t start;
250 struct timeval tv; 257 struct timeval tv;
258 int i;
251 259
252 multi = NULL; 260 multi = NULL;
253 cbc.buf = buf; 261 cbc.buf = buf;
254 cbc.size = 2048; 262 cbc.size = 2048;
255 cbc.pos = 0; 263 cbc.pos = 0;
256 d = MHD_start_daemon (MHD_USE_DEBUG, 264 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
257 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 265 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
258 if (d == NULL) 266 if (d == NULL)
259 return 256; 267 return 256;
260 c = curl_easy_init ();
261 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
262 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
263 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
264 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
265 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
266 curl_easy_setopt (c, CURLOPT_POST, 1L);
267 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
268 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
269 if (oneone)
270 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
271 else
272 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
273 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
274 // NOTE: use of CONNECTTIMEOUT without also
275 // setting NOSIGNAL results in really weird
276 // crashes on my system!
277 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
278
279
280 multi = curl_multi_init (); 268 multi = curl_multi_init ();
281 if (multi == NULL) 269 if (multi == NULL)
282 { 270 {
283 curl_easy_cleanup (c);
284 MHD_stop_daemon (d); 271 MHD_stop_daemon (d);
285 return 512; 272 return 512;
286 } 273 }
287 mret = curl_multi_add_handle (multi, c); 274
288 if (mret != CURLM_OK) 275 zzuf_socat_start ();
289 { 276 for (i = 0; i < LOOP_COUNT; i++)
290 curl_multi_cleanup (multi);
291 curl_easy_cleanup (c);
292 MHD_stop_daemon (d);
293 return 1024;
294 }
295 start = time (NULL);
296 while ((time (NULL) - start < 5) && (multi != NULL))
297 { 277 {
298 max = 0; 278 fprintf (stderr, ".");
299 FD_ZERO (&rs); 279
300 FD_ZERO (&ws); 280
301 FD_ZERO (&es); 281 c = curl_easy_init ();
302 curl_multi_perform (multi, &running); 282 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
303 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 283 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
284 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
285 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
286 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
287 curl_easy_setopt (c, CURLOPT_POST, 1L);
288 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
289 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
290 if (oneone)
291 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
292 else
293 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
294 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
295 // NOTE: use of CONNECTTIMEOUT without also
296 // setting NOSIGNAL results in really weird
297 // crashes on my system!
298 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
299
300
301 mret = curl_multi_add_handle (multi, c);
304 if (mret != CURLM_OK) 302 if (mret != CURLM_OK)
305 { 303 {
306 curl_multi_remove_handle (multi, c);
307 curl_multi_cleanup (multi);
308 curl_easy_cleanup (c);
309 MHD_stop_daemon (d);
310 return 2048;
311 }
312 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
313 {
314 curl_multi_remove_handle (multi, c);
315 curl_multi_cleanup (multi); 304 curl_multi_cleanup (multi);
316 curl_easy_cleanup (c); 305 curl_easy_cleanup (c);
306 zzuf_socat_stop ();
317 MHD_stop_daemon (d); 307 MHD_stop_daemon (d);
318 return 4096; 308 return 1024;
319 } 309 }
320 tv.tv_sec = 0; 310 start = time (NULL);
321 tv.tv_usec = 1000; 311 while ((time (NULL) - start < 5) && (c != NULL))
322 select (max + 1, &rs, &ws, &es, &tv);
323 curl_multi_perform (multi, &running);
324 if (running == 0)
325 { 312 {
326 msg = curl_multi_info_read (multi, &running); 313 max = 0;
327 if (msg == NULL) 314 FD_ZERO (&rs);
328 break; 315 FD_ZERO (&ws);
329 if (msg->msg == CURLMSG_DONE) 316 FD_ZERO (&es);
317 curl_multi_perform (multi, &running);
318 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
319 if (mret != CURLM_OK)
330 { 320 {
331 if (msg->data.result != CURLE_OK)
332 printf ("%s failed at %s:%d: `%s'\n",
333 "curl_multi_perform",
334 __FILE__,
335 __LINE__, curl_easy_strerror (msg->data.result));
336 curl_multi_remove_handle (multi, c); 321 curl_multi_remove_handle (multi, c);
337 curl_multi_cleanup (multi); 322 curl_multi_cleanup (multi);
338 curl_easy_cleanup (c); 323 curl_easy_cleanup (c);
324 zzuf_socat_stop ();
325 MHD_stop_daemon (d);
326 return 2048;
327 }
328 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
329 {
330 curl_multi_remove_handle (multi, c);
331 curl_multi_cleanup (multi);
332 curl_easy_cleanup (c);
333 zzuf_socat_stop ();
334 MHD_stop_daemon (d);
335 return 4096;
336 }
337 tv.tv_sec = 0;
338 tv.tv_usec = 1000;
339 select (max + 1, &rs, &ws, &es, &tv);
340 curl_multi_perform (multi, &running);
341 if (running == 0)
342 {
343 curl_multi_info_read (multi, &running);
344 curl_multi_remove_handle (multi, c);
345 curl_easy_cleanup (c);
339 c = NULL; 346 c = NULL;
340 multi = NULL;
341 } 347 }
348 MHD_run (d);
342 } 349 }
343 MHD_run (d); 350 if (c != NULL)
344 } 351 {
345 if (multi != NULL) 352 curl_multi_remove_handle (multi, c);
346 { 353 curl_easy_cleanup (c);
347 curl_multi_remove_handle (multi, c); 354 }
348 curl_easy_cleanup (c); 355
349 curl_multi_cleanup (multi);
350 } 356 }
357 fprintf (stderr, "\n");
358 curl_multi_cleanup (multi);
359 zzuf_socat_stop ();
360
351 MHD_stop_daemon (d); 361 MHD_stop_daemon (d);
352 if (cbc.pos != strlen ("/hello_world"))
353 return 8192;
354 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
355 return 16384;
356 return 0; 362 return 0;
357} 363}
358 364
diff --git a/src/testzzuf/daemontest_post_loop.c b/src/testzzuf/daemontest_post_loop.c
deleted file mode 100644
index 8630304e..00000000
--- a/src/testzzuf/daemontest_post_loop.c
+++ /dev/null
@@ -1,386 +0,0 @@
1/*
2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff
4
5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file daemontest_post_loop.c
23 * @brief Testcase for libmicrohttpd POST operations using URL-encoding
24 * @author Christian Grothoff (inspired by bug report #1296)
25 */
26
27#include "config.h"
28#include <curl/curl.h>
29#include <microhttpd.h>
30#include <stdlib.h>
31#include <string.h>
32#include <time.h>
33
34#ifndef WINDOWS
35#include <unistd.h>
36#endif
37
38#define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n"
39
40#define LOOPCOUNT 10
41
42static int oneone;
43
44struct CBC
45{
46 char *buf;
47 size_t pos;
48 size_t size;
49};
50
51static size_t
52copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
53{
54 struct CBC *cbc = ctx;
55
56 if (cbc->pos + size * nmemb > cbc->size)
57 return 0; /* overflow */
58 memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
59 cbc->pos += size * nmemb;
60 return size * nmemb;
61}
62
63static int
64ahc_echo (void *cls,
65 struct MHD_Connection *connection,
66 const char *url,
67 const char *method,
68 const char *version,
69 const char *upload_data, unsigned int *upload_data_size,
70 void **mptr)
71{
72 static int marker;
73 struct MHD_Response *response;
74 int ret;
75
76 if (0 != strcmp ("POST", method))
77 {
78 printf ("METHOD: %s\n", method);
79 return MHD_NO; /* unexpected method */
80 }
81 if ((*mptr != NULL) && (0 == *upload_data_size))
82 {
83 if (*mptr != &marker)
84 abort ();
85 response = MHD_create_response_from_data (2, "OK", MHD_NO, MHD_NO);
86 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
87 MHD_destroy_response (response);
88 *mptr = NULL;
89 return ret;
90 }
91 if (strlen (POST_DATA) != *upload_data_size)
92 return MHD_YES;
93 *upload_data_size = 0;
94 *mptr = &marker;
95 return MHD_YES;
96}
97
98
99static int
100testInternalPost ()
101{
102 struct MHD_Daemon *d;
103 CURL *c;
104 char buf[2048];
105 struct CBC cbc;
106 CURLcode errornum;
107 int i;
108 char url[1024];
109
110 cbc.buf = buf;
111 cbc.size = 2048;
112 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
113 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
114 if (d == NULL)
115 return 1;
116 for (i = 0; i < LOOPCOUNT; i++)
117 {
118 if (99 == i % 100)
119 fprintf (stderr, ".");
120 c = curl_easy_init ();
121 cbc.pos = 0;
122 buf[0] = '\0';
123 sprintf (url, "http://localhost:1080/hw%d", i);
124 curl_easy_setopt (c, CURLOPT_URL, url);
125 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
126 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
127 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
128 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
129 curl_easy_setopt (c, CURLOPT_POST, 1L);
130 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
131 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
132 if (oneone)
133 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
134 else
135 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
136 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
137 // NOTE: use of CONNECTTIMEOUT without also
138 // setting NOSIGNAL results in really weird
139 // crashes on my system!
140 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
141 if (CURLE_OK != (errornum = curl_easy_perform (c)))
142 {
143 fprintf (stderr,
144 "curl_easy_perform failed: `%s'\n",
145 curl_easy_strerror (errornum));
146 curl_easy_cleanup (c);
147 MHD_stop_daemon (d);
148 return 2;
149 }
150 curl_easy_cleanup (c);
151 if ((buf[0] != 'O') || (buf[1] != 'K'))
152 {
153 MHD_stop_daemon (d);
154 return 4;
155 }
156 }
157 MHD_stop_daemon (d);
158 if (LOOPCOUNT >= 99)
159 fprintf (stderr, "\n");
160 return 0;
161}
162
163static int
164testMultithreadedPost ()
165{
166 struct MHD_Daemon *d;
167 CURL *c;
168 char buf[2048];
169 struct CBC cbc;
170 CURLcode errornum;
171 int i;
172 char url[1024];
173
174 cbc.buf = buf;
175 cbc.size = 2048;
176 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
177 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
178 if (d == NULL)
179 return 16;
180 for (i = 0; i < LOOPCOUNT; i++)
181 {
182 if (99 == i % 100)
183 fprintf (stderr, ".");
184 c = curl_easy_init ();
185 cbc.pos = 0;
186 buf[0] = '\0';
187 sprintf (url, "http://localhost:1081/hw%d", i);
188 curl_easy_setopt (c, CURLOPT_URL, url);
189 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
190 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
191 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
192 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
193 curl_easy_setopt (c, CURLOPT_POST, 1L);
194 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
195 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
196 if (oneone)
197 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
198 else
199 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
200 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
201 // NOTE: use of CONNECTTIMEOUT without also
202 // setting NOSIGNAL results in really weird
203 // crashes on my system!
204 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
205 if (CURLE_OK != (errornum = curl_easy_perform (c)))
206 {
207 fprintf (stderr,
208 "curl_easy_perform failed: `%s'\n",
209 curl_easy_strerror (errornum));
210 curl_easy_cleanup (c);
211 MHD_stop_daemon (d);
212 return 32;
213 }
214 curl_easy_cleanup (c);
215 if ((buf[0] != 'O') || (buf[1] != 'K'))
216 {
217 MHD_stop_daemon (d);
218 return 64;
219 }
220 }
221 MHD_stop_daemon (d);
222 if (LOOPCOUNT >= 99)
223 fprintf (stderr, "\n");
224 return 0;
225}
226
227
228static int
229testExternalPost ()
230{
231 struct MHD_Daemon *d;
232 CURL *c;
233 char buf[2048];
234 struct CBC cbc;
235 CURLM *multi;
236 CURLMcode mret;
237 fd_set rs;
238 fd_set ws;
239 fd_set es;
240 int max;
241 int running;
242 struct CURLMsg *msg;
243 time_t start;
244 struct timeval tv;
245 int i;
246 unsigned long long timeout;
247 long ctimeout;
248 char url[1024];
249
250 multi = NULL;
251 cbc.buf = buf;
252 cbc.size = 2048;
253 cbc.pos = 0;
254 d = MHD_start_daemon (MHD_USE_DEBUG,
255 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
256 if (d == NULL)
257 return 256;
258 multi = curl_multi_init ();
259 if (multi == NULL)
260 {
261 MHD_stop_daemon (d);
262 return 512;
263 }
264 for (i = 0; i < LOOPCOUNT; i++)
265 {
266 fprintf (stderr, ".");
267 c = curl_easy_init ();
268 cbc.pos = 0;
269 buf[0] = '\0';
270 sprintf (url, "http://localhost:1082/hw%d", i);
271 curl_easy_setopt (c, CURLOPT_URL, url);
272 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
273 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
274 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
275 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
276 curl_easy_setopt (c, CURLOPT_POST, 1L);
277 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
278 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
279 if (oneone)
280 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
281 else
282 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
283 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
284 // NOTE: use of CONNECTTIMEOUT without also
285 // setting NOSIGNAL results in really weird
286 // crashes on my system!
287 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
288 mret = curl_multi_add_handle (multi, c);
289 if (mret != CURLM_OK)
290 {
291 curl_multi_cleanup (multi);
292 curl_easy_cleanup (c);
293 MHD_stop_daemon (d);
294 return 1024;
295 }
296 start = time (NULL);
297 while ((time (NULL) - start < 5) && (multi != NULL))
298 {
299 max = 0;
300 FD_ZERO (&rs);
301 FD_ZERO (&ws);
302 FD_ZERO (&es);
303 while (CURLM_CALL_MULTI_PERFORM ==
304 curl_multi_perform (multi, &running));
305 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
306 if (mret != CURLM_OK)
307 {
308 curl_multi_remove_handle (multi, c);
309 curl_multi_cleanup (multi);
310 curl_easy_cleanup (c);
311 MHD_stop_daemon (d);
312 return 2048;
313 }
314 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
315 {
316 curl_multi_remove_handle (multi, c);
317 curl_multi_cleanup (multi);
318 curl_easy_cleanup (c);
319 MHD_stop_daemon (d);
320 return 4096;
321 }
322 if (MHD_NO == MHD_get_timeout (d, &timeout))
323 timeout = 100; /* 100ms == INFTY -- CURL bug... */
324 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) &&
325 (ctimeout < timeout) && (ctimeout >= 0))
326 timeout = ctimeout;
327 tv.tv_sec = timeout / 1000;
328 tv.tv_usec = (timeout % 1000) * 1000;
329 select (max + 1, &rs, &ws, &es, &tv);
330 while (CURLM_CALL_MULTI_PERFORM ==
331 curl_multi_perform (multi, &running));
332 if (running == 0)
333 {
334 msg = curl_multi_info_read (multi, &running);
335 if (msg == NULL)
336 break;
337 if (msg->msg == CURLMSG_DONE)
338 {
339 if (msg->data.result != CURLE_OK)
340 printf ("%s failed at %s:%d: `%s'\n",
341 "curl_multi_perform",
342 __FILE__,
343 __LINE__, curl_easy_strerror (msg->data.result));
344 curl_multi_remove_handle (multi, c);
345 curl_easy_cleanup (c);
346 c = NULL;
347 }
348 }
349 MHD_run (d);
350 }
351 if (c != NULL)
352 {
353 curl_multi_remove_handle (multi, c);
354 curl_easy_cleanup (c);
355 }
356 if ((buf[0] != 'O') || (buf[1] != 'K'))
357 {
358 curl_multi_cleanup (multi);
359 MHD_stop_daemon (d);
360 return 8192;
361 }
362 }
363 curl_multi_cleanup (multi);
364 MHD_stop_daemon (d);
365 fprintf (stderr, "\n");
366 return 0;
367}
368
369
370
371int
372main (int argc, char *const *argv)
373{
374 unsigned int errorCount = 0;
375
376 oneone = NULL != strstr (argv[0], "11");
377 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
378 return 2;
379 errorCount += testInternalPost ();
380 errorCount += testMultithreadedPost ();
381 errorCount += testExternalPost ();
382 if (errorCount != 0)
383 fprintf (stderr, "Error (code: %u)\n", errorCount);
384 curl_global_cleanup ();
385 return errorCount != 0; /* 0 == pass */
386}
diff --git a/src/testzzuf/daemontest_postform.c b/src/testzzuf/daemontest_postform.c
index 4142b138..e4f6ec3d 100644
--- a/src/testzzuf/daemontest_postform.c
+++ b/src/testzzuf/daemontest_postform.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007, 2008 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -35,6 +35,19 @@
35#include <unistd.h> 35#include <unistd.h>
36#endif 36#endif
37 37
38
39#include "socat.c"
40
41/**
42 * A larger loop count will run more random tests --
43 * which would be good, except that it may take too
44 * long for most user's patience. So this small
45 * value is the default.
46 */
47#define LOOP_COUNT 10
48
49#define CURL_TIMEOUT 50L
50
38static int oneone; 51static int oneone;
39 52
40struct CBC 53struct CBC
@@ -72,6 +85,8 @@ post_iterator (void *cls,
72{ 85{
73 int *eok = cls; 86 int *eok = cls;
74 87
88 if (key == NULL)
89 return MHD_YES;
75#if 0 90#if 0
76 fprintf (stderr, "PI sees %s-%.*s\n", key, size, value); 91 fprintf (stderr, "PI sees %s-%.*s\n", key, size, value);
77#endif 92#endif
@@ -100,7 +115,6 @@ ahc_echo (void *cls,
100 115
101 if (0 != strcmp ("POST", method)) 116 if (0 != strcmp ("POST", method))
102 { 117 {
103 printf ("METHOD: %s\n", method);
104 return MHD_NO; /* unexpected method */ 118 return MHD_NO; /* unexpected method */
105 } 119 }
106 pp = *unused; 120 pp = *unused;
@@ -109,7 +123,7 @@ ahc_echo (void *cls,
109 eok = 0; 123 eok = 0;
110 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 124 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
111 if (pp == NULL) 125 if (pp == NULL)
112 abort (); 126 return MHD_NO;
113 *unused = pp; 127 *unused = pp;
114 } 128 }
115 MHD_post_process (pp, upload_data, *upload_data_size); 129 MHD_post_process (pp, upload_data, *upload_data_size);
@@ -149,50 +163,44 @@ testInternalPost ()
149 CURL *c; 163 CURL *c;
150 char buf[2048]; 164 char buf[2048];
151 struct CBC cbc; 165 struct CBC cbc;
152 CURLcode errornum; 166 int i;
153 struct curl_httppost *pd; 167 struct curl_httppost *pd;
154 168
155 cbc.buf = buf; 169 cbc.buf = buf;
156 cbc.size = 2048; 170 cbc.size = 2048;
157 cbc.pos = 0; 171 cbc.pos = 0;
158 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 172 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
159 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 173 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
160 if (d == NULL) 174 if (d == NULL)
161 return 1; 175 return 1;
162 c = curl_easy_init (); 176 zzuf_socat_start ();
163 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); 177 for (i = 0; i < LOOP_COUNT; i++)
164 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
165 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
166 pd = make_form ();
167 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
168 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
169 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
170 if (oneone)
171 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
172 else
173 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
174 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
175 // NOTE: use of CONNECTTIMEOUT without also
176 // setting NOSIGNAL results in really weird
177 // crashes on my system!
178 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
179 if (CURLE_OK != (errornum = curl_easy_perform (c)))
180 { 178 {
181 fprintf (stderr, 179 fprintf (stderr, ".");
182 "curl_easy_perform failed: `%s'\n", 180 c = curl_easy_init ();
183 curl_easy_strerror (errornum)); 181 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
182 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
183 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
184 pd = make_form ();
185 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
186 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
187 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
188 if (oneone)
189 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
190 else
191 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
192 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
193 // NOTE: use of CONNECTTIMEOUT without also
194 // setting NOSIGNAL results in really weird
195 // crashes on my system!
196 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
197 curl_easy_perform (c);
184 curl_easy_cleanup (c); 198 curl_easy_cleanup (c);
185 curl_formfree (pd); 199 curl_formfree (pd);
186 MHD_stop_daemon (d);
187 return 2;
188 } 200 }
189 curl_easy_cleanup (c); 201 fprintf (stderr, "\n");
190 curl_formfree (pd); 202 zzuf_socat_stop ();
191 MHD_stop_daemon (d); 203 MHD_stop_daemon (d);
192 if (cbc.pos != strlen ("/hello_world"))
193 return 4;
194 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
195 return 8;
196 return 0; 204 return 0;
197} 205}
198 206
@@ -203,50 +211,44 @@ testMultithreadedPost ()
203 CURL *c; 211 CURL *c;
204 char buf[2048]; 212 char buf[2048];
205 struct CBC cbc; 213 struct CBC cbc;
206 CURLcode errornum; 214 int i;
207 struct curl_httppost *pd; 215 struct curl_httppost *pd;
208 216
209 cbc.buf = buf; 217 cbc.buf = buf;
210 cbc.size = 2048; 218 cbc.size = 2048;
211 cbc.pos = 0; 219 cbc.pos = 0;
212 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 220 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
213 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 221 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
214 if (d == NULL) 222 if (d == NULL)
215 return 16; 223 return 16;
216 c = curl_easy_init (); 224 zzuf_socat_start ();
217 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); 225 for (i = 0; i < LOOP_COUNT; i++)
218 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
219 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
220 pd = make_form ();
221 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
222 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
223 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
224 if (oneone)
225 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
226 else
227 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
228 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L);
229 // NOTE: use of CONNECTTIMEOUT without also
230 // setting NOSIGNAL results in really weird
231 // crashes on my system!
232 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
233 if (CURLE_OK != (errornum = curl_easy_perform (c)))
234 { 226 {
235 fprintf (stderr, 227 fprintf (stderr, ".");
236 "curl_easy_perform failed: `%s'\n", 228 c = curl_easy_init ();
237 curl_easy_strerror (errornum)); 229 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
230 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
231 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
232 pd = make_form ();
233 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
234 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
235 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
236 if (oneone)
237 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
238 else
239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
240 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
241 // NOTE: use of CONNECTTIMEOUT without also
242 // setting NOSIGNAL results in really weird
243 // crashes on my system!
244 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
245 curl_easy_perform (c);
238 curl_easy_cleanup (c); 246 curl_easy_cleanup (c);
239 curl_formfree (pd); 247 curl_formfree (pd);
240 MHD_stop_daemon (d);
241 return 32;
242 } 248 }
243 curl_easy_cleanup (c); 249 fprintf (stderr, "\n");
244 curl_formfree (pd); 250 zzuf_socat_stop ();
245 MHD_stop_daemon (d); 251 MHD_stop_daemon (d);
246 if (cbc.pos != strlen ("/hello_world"))
247 return 64;
248 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
249 return 128;
250 return 0; 252 return 0;
251} 253}
252 254
@@ -265,119 +267,112 @@ testExternalPost ()
265 fd_set es; 267 fd_set es;
266 int max; 268 int max;
267 int running; 269 int running;
268 struct CURLMsg *msg;
269 time_t start; 270 time_t start;
270 struct timeval tv; 271 struct timeval tv;
271 struct curl_httppost *pd; 272 struct curl_httppost *pd;
273 int i;
272 274
273 multi = NULL; 275 multi = NULL;
274 cbc.buf = buf; 276 cbc.buf = buf;
275 cbc.size = 2048; 277 cbc.size = 2048;
276 cbc.pos = 0; 278 cbc.pos = 0;
277 d = MHD_start_daemon (MHD_USE_DEBUG, 279 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
278 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); 280 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
279 if (d == NULL) 281 if (d == NULL)
280 return 256; 282 return 256;
281 c = curl_easy_init ();
282 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
283 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
284 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
285 pd = make_form ();
286 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
287 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
288 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
289 if (oneone)
290 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
291 else
292 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
293 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
294 // NOTE: use of CONNECTTIMEOUT without also
295 // setting NOSIGNAL results in really weird
296 // crashes on my system!
297 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
298
299
300 multi = curl_multi_init (); 283 multi = curl_multi_init ();
301 if (multi == NULL) 284 if (multi == NULL)
302 { 285 {
303 curl_easy_cleanup (c);
304 curl_formfree (pd);
305 MHD_stop_daemon (d); 286 MHD_stop_daemon (d);
306 return 512; 287 return 512;
307 } 288 }
308 mret = curl_multi_add_handle (multi, c); 289 zzuf_socat_start ();
309 if (mret != CURLM_OK) 290 for (i = 0; i < LOOP_COUNT; i++)
310 { 291 {
311 curl_multi_cleanup (multi); 292 fprintf (stderr, ".");
312 curl_formfree (pd); 293
313 curl_easy_cleanup (c); 294 c = curl_easy_init ();
314 MHD_stop_daemon (d); 295 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
315 return 1024; 296 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
316 } 297 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
317 start = time (NULL); 298 pd = make_form ();
318 while ((time (NULL) - start < 5) && (multi != NULL)) 299 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
319 { 300 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
320 max = 0; 301 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
321 FD_ZERO (&rs); 302 if (oneone)
322 FD_ZERO (&ws); 303 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
323 FD_ZERO (&es); 304 else
324 curl_multi_perform (multi, &running); 305 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
325 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 306 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
307 // NOTE: use of CONNECTTIMEOUT without also
308 // setting NOSIGNAL results in really weird
309 // crashes on my system!
310 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
311
312
313 mret = curl_multi_add_handle (multi, c);
326 if (mret != CURLM_OK) 314 if (mret != CURLM_OK)
327 { 315 {
328 curl_multi_remove_handle (multi, c);
329 curl_multi_cleanup (multi); 316 curl_multi_cleanup (multi);
330 curl_easy_cleanup (c);
331 MHD_stop_daemon (d);
332 curl_formfree (pd); 317 curl_formfree (pd);
333 return 2048;
334 }
335 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
336 {
337 curl_multi_remove_handle (multi, c);
338 curl_multi_cleanup (multi);
339 curl_easy_cleanup (c); 318 curl_easy_cleanup (c);
340 curl_formfree (pd); 319 zzuf_socat_stop ();
341 MHD_stop_daemon (d); 320 MHD_stop_daemon (d);
342 return 4096; 321 return 1024;
343 } 322 }
344 tv.tv_sec = 0; 323 start = time (NULL);
345 tv.tv_usec = 1000; 324 while ((time (NULL) - start < 5) && (c != NULL))
346 select (max + 1, &rs, &ws, &es, &tv);
347 curl_multi_perform (multi, &running);
348 if (running == 0)
349 { 325 {
350 msg = curl_multi_info_read (multi, &running); 326 max = 0;
351 if (msg == NULL) 327 FD_ZERO (&rs);
352 break; 328 FD_ZERO (&ws);
353 if (msg->msg == CURLMSG_DONE) 329 FD_ZERO (&es);
330 curl_multi_perform (multi, &running);
331 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
332 if (mret != CURLM_OK)
333 {
334 curl_multi_remove_handle (multi, c);
335 curl_multi_cleanup (multi);
336 curl_easy_cleanup (c);
337 zzuf_socat_stop ();
338 MHD_stop_daemon (d);
339 curl_formfree (pd);
340 return 2048;
341 }
342 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
354 { 343 {
355 if (msg->data.result != CURLE_OK)
356 printf ("%s failed at %s:%d: `%s'\n",
357 "curl_multi_perform",
358 __FILE__,
359 __LINE__, curl_easy_strerror (msg->data.result));
360 curl_multi_remove_handle (multi, c); 344 curl_multi_remove_handle (multi, c);
361 curl_multi_cleanup (multi); 345 curl_multi_cleanup (multi);
362 curl_easy_cleanup (c); 346 curl_easy_cleanup (c);
347 curl_formfree (pd);
348 zzuf_socat_stop ();
349 MHD_stop_daemon (d);
350 return 4096;
351 }
352 tv.tv_sec = 0;
353 tv.tv_usec = 1000;
354 select (max + 1, &rs, &ws, &es, &tv);
355 curl_multi_perform (multi, &running);
356 if (running == 0)
357 {
358 curl_multi_info_read (multi, &running);
359 curl_multi_remove_handle (multi, c);
360 curl_easy_cleanup (c);
363 c = NULL; 361 c = NULL;
364 multi = NULL;
365 } 362 }
363 MHD_run (d);
366 } 364 }
367 MHD_run (d); 365 if (c != NULL)
368 } 366 {
369 if (multi != NULL) 367 curl_multi_remove_handle (multi, c);
370 { 368 curl_easy_cleanup (c);
371 curl_multi_remove_handle (multi, c); 369 }
372 curl_easy_cleanup (c); 370 curl_formfree (pd);
373 curl_multi_cleanup (multi);
374 } 371 }
375 curl_formfree (pd); 372 fprintf (stderr, "\n");
373 zzuf_socat_stop ();
374
376 MHD_stop_daemon (d); 375 MHD_stop_daemon (d);
377 if (cbc.pos != strlen ("/hello_world"))
378 return 8192;
379 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
380 return 16384;
381 return 0; 376 return 0;
382} 377}
383 378
@@ -392,11 +387,8 @@ main (int argc, char *const *argv)
392 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 387 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
393 return 2; 388 return 2;
394 errorCount += testInternalPost (); 389 errorCount += testInternalPost ();
395 if (0) 390 errorCount += testMultithreadedPost ();
396 { 391 errorCount += testExternalPost ();
397 errorCount += testMultithreadedPost ();
398 errorCount += testExternalPost ();
399 }
400 if (errorCount != 0) 392 if (errorCount != 0)
401 fprintf (stderr, "Error (code: %u)\n", errorCount); 393 fprintf (stderr, "Error (code: %u)\n", errorCount);
402 curl_global_cleanup (); 394 curl_global_cleanup ();
diff --git a/src/testzzuf/daemontest_put.c b/src/testzzuf/daemontest_put.c
index e1f89402..82ab2289 100644
--- a/src/testzzuf/daemontest_put.c
+++ b/src/testzzuf/daemontest_put.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007, 2008 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -35,6 +35,19 @@
35#include <unistd.h> 35#include <unistd.h>
36#endif 36#endif
37 37
38
39#include "socat.c"
40
41/**
42 * A larger loop count will run more random tests --
43 * which would be good, except that it may take too
44 * long for most user's patience. So this small
45 * value is the default.
46 */
47#define LOOP_COUNT 10
48
49#define CURL_TIMEOUT 50L
50
38static int oneone; 51static int oneone;
39 52
40struct CBC 53struct CBC
@@ -118,50 +131,45 @@ testInternalPut ()
118 struct CBC cbc; 131 struct CBC cbc;
119 unsigned int pos = 0; 132 unsigned int pos = 0;
120 int done_flag = 0; 133 int done_flag = 0;
121 CURLcode errornum; 134 int i;
122 135
123 cbc.buf = buf; 136 cbc.buf = buf;
124 cbc.size = 2048; 137 cbc.size = 2048;
125 cbc.pos = 0; 138 cbc.pos = 0;
126 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 139 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
127 1080, 140 11080,
128 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 141 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
129 if (d == NULL) 142 if (d == NULL)
130 return 1; 143 return 1;
131 c = curl_easy_init (); 144 zzuf_socat_start ();
132 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); 145 for (i = 0; i < LOOP_COUNT; i++)
133 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
134 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
135 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
136 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
137 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
138 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
139 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
140 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
141 if (oneone)
142 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
143 else
144 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
145 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
146 // NOTE: use of CONNECTTIMEOUT without also
147 // setting NOSIGNAL results in really weird
148 // crashes on my system!
149 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
150 if (CURLE_OK != (errornum = curl_easy_perform (c)))
151 { 146 {
152 fprintf (stderr, 147 fprintf (stderr, ".");
153 "curl_easy_perform failed: `%s'\n", 148 c = curl_easy_init ();
154 curl_easy_strerror (errornum)); 149 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
150 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
151 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
152 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
153 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
154 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
155 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
156 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
157 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
158 if (oneone)
159 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
160 else
161 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
162 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
163 // NOTE: use of CONNECTTIMEOUT without also
164 // setting NOSIGNAL results in really weird
165 // crashes on my system!
166 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
167 curl_easy_perform (c);
155 curl_easy_cleanup (c); 168 curl_easy_cleanup (c);
156 MHD_stop_daemon (d);
157 return 2;
158 } 169 }
159 curl_easy_cleanup (c); 170 fprintf (stderr, "\n");
171 zzuf_socat_stop ();
160 MHD_stop_daemon (d); 172 MHD_stop_daemon (d);
161 if (cbc.pos != strlen ("/hello_world"))
162 return 4;
163 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
164 return 8;
165 return 0; 173 return 0;
166} 174}
167 175
@@ -174,51 +182,45 @@ testMultithreadedPut ()
174 struct CBC cbc; 182 struct CBC cbc;
175 unsigned int pos = 0; 183 unsigned int pos = 0;
176 int done_flag = 0; 184 int done_flag = 0;
177 CURLcode errornum; 185 int i;
178 186
179 cbc.buf = buf; 187 cbc.buf = buf;
180 cbc.size = 2048; 188 cbc.size = 2048;
181 cbc.pos = 0; 189 cbc.pos = 0;
182 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 190 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
183 1081, 191 11080,
184 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 192 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
185 if (d == NULL) 193 if (d == NULL)
186 return 16; 194 return 16;
187 c = curl_easy_init (); 195 zzuf_socat_start ();
188 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); 196 for (i = 0; i < LOOP_COUNT; i++)
189 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
190 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
191 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
192 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
193 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
194 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
195 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
196 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
197 if (oneone)
198 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
199 else
200 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
201 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
202 // NOTE: use of CONNECTTIMEOUT without also
203 // setting NOSIGNAL results in really weird
204 // crashes on my system!
205 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
206 if (CURLE_OK != (errornum = curl_easy_perform (c)))
207 { 197 {
208 fprintf (stderr, 198 fprintf (stderr, ".");
209 "curl_easy_perform failed: `%s'\n", 199 c = curl_easy_init ();
210 curl_easy_strerror (errornum)); 200 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
201 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
202 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
203 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
204 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
205 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
206 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
207 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
208 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
209 if (oneone)
210 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
211 else
212 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
213 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
214 // NOTE: use of CONNECTTIMEOUT without also
215 // setting NOSIGNAL results in really weird
216 // crashes on my system!
217 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
218 curl_easy_perform (c);
211 curl_easy_cleanup (c); 219 curl_easy_cleanup (c);
212 MHD_stop_daemon (d);
213 return 32;
214 } 220 }
215 curl_easy_cleanup (c); 221 fprintf (stderr, "\n");
222 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 223 MHD_stop_daemon (d);
217 if (cbc.pos != strlen ("/hello_world"))
218 return 64;
219 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
220 return 128;
221
222 return 0; 224 return 0;
223} 225}
224 226
@@ -237,118 +239,113 @@ testExternalPut ()
237 fd_set es; 239 fd_set es;
238 int max; 240 int max;
239 int running; 241 int running;
240 struct CURLMsg *msg;
241 time_t start; 242 time_t start;
242 struct timeval tv; 243 struct timeval tv;
243 unsigned int pos = 0; 244 unsigned int pos = 0;
244 int done_flag = 0; 245 int done_flag = 0;
246 int i;
245 247
246 multi = NULL; 248 multi = NULL;
247 cbc.buf = buf; 249 cbc.buf = buf;
248 cbc.size = 2048; 250 cbc.size = 2048;
249 cbc.pos = 0; 251 cbc.pos = 0;
250 d = MHD_start_daemon (MHD_USE_DEBUG, 252 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
251 1082, 253 11080,
252 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 254 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
253 if (d == NULL) 255 if (d == NULL)
254 return 256; 256 return 256;
255 c = curl_easy_init ();
256 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
257 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
258 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
259 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
260 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
261 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
262 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
263 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
264 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
265 if (oneone)
266 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
267 else
268 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
269 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
270 // NOTE: use of CONNECTTIMEOUT without also
271 // setting NOSIGNAL results in really weird
272 // crashes on my system!
273 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
274
275
276 multi = curl_multi_init (); 257 multi = curl_multi_init ();
277 if (multi == NULL) 258 if (multi == NULL)
278 { 259 {
279 curl_easy_cleanup (c);
280 MHD_stop_daemon (d); 260 MHD_stop_daemon (d);
281 return 512; 261 return 512;
282 } 262 }
283 mret = curl_multi_add_handle (multi, c); 263 zzuf_socat_start ();
284 if (mret != CURLM_OK) 264 for (i = 0; i < LOOP_COUNT; i++)
285 {
286 curl_multi_cleanup (multi);
287 curl_easy_cleanup (c);
288 MHD_stop_daemon (d);
289 return 1024;
290 }
291 start = time (NULL);
292 while ((time (NULL) - start < 5) && (multi != NULL))
293 { 265 {
294 max = 0; 266 fprintf (stderr, ".");
295 FD_ZERO (&rs); 267
296 FD_ZERO (&ws); 268 c = curl_easy_init ();
297 FD_ZERO (&es); 269 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
298 curl_multi_perform (multi, &running); 270 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
299 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 271 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
272 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
273 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
274 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
275 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
276 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
277 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
278 if (oneone)
279 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
280 else
281 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
282 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
283 // NOTE: use of CONNECTTIMEOUT without also
284 // setting NOSIGNAL results in really weird
285 // crashes on my system!
286 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
287
288
289
290 mret = curl_multi_add_handle (multi, c);
300 if (mret != CURLM_OK) 291 if (mret != CURLM_OK)
301 { 292 {
302 curl_multi_remove_handle (multi, c);
303 curl_multi_cleanup (multi);
304 curl_easy_cleanup (c);
305 MHD_stop_daemon (d);
306 return 2048;
307 }
308 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
309 {
310 curl_multi_remove_handle (multi, c);
311 curl_multi_cleanup (multi); 293 curl_multi_cleanup (multi);
312 curl_easy_cleanup (c); 294 curl_easy_cleanup (c);
295 zzuf_socat_stop ();
313 MHD_stop_daemon (d); 296 MHD_stop_daemon (d);
314 return 4096; 297 return 1024;
315 } 298 }
316 tv.tv_sec = 0; 299 start = time (NULL);
317 tv.tv_usec = 1000; 300 while ((time (NULL) - start < 5) && (c != NULL))
318 select (max + 1, &rs, &ws, &es, &tv);
319 curl_multi_perform (multi, &running);
320 if (running == 0)
321 { 301 {
322 msg = curl_multi_info_read (multi, &running); 302 max = 0;
323 if (msg == NULL) 303 FD_ZERO (&rs);
324 break; 304 FD_ZERO (&ws);
325 if (msg->msg == CURLMSG_DONE) 305 FD_ZERO (&es);
306 curl_multi_perform (multi, &running);
307 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
308 if (mret != CURLM_OK)
326 { 309 {
327 if (msg->data.result != CURLE_OK)
328 printf ("%s failed at %s:%d: `%s'\n",
329 "curl_multi_perform",
330 __FILE__,
331 __LINE__, curl_easy_strerror (msg->data.result));
332 curl_multi_remove_handle (multi, c); 310 curl_multi_remove_handle (multi, c);
333 curl_multi_cleanup (multi); 311 curl_multi_cleanup (multi);
334 curl_easy_cleanup (c); 312 curl_easy_cleanup (c);
313 zzuf_socat_stop ();
314 MHD_stop_daemon (d);
315 return 2048;
316 }
317 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
318 {
319 curl_multi_remove_handle (multi, c);
320 curl_multi_cleanup (multi);
321 curl_easy_cleanup (c);
322 zzuf_socat_stop ();
323 MHD_stop_daemon (d);
324 return 4096;
325 }
326 tv.tv_sec = 0;
327 tv.tv_usec = 1000;
328 select (max + 1, &rs, &ws, &es, &tv);
329 curl_multi_perform (multi, &running);
330 if (running == 0)
331 {
332 curl_multi_info_read (multi, &running);
333 curl_multi_remove_handle (multi, c);
334 curl_easy_cleanup (c);
335 c = NULL; 335 c = NULL;
336 multi = NULL;
337 } 336 }
337 MHD_run (d);
338 }
339 if (c != NULL)
340 {
341 curl_multi_remove_handle (multi, c);
342 curl_easy_cleanup (c);
338 } 343 }
339 MHD_run (d);
340 }
341 if (multi != NULL)
342 {
343 curl_multi_remove_handle (multi, c);
344 curl_easy_cleanup (c);
345 curl_multi_cleanup (multi);
346 } 344 }
345 fprintf (stderr, "\n");
346 curl_multi_cleanup (multi);
347 zzuf_socat_stop ();
347 MHD_stop_daemon (d); 348 MHD_stop_daemon (d);
348 if (cbc.pos != strlen ("/hello_world"))
349 return 8192;
350 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
351 return 16384;
352 return 0; 349 return 0;
353} 350}
354 351
@@ -363,11 +360,8 @@ main (int argc, char *const *argv)
363 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 360 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
364 return 2; 361 return 2;
365 errorCount += testInternalPut (); 362 errorCount += testInternalPut ();
366 if (0) 363 errorCount += testMultithreadedPut ();
367 { 364 errorCount += testExternalPut ();
368 errorCount += testMultithreadedPut ();
369 errorCount += testExternalPut ();
370 }
371 if (errorCount != 0) 365 if (errorCount != 0)
372 fprintf (stderr, "Error (code: %u)\n", errorCount); 366 fprintf (stderr, "Error (code: %u)\n", errorCount);
373 curl_global_cleanup (); 367 curl_global_cleanup ();
diff --git a/src/testzzuf/daemontest_put_chunked.c b/src/testzzuf/daemontest_put_chunked.c
index 0cc3eb8f..a78db8d3 100644
--- a/src/testzzuf/daemontest_put_chunked.c
+++ b/src/testzzuf/daemontest_put_chunked.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Christian Grothoff 3 (C) 2007, 2008 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -36,6 +36,18 @@
36#include <unistd.h> 36#include <unistd.h>
37#endif 37#endif
38 38
39#include "socat.c"
40
41/**
42 * A larger loop count will run more random tests --
43 * which would be good, except that it may take too
44 * long for most user's patience. So this small
45 * value is the default.
46 */
47#define LOOP_COUNT 10
48
49#define CURL_TIMEOUT 50L
50
39struct CBC 51struct CBC
40{ 52{
41 char *buf; 53 char *buf;
@@ -92,7 +104,6 @@ ahc_echo (void *cls,
92 have = *upload_data_size; 104 have = *upload_data_size;
93 if (have + *done > 8) 105 if (have + *done > 8)
94 { 106 {
95 printf ("Invalid upload data `%8s'!\n", upload_data);
96 return MHD_NO; 107 return MHD_NO;
97 } 108 }
98 if (0 == memcmp (upload_data, &"Hello123"[*done], have)) 109 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
@@ -102,7 +113,6 @@ ahc_echo (void *cls,
102 } 113 }
103 else 114 else
104 { 115 {
105 printf ("Invalid upload data `%8s'!\n", upload_data);
106 return MHD_NO; 116 return MHD_NO;
107 } 117 }
108#if 0 118#if 0
@@ -127,7 +137,7 @@ testInternalPut ()
127 struct CBC cbc; 137 struct CBC cbc;
128 unsigned int pos = 0; 138 unsigned int pos = 0;
129 int done_flag = 0; 139 int done_flag = 0;
130 CURLcode errornum; 140 int i;
131 141
132 cbc.buf = buf; 142 cbc.buf = buf;
133 cbc.size = 2048; 143 cbc.size = 2048;
@@ -137,40 +147,35 @@ testInternalPut ()
137 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 147 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
138 if (d == NULL) 148 if (d == NULL)
139 return 1; 149 return 1;
140 c = curl_easy_init (); 150 zzuf_socat_start ();
141 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/hello_world"); 151 for (i = 0; i < LOOP_COUNT; i++)
142 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
143 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
144 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
145 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
146 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
147 /*
148 // by not giving the file size, we force chunking!
149 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
150 */
151 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
152 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
153 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
154 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
155 // NOTE: use of CONNECTTIMEOUT without also
156 // setting NOSIGNAL results in really weird
157 // crashes on my system!
158 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
159 if (CURLE_OK != (errornum = curl_easy_perform (c)))
160 { 152 {
161 fprintf (stderr, 153 fprintf (stderr, ".");
162 "curl_easy_perform failed: `%s'\n", 154 c = curl_easy_init ();
163 curl_easy_strerror (errornum)); 155 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/hello_world");
156 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
157 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
158 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
159 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
160 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
161 /*
162 // by not giving the file size, we force chunking!
163 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
164 */
165 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
166 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
167 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
168 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
169 // NOTE: use of CONNECTTIMEOUT without also
170 // setting NOSIGNAL results in really weird
171 // crashes on my system!
172 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
173 curl_easy_perform (c);
164 curl_easy_cleanup (c); 174 curl_easy_cleanup (c);
165 MHD_stop_daemon (d);
166 return 2;
167 } 175 }
168 curl_easy_cleanup (c); 176 fprintf (stderr, "\n");
177 zzuf_socat_stop ();
169 MHD_stop_daemon (d); 178 MHD_stop_daemon (d);
170 if (cbc.pos != strlen ("/hello_world"))
171 return 4;
172 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
173 return 8;
174 return 0; 179 return 0;
175} 180}
176 181
@@ -246,11 +251,11 @@ testExternalPut ()
246 fd_set es; 251 fd_set es;
247 int max; 252 int max;
248 int running; 253 int running;
249 struct CURLMsg *msg;
250 time_t start; 254 time_t start;
251 struct timeval tv; 255 struct timeval tv;
252 unsigned int pos = 0; 256 unsigned int pos = 0;
253 int done_flag = 0; 257 int done_flag = 0;
258 int i;
254 259
255 multi = NULL; 260 multi = NULL;
256 cbc.buf = buf; 261 cbc.buf = buf;
@@ -261,103 +266,97 @@ testExternalPut ()
261 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 266 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
262 if (d == NULL) 267 if (d == NULL)
263 return 256; 268 return 256;
264 c = curl_easy_init ();
265 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11082/hello_world");
266 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
267 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
268 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
269 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
270 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
271 /*
272 // by not giving the file size, we force chunking!
273 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
274 */
275 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
276 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
277 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
278 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
279 // NOTE: use of CONNECTTIMEOUT without also
280 // setting NOSIGNAL results in really weird
281 // crashes on my system!
282 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
283
284 269
285 multi = curl_multi_init (); 270 multi = curl_multi_init ();
286 if (multi == NULL) 271 if (multi == NULL)
287 { 272 {
288 curl_easy_cleanup (c);
289 MHD_stop_daemon (d); 273 MHD_stop_daemon (d);
290 return 512; 274 return 512;
291 } 275 }
292 mret = curl_multi_add_handle (multi, c); 276 zzuf_socat_start ();
293 if (mret != CURLM_OK) 277 for (i = 0; i < LOOP_COUNT; i++)
294 { 278 {
295 curl_multi_cleanup (multi); 279 fprintf (stderr, ".");
296 curl_easy_cleanup (c); 280 c = curl_easy_init ();
297 MHD_stop_daemon (d); 281 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11082/hello_world");
298 return 1024; 282 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
299 } 283 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
300 start = time (NULL); 284 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
301 while ((time (NULL) - start < 5) && (multi != NULL)) 285 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
302 { 286 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
303 max = 0; 287 /*
304 FD_ZERO (&rs); 288 // by not giving the file size, we force chunking!
305 FD_ZERO (&ws); 289 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
306 FD_ZERO (&es); 290 */
307 curl_multi_perform (multi, &running); 291 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
308 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 292 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
293 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
294 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
295 // NOTE: use of CONNECTTIMEOUT without also
296 // setting NOSIGNAL results in really weird
297 // crashes on my system!
298 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
299
300
301 mret = curl_multi_add_handle (multi, c);
309 if (mret != CURLM_OK) 302 if (mret != CURLM_OK)
310 { 303 {
311 curl_multi_remove_handle (multi, c);
312 curl_multi_cleanup (multi);
313 curl_easy_cleanup (c);
314 MHD_stop_daemon (d);
315 return 2048;
316 }
317 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
318 {
319 curl_multi_remove_handle (multi, c);
320 curl_multi_cleanup (multi); 304 curl_multi_cleanup (multi);
321 curl_easy_cleanup (c); 305 curl_easy_cleanup (c);
306 zzuf_socat_stop ();
322 MHD_stop_daemon (d); 307 MHD_stop_daemon (d);
323 return 4096; 308 return 1024;
324 } 309 }
325 tv.tv_sec = 0; 310 start = time (NULL);
326 tv.tv_usec = 1000; 311 while ((time (NULL) - start < 5) && (c != NULL))
327 select (max + 1, &rs, &ws, &es, &tv);
328 curl_multi_perform (multi, &running);
329 if (running == 0)
330 { 312 {
331 msg = curl_multi_info_read (multi, &running); 313 max = 0;
332 if (msg == NULL) 314 FD_ZERO (&rs);
333 break; 315 FD_ZERO (&ws);
334 if (msg->msg == CURLMSG_DONE) 316 FD_ZERO (&es);
317 curl_multi_perform (multi, &running);
318 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
319 if (mret != CURLM_OK)
320 {
321 curl_multi_remove_handle (multi, c);
322 curl_multi_cleanup (multi);
323 curl_easy_cleanup (c);
324 zzuf_socat_stop ();
325 MHD_stop_daemon (d);
326 return 2048;
327 }
328 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
335 { 329 {
336 if (msg->data.result != CURLE_OK)
337 printf ("%s failed at %s:%d: `%s'\n",
338 "curl_multi_perform",
339 __FILE__,
340 __LINE__, curl_easy_strerror (msg->data.result));
341 curl_multi_remove_handle (multi, c); 330 curl_multi_remove_handle (multi, c);
342 curl_multi_cleanup (multi); 331 curl_multi_cleanup (multi);
343 curl_easy_cleanup (c); 332 curl_easy_cleanup (c);
333 zzuf_socat_stop ();
334 MHD_stop_daemon (d);
335 return 4096;
336 }
337 tv.tv_sec = 0;
338 tv.tv_usec = 1000;
339 select (max + 1, &rs, &ws, &es, &tv);
340 curl_multi_perform (multi, &running);
341 if (running == 0)
342 {
343 curl_multi_info_read (multi, &running);
344 curl_multi_remove_handle (multi, c);
345 curl_easy_cleanup (c);
344 c = NULL; 346 c = NULL;
345 multi = NULL;
346 } 347 }
348 MHD_run (d);
349 }
350 if (c != NULL)
351 {
352 curl_multi_remove_handle (multi, c);
353 curl_easy_cleanup (c);
347 } 354 }
348 MHD_run (d);
349 }
350 if (multi != NULL)
351 {
352 curl_multi_remove_handle (multi, c);
353 curl_easy_cleanup (c);
354 curl_multi_cleanup (multi);
355 } 355 }
356 fprintf (stderr, "\n");
357 curl_multi_cleanup (multi);
358 zzuf_socat_stop ();
356 MHD_stop_daemon (d); 359 MHD_stop_daemon (d);
357 if (cbc.pos != strlen ("/hello_world"))
358 return 8192;
359 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
360 return 16384;
361 return 0; 360 return 0;
362} 361}
363 362
@@ -371,11 +370,8 @@ main (int argc, char *const *argv)
371 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 370 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
372 return 2; 371 return 2;
373 errorCount += testInternalPut (); 372 errorCount += testInternalPut ();
374 if (0) 373 errorCount += testMultithreadedPut ();
375 { 374 errorCount += testExternalPut ();
376 errorCount += testMultithreadedPut ();
377 errorCount += testExternalPut ();
378 }
379 if (errorCount != 0) 375 if (errorCount != 0)
380 fprintf (stderr, "Error (code: %u)\n", errorCount); 376 fprintf (stderr, "Error (code: %u)\n", errorCount);
381 curl_global_cleanup (); 377 curl_global_cleanup ();
diff --git a/src/testzzuf/socat.c b/src/testzzuf/socat.c
index 0933010b..800d5c37 100644
--- a/src/testzzuf/socat.c
+++ b/src/testzzuf/socat.c
@@ -42,6 +42,9 @@ zzuf_socat_start ()
42 "-n", 42 "-n",
43 "-A", 43 "-A",
44 "socat", 44 "socat",
45 "--",
46 "-lf",
47 "/dev/null",
45 "TCP4-LISTEN:11081,reuseaddr,fork", 48 "TCP4-LISTEN:11081,reuseaddr,fork",
46 "TCP4:127.0.0.1:11080", 49 "TCP4:127.0.0.1:11080",
47 NULL, 50 NULL,