|
Packit |
875988 |
/*
|
|
Packit |
875988 |
This file is part of libmicrohttpd
|
|
Packit |
875988 |
Copyright (C) 2011 Christian Grothoff
|
|
Packit |
875988 |
|
|
Packit |
875988 |
libmicrohttpd is free software; you can redistribute it and/or modify
|
|
Packit |
875988 |
it under the terms of the GNU General Public License as published
|
|
Packit |
875988 |
by the Free Software Foundation; either version 2, or (at your
|
|
Packit |
875988 |
option) any later version.
|
|
Packit |
875988 |
|
|
Packit |
875988 |
libmicrohttpd is distributed in the hope that it will be useful, but
|
|
Packit |
875988 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
875988 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
875988 |
General Public License for more details.
|
|
Packit |
875988 |
|
|
Packit |
875988 |
You should have received a copy of the GNU General Public License
|
|
Packit |
875988 |
along with libmicrohttpd; see the file COPYING. If not, write to the
|
|
Packit |
875988 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit |
875988 |
Boston, MA 02110-1301, USA.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/**
|
|
Packit |
875988 |
* @file test_start_stop.c
|
|
Packit |
875988 |
* @brief test for #1901 (start+stop)
|
|
Packit |
875988 |
* @author Christian Grothoff
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
#include "mhd_options.h"
|
|
Packit |
875988 |
#include "platform.h"
|
|
Packit |
875988 |
#include <microhttpd.h>
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2
|
|
Packit |
875988 |
#undef CPU_COUNT
|
|
Packit |
875988 |
#endif
|
|
Packit |
875988 |
#if !defined(CPU_COUNT)
|
|
Packit |
875988 |
#define CPU_COUNT 2
|
|
Packit |
875988 |
#endif
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
ahc_echo (void *cls,
|
|
Packit |
875988 |
struct MHD_Connection *connection,
|
|
Packit |
875988 |
const char *url,
|
|
Packit |
875988 |
const char *method,
|
|
Packit |
875988 |
const char *version,
|
|
Packit |
875988 |
const char *upload_data, size_t *upload_data_size,
|
|
Packit |
875988 |
void **unused)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
(void)cls;(void)connection;(void)url; /* Unused. Silent compiler warning. */
|
|
Packit |
875988 |
(void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */
|
|
Packit |
875988 |
(void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */
|
|
Packit |
875988 |
|
|
Packit |
875988 |
return MHD_NO;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
testInternalGet (int poll_flag)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
struct MHD_Daemon *d;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
Packit |
875988 |
0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
Packit |
875988 |
if (d == NULL)
|
|
Packit |
875988 |
return 1;
|
|
Packit |
875988 |
MHD_stop_daemon (d);
|
|
Packit |
875988 |
return 0;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
testMultithreadedGet (int poll_flag)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
struct MHD_Daemon *d;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
Packit |
875988 |
0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
Packit |
875988 |
if (d == NULL)
|
|
Packit |
875988 |
return 2;
|
|
Packit |
875988 |
MHD_stop_daemon (d);
|
|
Packit |
875988 |
return 0;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
testMultithreadedPoolGet (int poll_flag)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
struct MHD_Daemon *d;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
|
|
Packit |
875988 |
0, NULL, NULL, &ahc_echo, "GET",
|
|
Packit |
875988 |
MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
|
|
Packit |
875988 |
if (d == NULL)
|
|
Packit |
875988 |
return 4;
|
|
Packit |
875988 |
MHD_stop_daemon (d);
|
|
Packit |
875988 |
return 0;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
testExternalGet ()
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
struct MHD_Daemon *d;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
|
|
Packit |
875988 |
0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
|
|
Packit |
875988 |
if (d == NULL)
|
|
Packit |
875988 |
return 8;
|
|
Packit |
875988 |
MHD_stop_daemon (d);
|
|
Packit |
875988 |
return 0;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
int
|
|
Packit |
875988 |
main (int argc, char *const *argv)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
unsigned int errorCount = 0;
|
|
Packit |
875988 |
(void)argc; (void)argv; /* Unused. Silent compiler warning. */
|
|
Packit |
875988 |
|
|
Packit |
875988 |
errorCount += testInternalGet (0);
|
|
Packit |
875988 |
errorCount += testMultithreadedGet (0);
|
|
Packit |
875988 |
errorCount += testMultithreadedPoolGet (0);
|
|
Packit |
875988 |
errorCount += testExternalGet ();
|
|
Packit |
875988 |
if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL))
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
errorCount += testInternalGet(MHD_USE_POLL);
|
|
Packit |
875988 |
errorCount += testMultithreadedGet(MHD_USE_POLL);
|
|
Packit |
875988 |
errorCount += testMultithreadedPoolGet(MHD_USE_POLL);
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
errorCount += testInternalGet(MHD_USE_EPOLL);
|
|
Packit |
875988 |
errorCount += testMultithreadedPoolGet(MHD_USE_EPOLL);
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
if (errorCount != 0)
|
|
Packit |
875988 |
fprintf (stderr, "Error (code: %u)\n", errorCount);
|
|
Packit |
875988 |
return errorCount != 0; /* 0 == pass */
|
|
Packit |
875988 |
}
|