summaryrefslogtreecommitdiff
path: root/src/testzzuf/daemontest_post.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/daemontest_post.c')
-rw-r--r--src/testzzuf/daemontest_post.c288
1 files changed, 147 insertions, 141 deletions
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 @@
/*
This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
+ (C) 2007, 2008 Christian Grothoff
libmicrohttpd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -35,6 +35,20 @@
#include <unistd.h>
#endif
+
+#include "socat.c"
+
+/**
+ * A larger loop count will run more random tests --
+ * which would be good, except that it may take too
+ * long for most user's patience. So this small
+ * value is the default.
+ */
+#define LOOP_COUNT 10
+
+#define CURL_TIMEOUT 50L
+
+
#define POST_DATA "name=daniel&project=curl"
static int oneone;
@@ -99,7 +113,6 @@ ahc_echo (void *cls,
if (0 != strcmp ("POST", method))
{
- printf ("METHOD: %s\n", method);
return MHD_NO; /* unexpected method */
}
pp = *unused;
@@ -133,48 +146,45 @@ testInternalPost ()
CURL *c;
char buf[2048];
struct CBC cbc;
- CURLcode errornum;
+ int i;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
- d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
- 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
+ d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
+ 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
- c = curl_easy_init ();
- curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world");
- curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
- curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
- curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
- curl_easy_setopt (c, CURLOPT_POST, 1L);
- curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
- if (oneone)
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- else
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
- // NOTE: use of CONNECTTIMEOUT without also
- // setting NOSIGNAL results in really weird
- // crashes on my system!
- curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
- if (CURLE_OK != (errornum = curl_easy_perform (c)))
+ zzuf_socat_start ();
+ for (i = 0; i < LOOP_COUNT; i++)
{
- fprintf (stderr,
- "curl_easy_perform failed: `%s'\n",
- curl_easy_strerror (errornum));
+ fprintf (stderr, ".");
+
+ c = curl_easy_init ();
+ curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
+ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
+ curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
+ curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
+ curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
+ curl_easy_setopt (c, CURLOPT_POST, 1L);
+ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
+ if (oneone)
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ else
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
+ // NOTE: use of CONNECTTIMEOUT without also
+ // setting NOSIGNAL results in really weird
+ // crashes on my system!
+ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
+ curl_easy_perform (c);
curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 2;
}
- curl_easy_cleanup (c);
+ fprintf (stderr, "\n");
+ zzuf_socat_stop ();
MHD_stop_daemon (d);
- if (cbc.pos != strlen ("/hello_world"))
- return 4;
- if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
- return 8;
+
return 0;
}
@@ -185,48 +195,46 @@ testMultithreadedPost ()
CURL *c;
char buf[2048];
struct CBC cbc;
- CURLcode errornum;
+ int i;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
- 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ ,
+ 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 16;
- c = curl_easy_init ();
- curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world");
- curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
- curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
- curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
- curl_easy_setopt (c, CURLOPT_POST, 1L);
- curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
- if (oneone)
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- else
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
- // NOTE: use of CONNECTTIMEOUT without also
- // setting NOSIGNAL results in really weird
- // crashes on my system!
- curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
- if (CURLE_OK != (errornum = curl_easy_perform (c)))
+
+ zzuf_socat_start ();
+ for (i = 0; i < LOOP_COUNT; i++)
{
- fprintf (stderr,
- "curl_easy_perform failed: `%s'\n",
- curl_easy_strerror (errornum));
+ fprintf (stderr, ".");
+
+ c = curl_easy_init ();
+ curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
+ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
+ curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
+ curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
+ curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
+ curl_easy_setopt (c, CURLOPT_POST, 1L);
+ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
+ if (oneone)
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ else
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
+ // NOTE: use of CONNECTTIMEOUT without also
+ // setting NOSIGNAL results in really weird
+ // crashes on my system!
+ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
+ curl_easy_perform (c);
curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 32;
}
- curl_easy_cleanup (c);
+ fprintf (stderr, "\n");
+ zzuf_socat_stop ();
+
MHD_stop_daemon (d);
- if (cbc.pos != strlen ("/hello_world"))
- return 64;
- if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
- return 128;
return 0;
}
@@ -245,114 +253,112 @@ testExternalPost ()
fd_set es;
int max;
int running;
- struct CURLMsg *msg;
time_t start;
struct timeval tv;
+ int i;
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
- d = MHD_start_daemon (MHD_USE_DEBUG,
+ d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 256;
- c = curl_easy_init ();
- curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
- curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
- curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
- curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
- curl_easy_setopt (c, CURLOPT_POST, 1L);
- curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
- if (oneone)
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- else
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
- // NOTE: use of CONNECTTIMEOUT without also
- // setting NOSIGNAL results in really weird
- // crashes on my system!
- curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
-
-
multi = curl_multi_init ();
if (multi == NULL)
{
- curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 512;
}
- mret = curl_multi_add_handle (multi, c);
- if (mret != CURLM_OK)
- {
- curl_multi_cleanup (multi);
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 1024;
- }
- start = time (NULL);
- while ((time (NULL) - start < 5) && (multi != NULL))
+
+ zzuf_socat_start ();
+ for (i = 0; i < LOOP_COUNT; i++)
{
- max = 0;
- FD_ZERO (&rs);
- FD_ZERO (&ws);
- FD_ZERO (&es);
- curl_multi_perform (multi, &running);
- mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
+ fprintf (stderr, ".");
+
+
+ c = curl_easy_init ();
+ curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world");
+ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
+ curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
+ curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
+ curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
+ curl_easy_setopt (c, CURLOPT_POST, 1L);
+ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
+ if (oneone)
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ else
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
+ // NOTE: use of CONNECTTIMEOUT without also
+ // setting NOSIGNAL results in really weird
+ // crashes on my system!
+ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
+
+
+ mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
- curl_multi_remove_handle (multi, c);
- curl_multi_cleanup (multi);
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 2048;
- }
- if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
- {
- curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
+ zzuf_socat_stop ();
MHD_stop_daemon (d);
- return 4096;
+ return 1024;
}
- tv.tv_sec = 0;
- tv.tv_usec = 1000;
- select (max + 1, &rs, &ws, &es, &tv);
- curl_multi_perform (multi, &running);
- if (running == 0)
+ start = time (NULL);
+ while ((time (NULL) - start < 5) && (c != NULL))
{
- msg = curl_multi_info_read (multi, &running);
- if (msg == NULL)
- break;
- if (msg->msg == CURLMSG_DONE)
+ max = 0;
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
+ curl_multi_perform (multi, &running);
+ mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
+ if (mret != CURLM_OK)
{
- if (msg->data.result != CURLE_OK)
- printf ("%s failed at %s:%d: `%s'\n",
- "curl_multi_perform",
- __FILE__,
- __LINE__, curl_easy_strerror (msg->data.result));
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
+ zzuf_socat_stop ();
+ MHD_stop_daemon (d);
+ return 2048;
+ }
+ if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
+ {
+ curl_multi_remove_handle (multi, c);
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (c);
+ zzuf_socat_stop ();
+ MHD_stop_daemon (d);
+ return 4096;
+ }
+ tv.tv_sec = 0;
+ tv.tv_usec = 1000;
+ select (max + 1, &rs, &ws, &es, &tv);
+ curl_multi_perform (multi, &running);
+ if (running == 0)
+ {
+ curl_multi_info_read (multi, &running);
+ curl_multi_remove_handle (multi, c);
+ curl_easy_cleanup (c);
c = NULL;
- multi = NULL;
}
+ MHD_run (d);
}
- MHD_run (d);
- }
- if (multi != NULL)
- {
- curl_multi_remove_handle (multi, c);
- curl_easy_cleanup (c);
- curl_multi_cleanup (multi);
+ if (c != NULL)
+ {
+ curl_multi_remove_handle (multi, c);
+ curl_easy_cleanup (c);
+ }
+
}
+ fprintf (stderr, "\n");
+ curl_multi_cleanup (multi);
+ zzuf_socat_stop ();
+
MHD_stop_daemon (d);
- if (cbc.pos != strlen ("/hello_world"))
- return 8192;
- if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
- return 16384;
return 0;
}