aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_start_stop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_start_stop.c')
-rw-r--r--src/microhttpd/test_start_stop.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/microhttpd/test_start_stop.c b/src/microhttpd/test_start_stop.c
new file mode 100644
index 00000000..1dd83575
--- /dev/null
+++ b/src/microhttpd/test_start_stop.c
@@ -0,0 +1,128 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file test_start_stop.c
23 * @brief test for #1901 (start+stop)
24 * @author Christian Grothoff
25 */
26#include "mhd_options.h"
27#include "platform.h"
28#include <microhttpd.h>
29
30#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2
31#undef CPU_COUNT
32#endif
33#if !defined(CPU_COUNT)
34#define CPU_COUNT 2
35#endif
36
37
38static int
39ahc_echo (void *cls,
40 struct MHD_Connection *connection,
41 const char *url,
42 const char *method,
43 const char *version,
44 const char *upload_data, size_t *upload_data_size,
45 void **unused)
46{
47 return MHD_NO;
48}
49
50
51static int
52testInternalGet (int poll_flag)
53{
54 struct MHD_Daemon *d;
55
56 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
57 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
58 if (d == NULL)
59 return 1;
60 MHD_stop_daemon (d);
61 return 0;
62}
63
64static int
65testMultithreadedGet (int poll_flag)
66{
67 struct MHD_Daemon *d;
68
69 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
70 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
71 if (d == NULL)
72 return 2;
73 MHD_stop_daemon (d);
74 return 0;
75}
76
77static int
78testMultithreadedPoolGet (int poll_flag)
79{
80 struct MHD_Daemon *d;
81
82 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
83 0, NULL, NULL, &ahc_echo, "GET",
84 MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
85 if (d == NULL)
86 return 4;
87 MHD_stop_daemon (d);
88 return 0;
89}
90
91static int
92testExternalGet ()
93{
94 struct MHD_Daemon *d;
95
96 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
97 0, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
98 if (d == NULL)
99 return 8;
100 MHD_stop_daemon (d);
101 return 0;
102}
103
104
105int
106main (int argc, char *const *argv)
107{
108 unsigned int errorCount = 0;
109
110 errorCount += testInternalGet (0);
111 errorCount += testMultithreadedGet (0);
112 errorCount += testMultithreadedPoolGet (0);
113 errorCount += testExternalGet ();
114 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL))
115 {
116 errorCount += testInternalGet(MHD_USE_POLL);
117 errorCount += testMultithreadedGet(MHD_USE_POLL);
118 errorCount += testMultithreadedPoolGet(MHD_USE_POLL);
119 }
120 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL))
121 {
122 errorCount += testInternalGet(MHD_USE_EPOLL);
123 errorCount += testMultithreadedPoolGet(MHD_USE_EPOLL);
124 }
125 if (errorCount != 0)
126 fprintf (stderr, "Error (code: %u)\n", errorCount);
127 return errorCount != 0; /* 0 == pass */
128}