aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_daemon.c')
-rw-r--r--src/microhttpd/test_daemon.c123
1 files changed, 92 insertions, 31 deletions
diff --git a/src/microhttpd/test_daemon.c b/src/microhttpd/test_daemon.c
index 169ebb60..75f03d0b 100644
--- a/src/microhttpd/test_daemon.c
+++ b/src/microhttpd/test_daemon.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2007 Christian Grothoff 3 Copyright (C) 2007, 2017 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
@@ -41,23 +41,34 @@ testStartError ()
41 struct MHD_Daemon *d; 41 struct MHD_Daemon *d;
42 42
43 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 0, NULL, NULL, NULL, NULL); 43 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 0, NULL, NULL, NULL, NULL);
44 if (d != NULL) 44 if (NULL != d)
45 {
46 fprintf (stderr,
47 "Succeeded at binding to port 0?\n");
45 return 1; 48 return 1;
49 }
46 return 0; 50 return 0;
47} 51}
48 52
53
49static int 54static int
50apc_nothing (void *cls, const struct sockaddr *addr, socklen_t addrlen) 55apc_nothing (void *cls,
56 const struct sockaddr *addr,
57 socklen_t addrlen)
51{ 58{
52 return MHD_NO; 59 return MHD_NO;
53} 60}
54 61
62
55static int 63static int
56apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) 64apc_all (void *cls,
65 const struct sockaddr *addr,
66 socklen_t addrlen)
57{ 67{
58 return MHD_YES; 68 return MHD_YES;
59} 69}
60 70
71
61static int 72static int
62ahc_nothing (void *cls, 73ahc_nothing (void *cls,
63 struct MHD_Connection *connection, 74 struct MHD_Connection *connection,
@@ -70,6 +81,7 @@ ahc_nothing (void *cls,
70 return MHD_NO; 81 return MHD_NO;
71} 82}
72 83
84
73static int 85static int
74testStartStop () 86testStartStop ()
75{ 87{
@@ -77,14 +89,21 @@ testStartStop ()
77 89
78 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 90 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
79 1080, 91 1080,
80 &apc_nothing, 92 &apc_nothing, NULL,
81 NULL, &ahc_nothing, NULL, MHD_OPTION_END); 93 &ahc_nothing, NULL,
82 if (d == NULL) 94 MHD_OPTION_END);
83 return 2; 95 if (NULL == d)
96 {
97 fprintf (stderr,
98 "Failed to start daemon on port %u\n",
99 1080);
100 exit (77);
101 }
84 MHD_stop_daemon (d); 102 MHD_stop_daemon (d);
85 return 0; 103 return 0;
86} 104}
87 105
106
88static int 107static int
89testExternalRun () 108testExternalRun ()
90{ 109{
@@ -95,23 +114,34 @@ testExternalRun ()
95 114
96 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 115 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
97 1081, 116 1081,
98 &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END); 117 &apc_all, NULL,
99 118 &ahc_nothing, NULL,
100 if (d == NULL) 119 MHD_OPTION_END);
101 return 4; 120
121 if (NULL == d)
122 {
123 fprintf (stderr,
124 "Failed to start daemon on port %u\n",
125 1081);
126 exit (77);
127 }
102 i = 0; 128 i = 0;
103 while (i < 15) 129 while (i < 15)
104 { 130 {
105 maxfd = 0; 131 maxfd = 0;
106 FD_ZERO (&rs); 132 FD_ZERO (&rs);
107 if (MHD_YES != MHD_get_fdset (d, &rs, &rs, &rs, &maxfd)) 133 if (MHD_YES != MHD_get_fdset (d, &rs, &rs, &rs, &maxfd))
108 { 134 {
109 MHD_stop_daemon (d); 135 MHD_stop_daemon (d);
110 return 256; 136 fprintf (stderr,
111 } 137 "Failed in MHD_get_fdset()\n");
138 return 256;
139 }
112 if (MHD_run (d) == MHD_NO) 140 if (MHD_run (d) == MHD_NO)
113 { 141 {
114 MHD_stop_daemon (d); 142 MHD_stop_daemon (d);
143 fprintf (stderr,
144 "Failed in MHD_run()\n");
115 return 8; 145 return 8;
116 } 146 }
117 i++; 147 i++;
@@ -120,48 +150,79 @@ testExternalRun ()
120 return 0; 150 return 0;
121} 151}
122 152
153
123static int 154static int
124testThread () 155testThread ()
125{ 156{
126 struct MHD_Daemon *d; 157 struct MHD_Daemon *d;
158
127 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_INTERNAL_POLLING_THREAD, 159 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_INTERNAL_POLLING_THREAD,
128 1082, 160 1082,
129 &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END); 161 &apc_all, NULL,
130 162 &ahc_nothing, NULL,
131 if (d == NULL) 163 MHD_OPTION_END);
132 return 16; 164
165 if (NULL == d)
166 {
167 fprintf (stderr,
168 "Failed to start daemon on port %u\n",
169 1082);
170 exit (77);
171 }
133 if (MHD_run (d) != MHD_NO) 172 if (MHD_run (d) != MHD_NO)
134 return 32; 173 {
174 fprintf (stderr,
175 "Failed in MHD_run()\n");
176 return 32;
177 }
135 MHD_stop_daemon (d); 178 MHD_stop_daemon (d);
136 return 0; 179 return 0;
137} 180}
138 181
182
139static int 183static int
140testMultithread () 184testMultithread ()
141{ 185{
142 struct MHD_Daemon *d; 186 struct MHD_Daemon *d;
143 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION,
144 1083,
145 &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END);
146 187
147 if (d == NULL) 188 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION,
148 return 64; 189 1083,
190 &apc_all, NULL,
191 &ahc_nothing, NULL,
192 MHD_OPTION_END);
193
194 if (NULL == d)
195 {
196 fprintf (stderr,
197 "Failed to start daemon on port %u\n",
198 1083);
199 exit (77);
200 }
149 if (MHD_run (d) != MHD_NO) 201 if (MHD_run (d) != MHD_NO)
150 return 128; 202 {
203 fprintf (stderr,
204 "Failed in MHD_run()\n");
205 return 128;
206 }
151 MHD_stop_daemon (d); 207 MHD_stop_daemon (d);
152 return 0; 208 return 0;
153} 209}
154 210
211
155int 212int
156main (int argc, char *const *argv) 213main (int argc,
214 char *const *argv)
157{ 215{
158 int errorCount = 0; 216 int errorCount = 0;
217
159 errorCount += testStartError (); 218 errorCount += testStartError ();
160 errorCount += testStartStop (); 219 errorCount += testStartStop ();
161 errorCount += testExternalRun (); 220 errorCount += testExternalRun ();
162 errorCount += testThread (); 221 errorCount += testThread ();
163 errorCount += testMultithread (); 222 errorCount += testMultithread ();
164 if (errorCount != 0) 223 if (0 != errorCount)
165 fprintf (stderr, "Error (code: %u)\n", errorCount); 224 fprintf (stderr,
166 return errorCount != 0; /* 0 == pass */ 225 "Error (code: %u)\n",
226 errorCount);
227 return 0 != errorCount; /* 0 == pass */
167} 228}