aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-13 20:37:48 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-13 20:37:48 +0200
commiteb8cc7eeff1855d3d2bad39562f45c39406c6c0e (patch)
tree21010fe71a11ca9e3ccb0d05405e4eeaf3f0fcff
parent5565cb954c8a4303b697271fa8620230baa64eaa (diff)
downloadlibmicrohttpd-eb8cc7eeff1855d3d2bad39562f45c39406c6c0e.tar.gz
libmicrohttpd-eb8cc7eeff1855d3d2bad39562f45c39406c6c0e.zip
make it explicit we want to ignore return value from write() in test
-rw-r--r--src/microhttpd/test_upgrade_large.c638
1 files changed, 327 insertions, 311 deletions
diff --git a/src/microhttpd/test_upgrade_large.c b/src/microhttpd/test_upgrade_large.c
index f3318e35..3a3a2f0c 100644
--- a/src/microhttpd/test_upgrade_large.c
+++ b/src/microhttpd/test_upgrade_large.c
@@ -51,9 +51,11 @@
51 51
52#include "test_helpers.h" 52#include "test_helpers.h"
53 53
54#define LARGE_STRING "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello" 54#define LARGE_STRING \
55 "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello"
55 56
56#define LARGE_REPLY_STRING "WorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorld" 57#define LARGE_REPLY_STRING \
58 "WorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorld"
57 59
58#ifdef HTTPS_SUPPORT 60#ifdef HTTPS_SUPPORT
59#include <gnutls/gnutls.h> 61#include <gnutls/gnutls.h>
@@ -67,7 +69,7 @@
67 69
68static int verbose = 0; 70static int verbose = 0;
69 71
70static int kicker[2] = {-1, -1} ; 72static int kicker[2] = {-1, -1};
71 73
72enum tls_tool 74enum tls_tool
73{ 75{
@@ -90,7 +92,7 @@ enum tls_tool use_tls_tool;
90 */ 92 */
91static pid_t 93static pid_t
92gnutlscli_connect (int *sock, 94gnutlscli_connect (int *sock,
93 uint16_t port) 95 uint16_t port)
94{ 96{
95 pid_t chld; 97 pid_t chld;
96 int sp[2]; 98 int sp[2];
@@ -103,11 +105,11 @@ gnutlscli_connect (int *sock,
103 return -1; 105 return -1;
104 chld = fork (); 106 chld = fork ();
105 if (0 != chld) 107 if (0 != chld)
106 { 108 {
107 *sock = sp[1]; 109 *sock = sp[1];
108 MHD_socket_close_chk_ (sp[0]); 110 MHD_socket_close_chk_ (sp[0]);
109 return chld; 111 return chld;
110 } 112 }
111 MHD_socket_close_chk_ (sp[1]); 113 MHD_socket_close_chk_ (sp[1]);
112 (void) close (0); 114 (void) close (0);
113 (void) close (1); 115 (void) close (1);
@@ -117,34 +119,34 @@ gnutlscli_connect (int *sock,
117 abort (); 119 abort ();
118 MHD_socket_close_chk_ (sp[0]); 120 MHD_socket_close_chk_ (sp[0]);
119 if (TLS_CLI_GNUTLS == use_tls_tool) 121 if (TLS_CLI_GNUTLS == use_tls_tool)
120 { 122 {
121 snprintf (destination, 123 snprintf (destination,
122 sizeof(destination), 124 sizeof(destination),
123 "%u", 125 "%u",
124 (unsigned int) port); 126 (unsigned int) port);
125 execlp ("gnutls-cli", 127 execlp ("gnutls-cli",
126 "gnutls-cli", 128 "gnutls-cli",
127 "--insecure", 129 "--insecure",
128 "-p", 130 "-p",
129 destination, 131 destination,
130 "127.0.0.1", 132 "127.0.0.1",
131 (char *) NULL); 133 (char *) NULL);
132 } 134 }
133 else if (TLS_CLI_OPENSSL == use_tls_tool) 135 else if (TLS_CLI_OPENSSL == use_tls_tool)
134 { 136 {
135 snprintf (destination, 137 snprintf (destination,
136 sizeof(destination), 138 sizeof(destination),
137 "127.0.0.1:%u", 139 "127.0.0.1:%u",
138 (unsigned int) port); 140 (unsigned int) port);
139 execlp ("openssl", 141 execlp ("openssl",
140 "openssl", 142 "openssl",
141 "s_client", 143 "s_client",
142 "-connect", 144 "-connect",
143 destination, 145 destination,
144 "-verify", 146 "-verify",
145 "1", 147 "1",
146 (char *) NULL); 148 (char *) NULL);
147 } 149 }
148 _exit (1); 150 _exit (1);
149} 151}
150#endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ 152#endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */
@@ -200,16 +202,16 @@ struct wr_socket
200 * @return created socket on success, NULL otherwise 202 * @return created socket on success, NULL otherwise
201 */ 203 */
202static struct wr_socket * 204static struct wr_socket *
203wr_create_plain_sckt(void) 205wr_create_plain_sckt (void)
204{ 206{
205 struct wr_socket *s = malloc(sizeof(struct wr_socket)); 207 struct wr_socket *s = malloc (sizeof(struct wr_socket));
206 if (NULL == s) 208 if (NULL == s)
207 return NULL; 209 return NULL;
208 s->t = wr_plain; 210 s->t = wr_plain;
209 s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); 211 s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
210 if (MHD_INVALID_SOCKET != s->fd) 212 if (MHD_INVALID_SOCKET != s->fd)
211 return s; 213 return s;
212 free(s); 214 free (s);
213 return NULL; 215 return NULL;
214} 216}
215 217
@@ -219,40 +221,44 @@ wr_create_plain_sckt(void)
219 * @return created socket on success, NULL otherwise 221 * @return created socket on success, NULL otherwise
220 */ 222 */
221static struct wr_socket * 223static struct wr_socket *
222wr_create_tls_sckt(void) 224wr_create_tls_sckt (void)
223{ 225{
224#ifdef HTTPS_SUPPORT 226#ifdef HTTPS_SUPPORT
225 struct wr_socket *s = malloc(sizeof(struct wr_socket)); 227 struct wr_socket *s = malloc (sizeof(struct wr_socket));
226 if (NULL == s) 228 if (NULL == s)
227 return NULL; 229 return NULL;
228 s->t = wr_tls; 230 s->t = wr_tls;
229 s->tls_connected = 0; 231 s->tls_connected = 0;
230 s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); 232 s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
231 if (MHD_INVALID_SOCKET != s->fd) 233 if (MHD_INVALID_SOCKET != s->fd)
234 {
235 if (GNUTLS_E_SUCCESS == gnutls_init (&(s->tls_s), GNUTLS_CLIENT))
232 { 236 {
233 if (GNUTLS_E_SUCCESS == gnutls_init (&(s->tls_s), GNUTLS_CLIENT)) 237 if (GNUTLS_E_SUCCESS == gnutls_set_default_priority (s->tls_s))
238 {
239 if (GNUTLS_E_SUCCESS == gnutls_certificate_allocate_credentials (
240 &(s->tls_crd)))
234 { 241 {
235 if (GNUTLS_E_SUCCESS == gnutls_set_default_priority (s->tls_s)) 242 if (GNUTLS_E_SUCCESS == gnutls_credentials_set (s->tls_s,
236 { 243 GNUTLS_CRD_CERTIFICATE,
237 if (GNUTLS_E_SUCCESS == gnutls_certificate_allocate_credentials (&(s->tls_crd))) 244 s->tls_crd))
238 { 245 {
239 if (GNUTLS_E_SUCCESS == gnutls_credentials_set (s->tls_s, GNUTLS_CRD_CERTIFICATE, s->tls_crd)) 246#if GNUTLS_VERSION_NUMBER + 0 >= 0x030109
240 { 247 gnutls_transport_set_int (s->tls_s, (int) (s->fd));
241#if GNUTLS_VERSION_NUMBER+0 >= 0x030109
242 gnutls_transport_set_int (s->tls_s, (int)(s->fd));
243#else /* GnuTLS before 3.1.9 */ 248#else /* GnuTLS before 3.1.9 */
244 gnutls_transport_set_ptr (s->tls_s, (gnutls_transport_ptr_t)(intptr_t)(s->fd)); 249 gnutls_transport_set_ptr (s->tls_s,
250 (gnutls_transport_ptr_t) (intptr_t) (s->fd));
245#endif /* GnuTLS before 3.1.9 */ 251#endif /* GnuTLS before 3.1.9 */
246 return s; 252 return s;
247 } 253 }
248 gnutls_certificate_free_credentials (s->tls_crd); 254 gnutls_certificate_free_credentials (s->tls_crd);
249 }
250 }
251 gnutls_deinit (s->tls_s);
252 } 255 }
253 (void)MHD_socket_close_ (s->fd); 256 }
257 gnutls_deinit (s->tls_s);
254 } 258 }
255 free(s); 259 (void) MHD_socket_close_ (s->fd);
260 }
261 free (s);
256#endif /* HTTPS_SUPPORT */ 262#endif /* HTTPS_SUPPORT */
257 return NULL; 263 return NULL;
258} 264}
@@ -265,9 +271,9 @@ wr_create_tls_sckt(void)
265 * @return created socket on success, NULL otherwise 271 * @return created socket on success, NULL otherwise
266 */ 272 */
267static struct wr_socket * 273static struct wr_socket *
268wr_create_from_plain_sckt(MHD_socket plain_sk) 274wr_create_from_plain_sckt (MHD_socket plain_sk)
269{ 275{
270 struct wr_socket *s = malloc(sizeof(struct wr_socket)); 276 struct wr_socket *s = malloc (sizeof(struct wr_socket));
271 277
272 if (NULL == s) 278 if (NULL == s)
273 return NULL; 279 return NULL;
@@ -285,9 +291,9 @@ wr_create_from_plain_sckt(MHD_socket plain_sk)
285 * @return zero on success, -1 otherwise. 291 * @return zero on success, -1 otherwise.
286 */ 292 */
287static int 293static int
288wr_connect(struct wr_socket *s, 294wr_connect (struct wr_socket *s,
289 const struct sockaddr *addr, 295 const struct sockaddr *addr,
290 int length) 296 int length)
291{ 297{
292 if (0 != connect (s->fd, addr, length)) 298 if (0 != connect (s->fd, addr, length))
293 return -1; 299 return -1;
@@ -295,15 +301,15 @@ wr_connect(struct wr_socket *s,
295 return 0; 301 return 0;
296#ifdef HTTPS_SUPPORT 302#ifdef HTTPS_SUPPORT
297 if (wr_tls == s->t) 303 if (wr_tls == s->t)
298 { 304 {
299 /* Do not try handshake here as 305 /* Do not try handshake here as
300 * it require processing on MHD side and 306 * it require processing on MHD side and
301 * when testing with "external" polling, 307 * when testing with "external" polling,
302 * test will call MHD processing only 308 * test will call MHD processing only
303 * after return from wr_connect(). */ 309 * after return from wr_connect(). */
304 s->tls_connected = 0; 310 s->tls_connected = 0;
305 return 0; 311 return 0;
306 } 312 }
307#endif /* HTTPS_SUPPORT */ 313#endif /* HTTPS_SUPPORT */
308 return -1; 314 return -1;
309} 315}
@@ -311,7 +317,7 @@ wr_connect(struct wr_socket *s,
311#ifdef HTTPS_SUPPORT 317#ifdef HTTPS_SUPPORT
312/* Only to be called from wr_send() and wr_recv() ! */ 318/* Only to be called from wr_send() and wr_recv() ! */
313static bool 319static bool
314wr_handshake(struct wr_socket *s) 320wr_handshake (struct wr_socket *s)
315{ 321{
316 int res = gnutls_handshake (s->tls_s); 322 int res = gnutls_handshake (s->tls_s);
317 if (GNUTLS_E_SUCCESS == res) 323 if (GNUTLS_E_SUCCESS == res)
@@ -340,22 +346,22 @@ wr_send (struct wr_socket *s,
340 size_t len) 346 size_t len)
341{ 347{
342 if (wr_plain == s->t) 348 if (wr_plain == s->t)
343 return MHD_send_(s->fd, buf, len); 349 return MHD_send_ (s->fd, buf, len);
344#ifdef HTTPS_SUPPORT 350#ifdef HTTPS_SUPPORT
345 if (wr_tls == s->t) 351 if (wr_tls == s->t)
346 { 352 {
347 ssize_t ret; 353 ssize_t ret;
348 if (!s->tls_connected && !wr_handshake (s)) 354 if (! s->tls_connected && ! wr_handshake (s))
349 return -1; 355 return -1;
350 356
351 ret = gnutls_record_send (s->tls_s, buf, len); 357 ret = gnutls_record_send (s->tls_s, buf, len);
352 if (ret > 0) 358 if (ret > 0)
353 return ret; 359 return ret;
354 if (GNUTLS_E_AGAIN == ret) 360 if (GNUTLS_E_AGAIN == ret)
355 MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); 361 MHD_socket_set_error_ (MHD_SCKT_EAGAIN_);
356 else 362 else
357 MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ 363 MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */
358 } 364 }
359#endif /* HTTPS_SUPPORT */ 365#endif /* HTTPS_SUPPORT */
360 return -1; 366 return -1;
361} 367}
@@ -379,19 +385,19 @@ wr_recv (struct wr_socket *s,
379 return MHD_recv_ (s->fd, buf, len); 385 return MHD_recv_ (s->fd, buf, len);
380#ifdef HTTPS_SUPPORT 386#ifdef HTTPS_SUPPORT
381 if (wr_tls == s->t) 387 if (wr_tls == s->t)
382 { 388 {
383 ssize_t ret; 389 ssize_t ret;
384 if (!s->tls_connected && !wr_handshake (s)) 390 if (! s->tls_connected && ! wr_handshake (s))
385 return -1; 391 return -1;
386 392
387 ret = gnutls_record_recv (s->tls_s, buf, len); 393 ret = gnutls_record_recv (s->tls_s, buf, len);
388 if (ret > 0) 394 if (ret > 0)
389 return ret; 395 return ret;
390 if (GNUTLS_E_AGAIN == ret) 396 if (GNUTLS_E_AGAIN == ret)
391 MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); 397 MHD_socket_set_error_ (MHD_SCKT_EAGAIN_);
392 else 398 else
393 MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ 399 MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */
394 } 400 }
395#endif /* HTTPS_SUPPORT */ 401#endif /* HTTPS_SUPPORT */
396 return -1; 402 return -1;
397} 403}
@@ -405,13 +411,13 @@ wr_recv (struct wr_socket *s,
405static int 411static int
406wr_close (struct wr_socket *s) 412wr_close (struct wr_socket *s)
407{ 413{
408 int ret = (MHD_socket_close_(s->fd)) ? 0 : -1; 414 int ret = (MHD_socket_close_ (s->fd)) ? 0 : -1;
409#ifdef HTTPS_SUPPORT 415#ifdef HTTPS_SUPPORT
410 if (wr_tls == s->t) 416 if (wr_tls == s->t)
411 { 417 {
412 gnutls_deinit (s->tls_s); 418 gnutls_deinit (s->tls_s);
413 gnutls_certificate_free_credentials (s->tls_crd); 419 gnutls_certificate_free_credentials (s->tls_crd);
414 } 420 }
415#endif /* HTTPS_SUPPORT */ 421#endif /* HTTPS_SUPPORT */
416 free (s); 422 free (s);
417 return ret; 423 return ret;
@@ -455,7 +461,7 @@ notify_completed_cb (void *cls,
455 void **con_cls, 461 void **con_cls,
456 enum MHD_RequestTerminationCode toe) 462 enum MHD_RequestTerminationCode toe)
457{ 463{
458 pthread_t* ppth = *con_cls; 464 pthread_t*ppth = *con_cls;
459 465
460 (void) cls; 466 (void) cls;
461 (void) connection; /* Unused. Silent compiler warning. */ 467 (void) connection; /* Unused. Silent compiler warning. */
@@ -463,7 +469,7 @@ notify_completed_cb (void *cls,
463 (toe != MHD_REQUEST_TERMINATED_CLIENT_ABORT) && 469 (toe != MHD_REQUEST_TERMINATED_CLIENT_ABORT) &&
464 (toe != MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN) ) 470 (toe != MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN) )
465 abort (); 471 abort ();
466 if (! pthread_equal (**((pthread_t**)con_cls), 472 if (! pthread_equal (**((pthread_t**) con_cls),
467 pthread_self ())) 473 pthread_self ()))
468 abort (); 474 abort ();
469 if (NULL != ppth) 475 if (NULL != ppth)
@@ -494,7 +500,7 @@ log_cb (void *cls,
494 abort (); 500 abort ();
495 ppth = malloc (sizeof (pthread_t)); 501 ppth = malloc (sizeof (pthread_t));
496 if (NULL == ppth) 502 if (NULL == ppth)
497 abort(); 503 abort ();
498 *ppth = pthread_self (); 504 *ppth = pthread_self ();
499 return (void *) ppth; 505 return (void *) ppth;
500} 506}
@@ -580,7 +586,7 @@ kick_select ()
580{ 586{
581 if (-1 != kicker[1]) 587 if (-1 != kicker[1])
582 { 588 {
583 write (kicker[1], "K", 1); 589 (void) write (kicker[1], "K", 1);
584 } 590 }
585} 591}
586 592
@@ -595,21 +601,21 @@ send_all (struct wr_socket *sock,
595 601
596 make_blocking (wr_fd (sock)); 602 make_blocking (wr_fd (sock));
597 for (off = 0; off < len; off += ret) 603 for (off = 0; off < len; off += ret)
604 {
605 ret = wr_send (sock,
606 &text[off],
607 len - off);
608 kick_select ();
609 if (0 > ret)
598 { 610 {
599 ret = wr_send (sock, 611 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
600 &text[off], 612 {
601 len - off); 613 ret = 0;
602 kick_select (); 614 continue;
603 if (0 > ret) 615 }
604 { 616 abort ();
605 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
606 {
607 ret = 0;
608 continue;
609 }
610 abort ();
611 }
612 } 617 }
618 }
613} 619}
614 620
615 621
@@ -629,37 +635,37 @@ recv_hdr (struct wr_socket *sock)
629 next = '\r'; 635 next = '\r';
630 i = 0; 636 i = 0;
631 while (i < 4) 637 while (i < 4)
638 {
639 ret = wr_recv (sock,
640 &c,
641 1);
642 kick_select ();
643 if (0 > ret)
632 { 644 {
633 ret = wr_recv (sock, 645 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
634 &c,
635 1);
636 kick_select ();
637 if (0 > ret)
638 {
639 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
640 continue;
641 abort ();
642 }
643 if (0 == ret)
644 continue; 646 continue;
645 if (c == next) 647 abort ();
646 { 648 }
647 i++; 649 if (0 == ret)
648 if (next == '\r') 650 continue;
649 next = '\n'; 651 if (c == next)
650 else 652 {
651 next = '\r'; 653 i++;
652 continue; 654 if (next == '\r')
653 } 655 next = '\n';
654 if (c == '\r') 656 else
655 { 657 next = '\r';
656 i = 1; 658 continue;
657 next = '\n';
658 continue;
659 }
660 i = 0;
661 next = '\r';
662 } 659 }
660 if (c == '\r')
661 {
662 i = 1;
663 next = '\n';
664 continue;
665 }
666 i = 0;
667 next = '\r';
668 }
663} 669}
664 670
665 671
@@ -674,22 +680,22 @@ recv_all (struct wr_socket *sock,
674 680
675 make_blocking (wr_fd (sock)); 681 make_blocking (wr_fd (sock));
676 for (off = 0; off < len; off += ret) 682 for (off = 0; off < len; off += ret)
683 {
684 ret = wr_recv (sock,
685 &buf[off],
686 len - off);
687 if (0 > ret)
677 { 688 {
678 ret = wr_recv (sock, 689 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
679 &buf[off], 690 {
680 len - off); 691 ret = 0;
681 if (0 > ret) 692 continue;
682 { 693 }
683 if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) 694 abort ();
684 {
685 ret = 0;
686 continue;
687 }
688 abort ();
689 }
690 } 695 }
696 }
691 if (0 != strncmp (text, buf, len)) 697 if (0 != strncmp (text, buf, len))
692 abort(); 698 abort ();
693} 699}
694 700
695 701
@@ -875,7 +881,7 @@ ahc_upgrade (void *cls,
875 881
876 if (NULL == *con_cls) 882 if (NULL == *con_cls)
877 abort (); 883 abort ();
878 if (! pthread_equal (**((pthread_t**)con_cls), pthread_self ())) 884 if (! pthread_equal (**((pthread_t**) con_cls), pthread_self ()))
879 abort (); 885 abort ();
880 resp = MHD_create_response_for_upgrade (&upgrade_cb, 886 resp = MHD_create_response_for_upgrade (&upgrade_cb,
881 NULL); 887 NULL);
@@ -909,40 +915,40 @@ run_mhd_select_loop (struct MHD_Daemon *daemon)
909 if (0 != pipe (kicker)) 915 if (0 != pipe (kicker))
910 abort (); 916 abort ();
911 while (! done) 917 while (! done)
912 { 918 {
913 FD_ZERO (&rs); 919 FD_ZERO (&rs);
914 FD_ZERO (&ws); 920 FD_ZERO (&ws);
915 FD_ZERO (&es); 921 FD_ZERO (&es);
916 max_fd = -1; 922 max_fd = -1;
923 to = 1000;
924
925 FD_SET (kicker[0], &rs);
926 if (MHD_YES !=
927 MHD_get_fdset (daemon,
928 &rs,
929 &ws,
930 &es,
931 &max_fd))
932 abort ();
933 (void) MHD_get_timeout (daemon,
934 &to);
935 if (1000 < to)
917 to = 1000; 936 to = 1000;
918 937 tv.tv_sec = to / 1000;
919 FD_SET (kicker[0], &rs); 938 tv.tv_usec = 1000 * (to % 1000);
920 if (MHD_YES != 939 if (0 > MHD_SYS_select_ (max_fd + 1,
921 MHD_get_fdset (daemon, 940 &rs,
941 &ws,
942 &es,
943 &tv))
944 abort ();
945 if (FD_ISSET (kicker[0], &rs))
946 (void) read (kicker[0], drain, sizeof (drain));
947 MHD_run_from_select (daemon,
922 &rs, 948 &rs,
923 &ws, 949 &ws,
924 &es, 950 &es);
925 &max_fd)) 951 }
926 abort ();
927 (void) MHD_get_timeout (daemon,
928 &to);
929 if (1000 < to)
930 to = 1000;
931 tv.tv_sec = to / 1000;
932 tv.tv_usec = 1000 * (to % 1000);
933 if (0 > MHD_SYS_select_ (max_fd + 1,
934 &rs,
935 &ws,
936 &es,
937 &tv))
938 abort ();
939 if (FD_ISSET (kicker[0], &rs))
940 (void) read (kicker[0], drain, sizeof (drain));
941 MHD_run_from_select (daemon,
942 &rs,
943 &ws,
944 &es);
945 }
946 close (kicker[0]); 952 close (kicker[0]);
947 close (kicker[1]); 953 close (kicker[1]);
948 kicker[0] = -1; 954 kicker[0] = -1;
@@ -959,7 +965,7 @@ run_mhd_select_loop (struct MHD_Daemon *daemon)
959static void 965static void
960run_mhd_poll_loop (struct MHD_Daemon *daemon) 966run_mhd_poll_loop (struct MHD_Daemon *daemon)
961{ 967{
962 (void)daemon; /* Unused. Silent compiler warning. */ 968 (void) daemon; /* Unused. Silent compiler warning. */
963 abort (); /* currently not implementable with existing MHD API */ 969 abort (); /* currently not implementable with existing MHD API */
964} 970}
965#endif /* HAVE_POLL */ 971#endif /* HAVE_POLL */
@@ -988,30 +994,30 @@ run_mhd_epoll_loop (struct MHD_Daemon *daemon)
988 if (0 != pipe (kicker)) 994 if (0 != pipe (kicker))
989 abort (); 995 abort ();
990 while (! done) 996 while (! done)
991 { 997 {
992 FD_ZERO (&rs); 998 FD_ZERO (&rs);
999 to = 1000;
1000 FD_SET (kicker[0], &rs);
1001 FD_SET (ep, &rs);
1002 (void) MHD_get_timeout (daemon,
1003 &to);
1004 if (1000 < to)
993 to = 1000; 1005 to = 1000;
994 FD_SET (kicker[0], &rs); 1006 tv.tv_sec = to / 1000;
995 FD_SET (ep, &rs); 1007 tv.tv_usec = 1000 * (to % 1000);
996 (void) MHD_get_timeout (daemon, 1008 ret = select (ep + 1,
997 &to); 1009 &rs,
998 if (1000 < to) 1010 NULL,
999 to = 1000; 1011 NULL,
1000 tv.tv_sec = to / 1000; 1012 &tv);
1001 tv.tv_usec = 1000 * (to % 1000); 1013 if ( (-1 == ret) &&
1002 ret = select (ep + 1, 1014 (EAGAIN != errno) &&
1003 &rs, 1015 (EINTR != errno) )
1004 NULL, 1016 abort ();
1005 NULL, 1017 if (FD_ISSET (kicker[0], &rs))
1006 &tv); 1018 (void) read (kicker[0], drain, sizeof (drain));
1007 if ( (-1 == ret) && 1019 MHD_run (daemon);
1008 (EAGAIN != errno) && 1020 }
1009 (EINTR != errno) )
1010 abort ();
1011 if (FD_ISSET (kicker[0], &rs))
1012 (void) read (kicker[0], drain, sizeof (drain));
1013 MHD_run (daemon);
1014 }
1015 close (kicker[0]); 1021 close (kicker[0]);
1016 close (kicker[1]); 1022 close (kicker[1]);
1017 kicker[0] = -1; 1023 kicker[0] = -1;
@@ -1068,27 +1074,34 @@ test_upgrade (int flags,
1068 1074
1069 if (! test_tls) 1075 if (! test_tls)
1070 d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE, 1076 d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE,
1071 MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT) ? 1077 MHD_is_feature_supported (
1078 MHD_FEATURE_AUTODETECT_BIND_PORT) ?
1072 0 : 1090, 1079 0 : 1090,
1073 NULL, NULL, 1080 NULL, NULL,
1074 &ahc_upgrade, NULL, 1081 &ahc_upgrade, NULL,
1075 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) 512, 1082 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) 512,
1076 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 1083 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
1077 MHD_OPTION_NOTIFY_COMPLETED, &notify_completed_cb, NULL, 1084 MHD_OPTION_NOTIFY_COMPLETED, &notify_completed_cb,
1078 MHD_OPTION_NOTIFY_CONNECTION, &notify_connection_cb, NULL, 1085 NULL,
1086 MHD_OPTION_NOTIFY_CONNECTION, &notify_connection_cb,
1087 NULL,
1079 MHD_OPTION_THREAD_POOL_SIZE, pool, 1088 MHD_OPTION_THREAD_POOL_SIZE, pool,
1080 MHD_OPTION_END); 1089 MHD_OPTION_END);
1081#ifdef HTTPS_SUPPORT 1090#ifdef HTTPS_SUPPORT
1082 else 1091 else
1083 d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE | MHD_USE_TLS, 1092 d = MHD_start_daemon (flags | MHD_USE_ERROR_LOG | MHD_ALLOW_UPGRADE
1084 MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT) ? 1093 | MHD_USE_TLS,
1085 0 : 1090, 1094 MHD_is_feature_supported (
1095 MHD_FEATURE_AUTODETECT_BIND_PORT) ?
1096 0 : 1090,
1086 NULL, NULL, 1097 NULL, NULL,
1087 &ahc_upgrade, NULL, 1098 &ahc_upgrade, NULL,
1088 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) 512, 1099 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) 512,
1089 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, 1100 MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL,
1090 MHD_OPTION_NOTIFY_COMPLETED, &notify_completed_cb, NULL, 1101 MHD_OPTION_NOTIFY_COMPLETED, &notify_completed_cb,
1091 MHD_OPTION_NOTIFY_CONNECTION, &notify_connection_cb, NULL, 1102 NULL,
1103 MHD_OPTION_NOTIFY_CONNECTION, &notify_connection_cb,
1104 NULL,
1092 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, 1105 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
1093 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, 1106 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
1094 MHD_OPTION_THREAD_POOL_SIZE, pool, 1107 MHD_OPTION_THREAD_POOL_SIZE, pool,
@@ -1105,43 +1118,43 @@ test_upgrade (int flags,
1105 if ( (NULL == dinfo) || 1118 if ( (NULL == dinfo) ||
1106 (0 == dinfo->port) ) 1119 (0 == dinfo->port) )
1107 abort (); 1120 abort ();
1108 if (!test_tls || TLS_LIB_GNUTLS == use_tls_tool) 1121 if (! test_tls ||(TLS_LIB_GNUTLS == use_tls_tool))
1109 { 1122 {
1110 sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt (); 1123 sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt ();
1111 if (NULL == sock) 1124 if (NULL == sock)
1112 abort (); 1125 abort ();
1113 sa.sin_family = AF_INET; 1126 sa.sin_family = AF_INET;
1114 sa.sin_port = htons (dinfo->port); 1127 sa.sin_port = htons (dinfo->port);
1115 sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 1128 sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
1116 if (0 != wr_connect (sock, 1129 if (0 != wr_connect (sock,
1117 (struct sockaddr *) &sa, 1130 (struct sockaddr *) &sa,
1118 sizeof (sa))) 1131 sizeof (sa)))
1119 abort (); 1132 abort ();
1120 } 1133 }
1121 else 1134 else
1122 { 1135 {
1123#if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) 1136#if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID)
1124 MHD_socket tls_fork_sock; 1137 MHD_socket tls_fork_sock;
1125 uint16_t port; 1138 uint16_t port;
1126 1139
1127 /* make address sanitizer happy */ 1140 /* make address sanitizer happy */
1128 memcpy (&port, 1141 memcpy (&port,
1129 dinfo /* ->port */, 1142 dinfo /* ->port */,
1130 sizeof (port)); 1143 sizeof (port));
1131 if (-1 == (pid = gnutlscli_connect (&tls_fork_sock, 1144 if (-1 == (pid = gnutlscli_connect (&tls_fork_sock,
1132 port))) 1145 port)))
1133 { 1146 {
1134 MHD_stop_daemon (d); 1147 MHD_stop_daemon (d);
1135 return 4; 1148 return 4;
1136 } 1149 }
1137 1150
1138 sock = wr_create_from_plain_sckt (tls_fork_sock); 1151 sock = wr_create_from_plain_sckt (tls_fork_sock);
1139 if (NULL == sock) 1152 if (NULL == sock)
1140 abort ();
1141#else /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */
1142 abort (); 1153 abort ();
1154#else /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */
1155 abort ();
1143#endif /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ 1156#endif /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */
1144 } 1157 }
1145 1158
1146 if (0 != pthread_create (&pt_client, 1159 if (0 != pthread_create (&pt_client,
1147 NULL, 1160 NULL,
@@ -1149,21 +1162,21 @@ test_upgrade (int flags,
1149 sock)) 1162 sock))
1150 abort (); 1163 abort ();
1151 if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) 1164 if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) )
1152 { 1165 {
1153 enum MHD_FLAG flags; 1166 enum MHD_FLAG flags;
1154 1167
1155 /* make address sanitizer happy */ 1168 /* make address sanitizer happy */
1156 memcpy (&flags, 1169 memcpy (&flags,
1157 real_flags /* ->flags */, 1170 real_flags /* ->flags */,
1158 sizeof (flags)); 1171 sizeof (flags));
1159 run_mhd_loop (d, flags); 1172 run_mhd_loop (d, flags);
1160 } 1173 }
1161 pthread_join (pt_client, 1174 pthread_join (pt_client,
1162 NULL); 1175 NULL);
1163 pthread_join (pt, 1176 pthread_join (pt,
1164 NULL); 1177 NULL);
1165#if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) 1178#if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID)
1166 if (test_tls && TLS_LIB_GNUTLS != use_tls_tool) 1179 if (test_tls &&(TLS_LIB_GNUTLS != use_tls_tool))
1167 waitpid (pid, NULL, 0); 1180 waitpid (pid, NULL, 0);
1168#endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ 1181#endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */
1169 MHD_stop_daemon (d); 1182 MHD_stop_daemon (d);
@@ -1179,56 +1192,56 @@ main (int argc,
1179 int res; 1192 int res;
1180 1193
1181 use_tls_tool = TLS_CLI_NO_TOOL; 1194 use_tls_tool = TLS_CLI_NO_TOOL;
1182 test_tls = has_in_name(argv[0], "_tls"); 1195 test_tls = has_in_name (argv[0], "_tls");
1183 1196
1184 verbose = 1; 1197 verbose = 1;
1185 if (has_param(argc, argv, "-q") || 1198 if (has_param (argc, argv, "-q") ||
1186 has_param(argc, argv, "--quiet")) 1199 has_param (argc, argv, "--quiet"))
1187 verbose = 0; 1200 verbose = 0;
1188 1201
1189 if (test_tls) 1202 if (test_tls)
1190 { 1203 {
1191#ifdef HTTPS_SUPPORT 1204#ifdef HTTPS_SUPPORT
1192 if (has_param(argc, argv, "--use-gnutls-cli")) 1205 if (has_param (argc, argv, "--use-gnutls-cli"))
1193 use_tls_tool = TLS_CLI_GNUTLS; 1206 use_tls_tool = TLS_CLI_GNUTLS;
1194 else if (has_param(argc, argv, "--use-openssl")) 1207 else if (has_param (argc, argv, "--use-openssl"))
1195 use_tls_tool = TLS_CLI_OPENSSL; 1208 use_tls_tool = TLS_CLI_OPENSSL;
1196 else if (has_param(argc, argv, "--use-gnutls-lib")) 1209 else if (has_param (argc, argv, "--use-gnutls-lib"))
1197 use_tls_tool = TLS_LIB_GNUTLS; 1210 use_tls_tool = TLS_LIB_GNUTLS;
1198#if defined(HAVE_FORK) && defined(HAVE_WAITPID) 1211#if defined(HAVE_FORK) && defined(HAVE_WAITPID)
1199 else if (0 == system ("gnutls-cli --version 1> /dev/null 2> /dev/null")) 1212 else if (0 == system ("gnutls-cli --version 1> /dev/null 2> /dev/null"))
1200 use_tls_tool = TLS_CLI_GNUTLS; 1213 use_tls_tool = TLS_CLI_GNUTLS;
1201 else if (0 == system ("openssl version 1> /dev/null 2> /dev/null")) 1214 else if (0 == system ("openssl version 1> /dev/null 2> /dev/null"))
1202 use_tls_tool = TLS_CLI_OPENSSL; 1215 use_tls_tool = TLS_CLI_OPENSSL;
1203#endif /* HAVE_FORK && HAVE_WAITPID */ 1216#endif /* HAVE_FORK && HAVE_WAITPID */
1204 else 1217 else
1205 use_tls_tool = TLS_LIB_GNUTLS; /* Should be available as MHD use it. */ 1218 use_tls_tool = TLS_LIB_GNUTLS; /* Should be available as MHD use it. */
1206 if (verbose) 1219 if (verbose)
1207 { 1220 {
1208 switch (use_tls_tool) 1221 switch (use_tls_tool)
1209 { 1222 {
1210 case TLS_CLI_GNUTLS: 1223 case TLS_CLI_GNUTLS:
1211 printf ("GnuTLS-CLI will be used for testing.\n"); 1224 printf ("GnuTLS-CLI will be used for testing.\n");
1212 break; 1225 break;
1213 case TLS_CLI_OPENSSL: 1226 case TLS_CLI_OPENSSL:
1214 printf ("Command line version of OpenSSL will be used for testing.\n"); 1227 printf ("Command line version of OpenSSL will be used for testing.\n");
1215 break; 1228 break;
1216 case TLS_LIB_GNUTLS: 1229 case TLS_LIB_GNUTLS:
1217 printf ("GnuTLS library will be used for testing.\n"); 1230 printf ("GnuTLS library will be used for testing.\n");
1218 break; 1231 break;
1219 default: 1232 default:
1220 abort ();
1221 }
1222 }
1223 if ( (TLS_LIB_GNUTLS == use_tls_tool) &&
1224 (GNUTLS_E_SUCCESS != gnutls_global_init()) )
1225 abort (); 1233 abort ();
1234 }
1235 }
1236 if ( (TLS_LIB_GNUTLS == use_tls_tool) &&
1237 (GNUTLS_E_SUCCESS != gnutls_global_init ()) )
1238 abort ();
1226 1239
1227#else /* ! HTTPS_SUPPORT */ 1240#else /* ! HTTPS_SUPPORT */
1228 fprintf (stderr, "HTTPS support was disabled by configure.\n"); 1241 fprintf (stderr, "HTTPS support was disabled by configure.\n");
1229 return 77; 1242 return 77;
1230#endif /* ! HTTPS_SUPPORT */ 1243#endif /* ! HTTPS_SUPPORT */
1231 } 1244 }
1232 1245
1233 /* run tests */ 1246 /* run tests */
1234 if (verbose) 1247 if (verbose)
@@ -1269,7 +1282,8 @@ main (int argc,
1269#endif 1282#endif
1270 1283
1271 /* Test thread-per-connection */ 1284 /* Test thread-per-connection */
1272 res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION, 1285 res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD
1286 | MHD_USE_THREAD_PER_CONNECTION,
1273 0); 1287 0);
1274 error_count += res; 1288 error_count += res;
1275 if (res) 1289 if (res)
@@ -1279,7 +1293,8 @@ main (int argc,
1279 else if (verbose) 1293 else if (verbose)
1280 printf ("PASSED: Upgrade with thread per connection.\n"); 1294 printf ("PASSED: Upgrade with thread per connection.\n");
1281 1295
1282 res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION, 1296 res = test_upgrade (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
1297 | MHD_USE_THREAD_PER_CONNECTION,
1283 0); 1298 0);
1284 error_count += res; 1299 error_count += res;
1285 if (res) 1300 if (res)
@@ -1289,7 +1304,8 @@ main (int argc,
1289 else if (verbose) 1304 else if (verbose)
1290 printf ("PASSED: Upgrade with thread per connection and 'auto'.\n"); 1305 printf ("PASSED: Upgrade with thread per connection and 'auto'.\n");
1291#ifdef HAVE_POLL 1306#ifdef HAVE_POLL
1292 res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL, 1307 res = test_upgrade (MHD_USE_INTERNAL_POLLING_THREAD
1308 | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL,
1293 0); 1309 0);
1294 error_count += res; 1310 error_count += res;
1295 if (res) 1311 if (res)
@@ -1381,7 +1397,7 @@ main (int argc,
1381 error_count); 1397 error_count);
1382#ifdef HTTPS_SUPPORT 1398#ifdef HTTPS_SUPPORT
1383 if (test_tls && (TLS_LIB_GNUTLS == use_tls_tool)) 1399 if (test_tls && (TLS_LIB_GNUTLS == use_tls_tool))
1384 gnutls_global_deinit(); 1400 gnutls_global_deinit ();
1385#endif /* HTTPS_SUPPORT */ 1401#endif /* HTTPS_SUPPORT */
1386 return error_count != 0; /* 0 == pass */ 1402 return error_count != 0; /* 0 == pass */
1387} 1403}