|
|
@@ -55,6 +55,7 @@
|
|
|
#endif
|
|
|
|
|
|
static int oneone;
|
|
|
+static int global_port;
|
|
|
|
|
|
struct CBC
|
|
|
{
|
|
|
@@ -117,35 +118,35 @@ testInternalGet (int poll_flag)
|
|
|
char buf[2048];
|
|
|
struct CBC cbc;
|
|
|
CURLcode errornum;
|
|
|
- int port;
|
|
|
|
|
|
- if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
- port = 0;
|
|
|
- else
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
- port = 1220;
|
|
|
- if (oneone)
|
|
|
- port += 20;
|
|
|
+ if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
+ {
|
|
|
+ global_port = 1220;
|
|
|
+ if (oneone)
|
|
|
+ global_port += 20;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cbc.buf = buf;
|
|
|
cbc.size = 2048;
|
|
|
cbc.pos = 0;
|
|
|
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
|
- port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
+ global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
if (d == NULL)
|
|
|
return 1;
|
|
|
- if (0 == port)
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
const union MHD_DaemonInfo *dinfo;
|
|
|
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
|
|
|
if (NULL == dinfo || 0 == dinfo->port)
|
|
|
{ MHD_stop_daemon (d); return 32; }
|
|
|
- port = (int)dinfo->port;
|
|
|
+ global_port = (int)dinfo->port;
|
|
|
}
|
|
|
c = curl_easy_init ();
|
|
|
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
|
|
|
- curl_easy_setopt (c, CURLOPT_PORT, (long)port);
|
|
|
+ curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
|
|
|
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
|
|
|
@@ -186,35 +187,35 @@ testMultithreadedGet (int poll_flag)
|
|
|
char buf[2048];
|
|
|
struct CBC cbc;
|
|
|
CURLcode errornum;
|
|
|
- int port;
|
|
|
|
|
|
- if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
- port = 0;
|
|
|
- else
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
- port = 1221;
|
|
|
- if (oneone)
|
|
|
- port += 20;
|
|
|
+ if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
+ {
|
|
|
+ global_port = 1221;
|
|
|
+ if (oneone)
|
|
|
+ global_port += 20;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cbc.buf = buf;
|
|
|
cbc.size = 2048;
|
|
|
cbc.pos = 0;
|
|
|
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
|
- port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
+ global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
if (d == NULL)
|
|
|
return 16;
|
|
|
- if (0 == port)
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
const union MHD_DaemonInfo *dinfo;
|
|
|
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
|
|
|
if (NULL == dinfo || 0 == dinfo->port)
|
|
|
{ MHD_stop_daemon (d); return 32; }
|
|
|
- port = (int)dinfo->port;
|
|
|
+ global_port = (int)dinfo->port;
|
|
|
}
|
|
|
c = curl_easy_init ();
|
|
|
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
|
|
|
- curl_easy_setopt (c, CURLOPT_PORT, (long)port);
|
|
|
+ curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
|
|
|
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
|
|
|
@@ -255,36 +256,36 @@ testMultithreadedPoolGet (int poll_flag)
|
|
|
char buf[2048];
|
|
|
struct CBC cbc;
|
|
|
CURLcode errornum;
|
|
|
- int port;
|
|
|
|
|
|
- if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
- port = 0;
|
|
|
- else
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
- port = 1222;
|
|
|
- if (oneone)
|
|
|
- port += 20;
|
|
|
+ if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
+ {
|
|
|
+ global_port = 1222;
|
|
|
+ if (oneone)
|
|
|
+ global_port += 20;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cbc.buf = buf;
|
|
|
cbc.size = 2048;
|
|
|
cbc.pos = 0;
|
|
|
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
|
- port, NULL, NULL, &ahc_echo, "GET",
|
|
|
+ global_port, NULL, NULL, &ahc_echo, "GET",
|
|
|
MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
|
|
|
if (d == NULL)
|
|
|
return 16;
|
|
|
- if (0 == port)
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
const union MHD_DaemonInfo *dinfo;
|
|
|
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
|
|
|
if (NULL == dinfo || 0 == dinfo->port)
|
|
|
{ MHD_stop_daemon (d); return 32; }
|
|
|
- port = (int)dinfo->port;
|
|
|
+ global_port = (int)dinfo->port;
|
|
|
}
|
|
|
c = curl_easy_init ();
|
|
|
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
|
|
|
- curl_easy_setopt (c, CURLOPT_PORT, (long)port);
|
|
|
+ curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
|
|
|
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
|
|
|
@@ -339,15 +340,15 @@ testExternalGet ()
|
|
|
struct CURLMsg *msg;
|
|
|
time_t start;
|
|
|
struct timeval tv;
|
|
|
- int port;
|
|
|
|
|
|
- if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
- port = 0;
|
|
|
- else
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
- port = 1223;
|
|
|
- if (oneone)
|
|
|
- port += 20;
|
|
|
+ if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
+ {
|
|
|
+ global_port = 1223;
|
|
|
+ if (oneone)
|
|
|
+ global_port += 20;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
multi = NULL;
|
|
|
@@ -355,20 +356,20 @@ testExternalGet ()
|
|
|
cbc.size = 2048;
|
|
|
cbc.pos = 0;
|
|
|
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
|
|
|
- port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
+ global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
if (d == NULL)
|
|
|
return 256;
|
|
|
- if (0 == port)
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
const union MHD_DaemonInfo *dinfo;
|
|
|
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
|
|
|
if (NULL == dinfo || 0 == dinfo->port)
|
|
|
{ MHD_stop_daemon (d); return 32; }
|
|
|
- port = (int)dinfo->port;
|
|
|
+ global_port = (int)dinfo->port;
|
|
|
}
|
|
|
c = curl_easy_init ();
|
|
|
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
|
|
|
- curl_easy_setopt (c, CURLOPT_PORT, (long)port);
|
|
|
+ curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
|
|
|
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
|
|
|
@@ -565,28 +566,28 @@ testStopRace (int poll_flag)
|
|
|
struct sockaddr_in sin;
|
|
|
MHD_socket fd;
|
|
|
struct MHD_Daemon *d;
|
|
|
- int port;
|
|
|
|
|
|
- if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
- port = 0;
|
|
|
- else
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
- port = 1224;
|
|
|
- if (oneone)
|
|
|
- port += 20;
|
|
|
+ if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
+ {
|
|
|
+ global_port = 1224;
|
|
|
+ if (oneone)
|
|
|
+ global_port += 20;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
|
- port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
+ global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
|
if (d == NULL)
|
|
|
return 16;
|
|
|
- if (0 == port)
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
const union MHD_DaemonInfo *dinfo;
|
|
|
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
|
|
|
if (NULL == dinfo || 0 == dinfo->port)
|
|
|
{ MHD_stop_daemon (d); return 32; }
|
|
|
- port = (int)dinfo->port;
|
|
|
+ global_port = (int)dinfo->port;
|
|
|
}
|
|
|
|
|
|
fd = socket (PF_INET, SOCK_STREAM, 0);
|
|
|
@@ -598,7 +599,7 @@ testStopRace (int poll_flag)
|
|
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
sin.sin_family = AF_INET;
|
|
|
- sin.sin_port = htons(port);
|
|
|
+ sin.sin_port = htons(global_port);
|
|
|
sin.sin_addr.s_addr = htonl(0x7f000001);
|
|
|
|
|
|
if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0)
|
|
|
@@ -680,35 +681,35 @@ testEmptyGet (int poll_flag)
|
|
|
struct CBC cbc;
|
|
|
CURLcode errornum;
|
|
|
int excess_found = 0;
|
|
|
- int port;
|
|
|
|
|
|
- if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
- port = 0;
|
|
|
- else
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
- port = 1225;
|
|
|
- if (oneone)
|
|
|
- port += 20;
|
|
|
+ if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
|
|
|
+ {
|
|
|
+ global_port = 1225;
|
|
|
+ if (oneone)
|
|
|
+ global_port += 20;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cbc.buf = buf;
|
|
|
cbc.size = 2048;
|
|
|
cbc.pos = 0;
|
|
|
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
|
- port, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END);
|
|
|
+ global_port, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END);
|
|
|
if (d == NULL)
|
|
|
return 4194304;
|
|
|
- if (0 == port)
|
|
|
+ if (0 == global_port)
|
|
|
{
|
|
|
const union MHD_DaemonInfo *dinfo;
|
|
|
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
|
|
|
if (NULL == dinfo || 0 == dinfo->port)
|
|
|
{ MHD_stop_daemon (d); return 32; }
|
|
|
- port = (int)dinfo->port;
|
|
|
+ global_port = (int)dinfo->port;
|
|
|
}
|
|
|
c = curl_easy_init ();
|
|
|
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
|
|
|
- curl_easy_setopt (c, CURLOPT_PORT, (long)port);
|
|
|
+ curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
|
|
|
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
|
|
|
curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound);
|
|
|
@@ -754,6 +755,7 @@ main (int argc, char *const *argv)
|
|
|
(NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
|
|
|
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
|
|
|
return 2;
|
|
|
+ global_port = 0;
|
|
|
errorCount += testInternalGet (0);
|
|
|
errorCount += testMultithreadedGet (0);
|
|
|
errorCount += testMultithreadedPoolGet (0);
|