diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-01-15 17:04:29 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-01-15 17:04:51 +0300 |
commit | d44b9b23e0ca8b4b80b8e79c6216fc996ad45137 (patch) | |
tree | cda48e05e027f41c73f00c4f2126360a51341854 | |
parent | dab2e231513e8540980dbd1136871a69a41428c1 (diff) | |
download | libmicrohttpd-d44b9b23e0ca8b4b80b8e79c6216fc996ad45137.tar.gz libmicrohttpd-d44b9b23e0ca8b4b80b8e79c6216fc996ad45137.zip |
test_upgrade_large: applied fixes and improvements from test_upgrade
-rw-r--r-- | src/microhttpd/test_upgrade_large.c | 401 |
1 files changed, 307 insertions, 94 deletions
diff --git a/src/microhttpd/test_upgrade_large.c b/src/microhttpd/test_upgrade_large.c index 817408fb..6588f6c0 100644 --- a/src/microhttpd/test_upgrade_large.c +++ b/src/microhttpd/test_upgrade_large.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | Copyright (C) 2016, 2019 Christian Grothoff | 3 | Copyright (C) 2016-2020 Christian Grothoff |
4 | Copyright (C) 2016-2022 Evgeny Grin (Karlson2k) | ||
4 | 5 | ||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | 6 | 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 | it under the terms of the GNU General Public License as published |
@@ -46,12 +47,23 @@ | |||
46 | #include <netinet/ip.h> | 47 | #include <netinet/ip.h> |
47 | #endif /* HAVE_NETINET_IP_H */ | 48 | #endif /* HAVE_NETINET_IP_H */ |
48 | 49 | ||
50 | #ifdef HTTPS_SUPPORT | ||
51 | #include <gnutls/gnutls.h> | ||
52 | #include "../testcurl/https/tls_test_keys.h" | ||
53 | |||
54 | #if defined(HAVE_FORK) && defined(HAVE_WAITPID) | ||
55 | #include <sys/types.h> | ||
56 | #include <sys/wait.h> | ||
57 | #endif /* HAVE_FORK && HAVE_WAITPID */ | ||
58 | #endif /* HTTPS_SUPPORT */ | ||
59 | |||
49 | #include "platform.h" | 60 | #include "platform.h" |
50 | #include "microhttpd.h" | 61 | #include "microhttpd.h" |
51 | #include "mhd_itc.h" | 62 | #include "mhd_itc.h" |
52 | 63 | ||
53 | #include "test_helpers.h" | 64 | #include "test_helpers.h" |
54 | 65 | ||
66 | |||
55 | #define LARGE_STRING \ | 67 | #define LARGE_STRING \ |
56 | "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello" \ | 68 | "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello" \ |
57 | "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello" \ | 69 | "HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello" \ |
@@ -212,15 +224,109 @@ | |||
212 | "WorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorld" \ | 224 | "WorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorld" \ |
213 | "WorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorld\n" | 225 | "WorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorldWorld\n" |
214 | 226 | ||
215 | #ifdef HTTPS_SUPPORT | ||
216 | #include <gnutls/gnutls.h> | ||
217 | #include "../testcurl/https/tls_test_keys.h" | ||
218 | 227 | ||
219 | #if defined(HAVE_FORK) && defined(HAVE_WAITPID) | 228 | _MHD_NORETURN static void |
220 | #include <sys/types.h> | 229 | _externalErrorExit_func (const char *errDesc, const char *funcName, int lineNum) |
221 | #include <sys/wait.h> | 230 | { |
222 | #endif /* HAVE_FORK && HAVE_WAITPID */ | 231 | fflush (stdout); |
223 | #endif /* HTTPS_SUPPORT */ | 232 | if ((NULL != errDesc) && (0 != errDesc[0])) |
233 | fprintf (stderr, "%s", errDesc); | ||
234 | else | ||
235 | fprintf (stderr, "System or external library call failed"); | ||
236 | if ((NULL != funcName) && (0 != funcName[0])) | ||
237 | fprintf (stderr, " in %s", funcName); | ||
238 | if (0 < lineNum) | ||
239 | fprintf (stderr, " at line %d", lineNum); | ||
240 | |||
241 | fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno, | ||
242 | strerror (errno)); | ||
243 | #ifdef MHD_WINSOCK_SOCKETS | ||
244 | fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); | ||
245 | #endif /* MHD_WINSOCK_SOCKETS */ | ||
246 | fflush (stderr); | ||
247 | exit (99); | ||
248 | } | ||
249 | |||
250 | |||
251 | _MHD_NORETURN static void | ||
252 | _mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum) | ||
253 | { | ||
254 | fflush (stdout); | ||
255 | if ((NULL != errDesc) && (0 != errDesc[0])) | ||
256 | fprintf (stderr, "%s", errDesc); | ||
257 | else | ||
258 | fprintf (stderr, "MHD unexpected error"); | ||
259 | if ((NULL != funcName) && (0 != funcName[0])) | ||
260 | fprintf (stderr, " in %s", funcName); | ||
261 | if (0 < lineNum) | ||
262 | fprintf (stderr, " at line %d", lineNum); | ||
263 | |||
264 | fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno, | ||
265 | strerror (errno)); | ||
266 | |||
267 | fflush (stderr); | ||
268 | exit (8); | ||
269 | } | ||
270 | |||
271 | |||
272 | static void | ||
273 | _testErrorLog_func (const char *errDesc, const char *funcName, int lineNum) | ||
274 | { | ||
275 | fflush (stdout); | ||
276 | if ((NULL != errDesc) && (0 != errDesc[0])) | ||
277 | fprintf (stderr, "%s", errDesc); | ||
278 | else | ||
279 | fprintf (stderr, "System or external library call resulted in error"); | ||
280 | if ((NULL != funcName) && (0 != funcName[0])) | ||
281 | fprintf (stderr, " in %s", funcName); | ||
282 | if (0 < lineNum) | ||
283 | fprintf (stderr, " at line %d", lineNum); | ||
284 | |||
285 | fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno, | ||
286 | strerror (errno)); | ||
287 | #ifdef MHD_WINSOCK_SOCKETS | ||
288 | fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); | ||
289 | #endif /* MHD_WINSOCK_SOCKETS */ | ||
290 | fflush (stderr); | ||
291 | } | ||
292 | |||
293 | |||
294 | #if defined(HAVE___FUNC__) | ||
295 | #define externalErrorExit(ignore) \ | ||
296 | _externalErrorExit_func(NULL, __func__, __LINE__) | ||
297 | #define externalErrorExitDesc(errDesc) \ | ||
298 | _externalErrorExit_func(errDesc, __func__, __LINE__) | ||
299 | #define mhdErrorExit(ignore) \ | ||
300 | _mhdErrorExit_func(NULL, __func__, __LINE__) | ||
301 | #define mhdErrorExitDesc(errDesc) \ | ||
302 | _mhdErrorExit_func(errDesc, __func__, __LINE__) | ||
303 | #define testErrorLog(ignore) \ | ||
304 | _testErrorLog_func(NULL, __func__, __LINE__) | ||
305 | #define testErrorLogDesc(errDesc) \ | ||
306 | _testErrorLog_func(errDesc, __func__, __LINE__) | ||
307 | #elif defined(HAVE___FUNCTION__) | ||
308 | #define externalErrorExit(ignore) \ | ||
309 | _externalErrorExit_func(NULL, __FUNCTION__, __LINE__) | ||
310 | #define externalErrorExitDesc(errDesc) \ | ||
311 | _externalErrorExit_func(errDesc, __FUNCTION__, __LINE__) | ||
312 | #define mhdErrorExit(ignore) \ | ||
313 | _mhdErrorExit_func(NULL, __FUNCTION__, __LINE__) | ||
314 | #define mhdErrorExitDesc(errDesc) \ | ||
315 | _mhdErrorExit_func(errDesc, __FUNCTION__, __LINE__) | ||
316 | #define testErrorLog(ignore) \ | ||
317 | _testErrorLog_func(NULL, __FUNCTION__, __LINE__) | ||
318 | #define testErrorLogDesc(errDesc) \ | ||
319 | _testErrorLog_func(errDesc, __FUNCTION__, __LINE__) | ||
320 | #else | ||
321 | #define externalErrorExit(ignore) _externalErrorExit_func(NULL, NULL, __LINE__) | ||
322 | #define externalErrorExitDesc(errDesc) \ | ||
323 | _externalErrorExit_func(errDesc, NULL, __LINE__) | ||
324 | #define mhdErrorExit(ignore) _mhdErrorExit_func(NULL, NULL, __LINE__) | ||
325 | #define mhdErrorExitDesc(errDesc) _mhdErrorExit_func(errDesc, NULL, __LINE__) | ||
326 | #define testErrorLog(ignore) _testErrorLog_func(NULL, NULL, __LINE__) | ||
327 | #define testErrorLogDesc(errDesc) _testErrorLog_func(errDesc, NULL, __LINE__) | ||
328 | #endif | ||
329 | |||
224 | 330 | ||
225 | static int verbose = 0; | 331 | static int verbose = 0; |
226 | 332 | ||
@@ -257,7 +363,10 @@ gnutlscli_connect (int *sock, | |||
257 | SOCK_STREAM, | 363 | SOCK_STREAM, |
258 | 0, | 364 | 0, |
259 | sp)) | 365 | sp)) |
260 | return -1; | 366 | { |
367 | testErrorLogDesc ("socketpair() failed"); | ||
368 | return (pid_t) -1; | ||
369 | } | ||
261 | chld = fork (); | 370 | chld = fork (); |
262 | if (0 != chld) | 371 | if (0 != chld) |
263 | { | 372 | { |
@@ -269,9 +378,9 @@ gnutlscli_connect (int *sock, | |||
269 | (void) close (0); | 378 | (void) close (0); |
270 | (void) close (1); | 379 | (void) close (1); |
271 | if (-1 == dup2 (sp[0], 0)) | 380 | if (-1 == dup2 (sp[0], 0)) |
272 | abort (); | 381 | externalErrorExitDesc ("dup2() failed"); |
273 | if (-1 == dup2 (sp[0], 1)) | 382 | if (-1 == dup2 (sp[0], 1)) |
274 | abort (); | 383 | externalErrorExitDesc ("dup2() failed"); |
275 | MHD_socket_close_chk_ (sp[0]); | 384 | MHD_socket_close_chk_ (sp[0]); |
276 | if (TLS_CLI_GNUTLS == use_tls_tool) | 385 | if (TLS_CLI_GNUTLS == use_tls_tool) |
277 | { | 386 | { |
@@ -363,11 +472,15 @@ wr_create_plain_sckt (void) | |||
363 | { | 472 | { |
364 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); | 473 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); |
365 | if (NULL == s) | 474 | if (NULL == s) |
475 | { | ||
476 | testErrorLogDesc ("malloc() failed"); | ||
366 | return NULL; | 477 | return NULL; |
478 | } | ||
367 | s->t = wr_plain; | 479 | s->t = wr_plain; |
368 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); | 480 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
369 | if (MHD_INVALID_SOCKET != s->fd) | 481 | if (MHD_INVALID_SOCKET != s->fd) |
370 | return s; | 482 | return s; /* Success */ |
483 | testErrorLogDesc ("socket() failed"); | ||
371 | free (s); | 484 | free (s); |
372 | return NULL; | 485 | return NULL; |
373 | } | 486 | } |
@@ -383,7 +496,10 @@ wr_create_tls_sckt (void) | |||
383 | #ifdef HTTPS_SUPPORT | 496 | #ifdef HTTPS_SUPPORT |
384 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); | 497 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); |
385 | if (NULL == s) | 498 | if (NULL == s) |
499 | { | ||
500 | testErrorLogDesc ("malloc() failed"); | ||
386 | return NULL; | 501 | return NULL; |
502 | } | ||
387 | s->t = wr_tls; | 503 | s->t = wr_tls; |
388 | s->tls_connected = 0; | 504 | s->tls_connected = 0; |
389 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); | 505 | s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
@@ -408,13 +524,23 @@ wr_create_tls_sckt (void) | |||
408 | #endif /* GnuTLS before 3.1.9 or Win x64 */ | 524 | #endif /* GnuTLS before 3.1.9 or Win x64 */ |
409 | return s; | 525 | return s; |
410 | } | 526 | } |
527 | else | ||
528 | testErrorLogDesc ("gnutls_credentials_set() failed"); | ||
411 | gnutls_certificate_free_credentials (s->tls_crd); | 529 | gnutls_certificate_free_credentials (s->tls_crd); |
412 | } | 530 | } |
531 | else | ||
532 | testErrorLogDesc ("gnutls_certificate_allocate_credentials() failed"); | ||
413 | } | 533 | } |
534 | else | ||
535 | testErrorLogDesc ("gnutls_set_default_priority() failed"); | ||
414 | gnutls_deinit (s->tls_s); | 536 | gnutls_deinit (s->tls_s); |
415 | } | 537 | } |
538 | else | ||
539 | testErrorLogDesc ("gnutls_init() failed"); | ||
416 | (void) MHD_socket_close_ (s->fd); | 540 | (void) MHD_socket_close_ (s->fd); |
417 | } | 541 | } |
542 | else | ||
543 | testErrorLogDesc ("socket() failed"); | ||
418 | free (s); | 544 | free (s); |
419 | #endif /* HTTPS_SUPPORT */ | 545 | #endif /* HTTPS_SUPPORT */ |
420 | return NULL; | 546 | return NULL; |
@@ -433,7 +559,10 @@ wr_create_from_plain_sckt (MHD_socket plain_sk) | |||
433 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); | 559 | struct wr_socket *s = malloc (sizeof(struct wr_socket)); |
434 | 560 | ||
435 | if (NULL == s) | 561 | if (NULL == s) |
562 | { | ||
563 | testErrorLogDesc ("malloc() failed"); | ||
436 | return NULL; | 564 | return NULL; |
565 | } | ||
437 | s->t = wr_plain; | 566 | s->t = wr_plain; |
438 | s->fd = plain_sk; | 567 | s->fd = plain_sk; |
439 | return s; | 568 | return s; |
@@ -453,7 +582,10 @@ wr_connect (struct wr_socket *s, | |||
453 | int length) | 582 | int length) |
454 | { | 583 | { |
455 | if (0 != connect (s->fd, addr, length)) | 584 | if (0 != connect (s->fd, addr, length)) |
585 | { | ||
586 | testErrorLogDesc ("connect() failed"); | ||
456 | return -1; | 587 | return -1; |
588 | } | ||
457 | if (wr_plain == s->t) | 589 | if (wr_plain == s->t) |
458 | return 0; | 590 | return 0; |
459 | #ifdef HTTPS_SUPPORT | 591 | #ifdef HTTPS_SUPPORT |
@@ -468,6 +600,8 @@ wr_connect (struct wr_socket *s, | |||
468 | return 0; | 600 | return 0; |
469 | } | 601 | } |
470 | #endif /* HTTPS_SUPPORT */ | 602 | #endif /* HTTPS_SUPPORT */ |
603 | testErrorLogDesc ("HTTPS socket connect called, but code does not support" \ | ||
604 | " HTTPS sockets"); | ||
471 | return -1; | 605 | return -1; |
472 | } | 606 | } |
473 | 607 | ||
@@ -483,7 +617,10 @@ wr_handshake (struct wr_socket *s) | |||
483 | else if (GNUTLS_E_AGAIN == res) | 617 | else if (GNUTLS_E_AGAIN == res) |
484 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); | 618 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); |
485 | else | 619 | else |
620 | { | ||
621 | testErrorLogDesc ("gnutls_handshake() failed with hard error"); | ||
486 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | 622 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ |
623 | } | ||
487 | return s->tls_connected; | 624 | return s->tls_connected; |
488 | } | 625 | } |
489 | 626 | ||
@@ -507,13 +644,7 @@ wr_send (struct wr_socket *s, | |||
507 | size_t len) | 644 | size_t len) |
508 | { | 645 | { |
509 | if (wr_plain == s->t) | 646 | if (wr_plain == s->t) |
510 | { | 647 | return MHD_send_ (s->fd, buf, len); |
511 | ssize_t ret; | ||
512 | |||
513 | ret = MHD_send_ (s->fd, buf, len); | ||
514 | |||
515 | return ret; | ||
516 | } | ||
517 | #ifdef HTTPS_SUPPORT | 648 | #ifdef HTTPS_SUPPORT |
518 | if (wr_tls == s->t) | 649 | if (wr_tls == s->t) |
519 | { | 650 | { |
@@ -521,17 +652,22 @@ wr_send (struct wr_socket *s, | |||
521 | 652 | ||
522 | if (! s->tls_connected && ! wr_handshake (s)) | 653 | if (! s->tls_connected && ! wr_handshake (s)) |
523 | return -1; | 654 | return -1; |
524 | ret = gnutls_record_send (s->tls_s, | 655 | |
525 | buf, | 656 | ret = gnutls_record_send (s->tls_s, buf, len); |
526 | len); | ||
527 | if (ret > 0) | 657 | if (ret > 0) |
528 | return ret; | 658 | return ret; |
529 | if (GNUTLS_E_AGAIN == ret) | 659 | if (GNUTLS_E_AGAIN == ret) |
530 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); | 660 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); |
531 | else | 661 | else |
532 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | 662 | { |
663 | testErrorLogDesc ("gnutls_record_send() failed with hard error"); | ||
664 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | ||
665 | return -1; | ||
666 | } | ||
533 | } | 667 | } |
534 | #endif /* HTTPS_SUPPORT */ | 668 | #endif /* HTTPS_SUPPORT */ |
669 | testErrorLogDesc ("HTTPS socket send called, but code does not support" \ | ||
670 | " HTTPS sockets"); | ||
535 | return -1; | 671 | return -1; |
536 | } | 672 | } |
537 | 673 | ||
@@ -565,7 +701,11 @@ wr_recv (struct wr_socket *s, | |||
565 | if (GNUTLS_E_AGAIN == ret) | 701 | if (GNUTLS_E_AGAIN == ret) |
566 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); | 702 | MHD_socket_set_error_ (MHD_SCKT_EAGAIN_); |
567 | else | 703 | else |
568 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | 704 | { |
705 | testErrorLogDesc ("gnutls_record_recv() failed with hard error"); | ||
706 | MHD_socket_set_error_ (MHD_SCKT_ECONNABORTED_); /* hard error */ | ||
707 | return -1; | ||
708 | } | ||
569 | } | 709 | } |
570 | #endif /* HTTPS_SUPPORT */ | 710 | #endif /* HTTPS_SUPPORT */ |
571 | return -1; | 711 | return -1; |
@@ -601,7 +741,7 @@ static pthread_t pt; | |||
601 | /** | 741 | /** |
602 | * Will be set to the upgraded socket. | 742 | * Will be set to the upgraded socket. |
603 | */ | 743 | */ |
604 | static struct wr_socket *usock; | 744 | static struct wr_socket *volatile usock; |
605 | 745 | ||
606 | /** | 746 | /** |
607 | * Thread we use to run the interaction with the upgraded socket. | 747 | * Thread we use to run the interaction with the upgraded socket. |
@@ -614,6 +754,32 @@ static pthread_t pt_client; | |||
614 | static volatile bool done; | 754 | static volatile bool done; |
615 | 755 | ||
616 | 756 | ||
757 | const char * | ||
758 | term_reason_str (enum MHD_RequestTerminationCode term_code) | ||
759 | { | ||
760 | switch ((int) term_code) | ||
761 | { | ||
762 | case MHD_REQUEST_TERMINATED_COMPLETED_OK: | ||
763 | return "COMPLETED_OK"; | ||
764 | case MHD_REQUEST_TERMINATED_WITH_ERROR: | ||
765 | return "TERMINATED_WITH_ERROR"; | ||
766 | case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED: | ||
767 | return "TIMEOUT_REACHED"; | ||
768 | case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: | ||
769 | return "DAEMON_SHUTDOWN"; | ||
770 | case MHD_REQUEST_TERMINATED_READ_ERROR: | ||
771 | return "READ_ERROR"; | ||
772 | case MHD_REQUEST_TERMINATED_CLIENT_ABORT: | ||
773 | return "CLIENT_ABORT"; | ||
774 | case -1: | ||
775 | return "(not called)"; | ||
776 | default: | ||
777 | return "(unknown code)"; | ||
778 | } | ||
779 | return "(problem)"; /* unreachable */ | ||
780 | } | ||
781 | |||
782 | |||
617 | /** | 783 | /** |
618 | * Callback used by MHD to notify the application about completed | 784 | * Callback used by MHD to notify the application about completed |
619 | * requests. Frees memory. | 785 | * requests. Frees memory. |
@@ -630,19 +796,23 @@ notify_completed_cb (void *cls, | |||
630 | void **con_cls, | 796 | void **con_cls, |
631 | enum MHD_RequestTerminationCode toe) | 797 | enum MHD_RequestTerminationCode toe) |
632 | { | 798 | { |
633 | pthread_t *ppth = *con_cls; | ||
634 | |||
635 | (void) cls; | 799 | (void) cls; |
636 | (void) connection; /* Unused. Silent compiler warning. */ | 800 | (void) connection; /* Unused. Silent compiler warning. */ |
801 | if (verbose) | ||
802 | printf ("notify_completed_cb() has been called with '%s' code.\n", | ||
803 | term_reason_str (toe)); | ||
637 | if ( (toe != MHD_REQUEST_TERMINATED_COMPLETED_OK) && | 804 | if ( (toe != MHD_REQUEST_TERMINATED_COMPLETED_OK) && |
638 | (toe != MHD_REQUEST_TERMINATED_CLIENT_ABORT) && | 805 | (toe != MHD_REQUEST_TERMINATED_CLIENT_ABORT) && |
639 | (toe != MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN) ) | 806 | (toe != MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN) ) |
640 | abort (); | 807 | mhdErrorExitDesc ("notify_completed_cb() called with wrong code"); |
808 | if (NULL == con_cls) | ||
809 | mhdErrorExitDesc ("'con_cls' parameter is NULL"); | ||
810 | if (NULL == *con_cls) | ||
811 | mhdErrorExitDesc ("'*con_cls' pointer is NULL"); | ||
641 | if (! pthread_equal (**((pthread_t **) con_cls), | 812 | if (! pthread_equal (**((pthread_t **) con_cls), |
642 | pthread_self ())) | 813 | pthread_self ())) |
643 | abort (); | 814 | mhdErrorExitDesc ("notify_completed_cb() is called in wrong thread"); |
644 | if (NULL != ppth) | 815 | free (*con_cls); |
645 | free (*con_cls); | ||
646 | *con_cls = NULL; | 816 | *con_cls = NULL; |
647 | } | 817 | } |
648 | 818 | ||
@@ -664,12 +834,16 @@ log_cb (void *cls, | |||
664 | 834 | ||
665 | (void) cls; | 835 | (void) cls; |
666 | (void) connection; /* Unused. Silent compiler warning. */ | 836 | (void) connection; /* Unused. Silent compiler warning. */ |
667 | if (0 != strcmp (uri, | 837 | if (NULL == uri) |
668 | "/")) | 838 | mhdErrorExitDesc ("The 'uri' parameter is NULL"); |
669 | abort (); | 839 | if (0 != strcmp (uri, "/")) |
840 | { | ||
841 | fprintf (stderr, "Wrong 'uri' value: '%s'. ", uri); | ||
842 | mhdErrorExit (); | ||
843 | } | ||
670 | ppth = malloc (sizeof (pthread_t)); | 844 | ppth = malloc (sizeof (pthread_t)); |
671 | if (NULL == ppth) | 845 | if (NULL == ppth) |
672 | abort (); | 846 | externalErrorExitDesc ("malloc() failed"); |
673 | *ppth = pthread_self (); | 847 | *ppth = pthread_self (); |
674 | return (void *) ppth; | 848 | return (void *) ppth; |
675 | } | 849 | } |
@@ -708,15 +882,15 @@ notify_connection_cb (void *cls, | |||
708 | { | 882 | { |
709 | case MHD_CONNECTION_NOTIFY_STARTED: | 883 | case MHD_CONNECTION_NOTIFY_STARTED: |
710 | if (MHD_NO != started) | 884 | if (MHD_NO != started) |
711 | abort (); | 885 | mhdErrorExitDesc ("The connection has been already started"); |
712 | started = MHD_YES; | 886 | started = MHD_YES; |
713 | *socket_context = &started; | 887 | *socket_context = &started; |
714 | break; | 888 | break; |
715 | case MHD_CONNECTION_NOTIFY_CLOSED: | 889 | case MHD_CONNECTION_NOTIFY_CLOSED: |
716 | if (MHD_YES != started) | 890 | if (MHD_YES != started) |
717 | abort (); | 891 | mhdErrorExitDesc ("The connection has not been started before"); |
718 | if (&started != *socket_context) | 892 | if (&started != *socket_context) |
719 | abort (); | 893 | mhdErrorExitDesc ("Wrong '*socket_context' value"); |
720 | *socket_context = NULL; | 894 | *socket_context = NULL; |
721 | started = MHD_NO; | 895 | started = MHD_NO; |
722 | break; | 896 | break; |
@@ -737,15 +911,15 @@ make_blocking (MHD_socket fd) | |||
737 | 911 | ||
738 | flags = fcntl (fd, F_GETFL); | 912 | flags = fcntl (fd, F_GETFL); |
739 | if (-1 == flags) | 913 | if (-1 == flags) |
740 | abort (); | 914 | externalErrorExitDesc ("fcntl() failed"); |
741 | if ((flags & ~O_NONBLOCK) != flags) | 915 | if ((flags & ~O_NONBLOCK) != flags) |
742 | if (-1 == fcntl (fd, F_SETFL, flags & ~O_NONBLOCK)) | 916 | if (-1 == fcntl (fd, F_SETFL, flags & ~O_NONBLOCK)) |
743 | abort (); | 917 | externalErrorExitDesc ("fcntl() failed"); |
744 | #elif defined(MHD_WINSOCK_SOCKETS) | 918 | #elif defined(MHD_WINSOCK_SOCKETS) |
745 | unsigned long flags = 0; | 919 | unsigned long flags = 0; |
746 | 920 | ||
747 | if (0 != ioctlsocket (fd, (int) FIONBIO, &flags)) | 921 | if (0 != ioctlsocket (fd, (int) FIONBIO, &flags)) |
748 | abort (); | 922 | externalErrorExitDesc ("ioctlsocket() failed"); |
749 | #endif /* MHD_WINSOCK_SOCKETS */ | 923 | #endif /* MHD_WINSOCK_SOCKETS */ |
750 | } | 924 | } |
751 | 925 | ||
@@ -776,9 +950,11 @@ send_all (struct wr_socket *sock, | |||
776 | len - off); | 950 | len - off); |
777 | if (0 > ret) | 951 | if (0 > ret) |
778 | { | 952 | { |
779 | if (! MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) | 953 | if (! MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()) && |
780 | abort (); | 954 | ! MHD_SCKT_ERR_IS_EINTR_ (MHD_socket_get_error_ ())) |
781 | ret = 0; | 955 | externalErrorExitDesc ("send() failed"); |
956 | else | ||
957 | ret = 0; | ||
782 | } | 958 | } |
783 | kick_select (); | 959 | kick_select (); |
784 | } | 960 | } |
@@ -809,13 +985,12 @@ recv_hdr (struct wr_socket *sock) | |||
809 | { | 985 | { |
810 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) | 986 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) |
811 | continue; | 987 | continue; |
812 | fprintf (stderr, | 988 | if (MHD_SCKT_ERR_IS_EINTR_ (MHD_socket_get_error_ ())) |
813 | "recv failed unexpectedly: %s\n", | 989 | continue; |
814 | MHD_socket_last_strerr_ ()); | 990 | externalErrorExitDesc ("recv() failed"); |
815 | abort (); | ||
816 | } | 991 | } |
817 | if (0 == ret) | 992 | if (0 == ret) |
818 | continue; | 993 | mhdErrorExitDesc ("The server unexpectedly closed connection"); |
819 | kick_select (); | 994 | kick_select (); |
820 | if (c == next) | 995 | if (c == next) |
821 | { | 996 | { |
@@ -855,18 +1030,29 @@ recv_all (struct wr_socket *sock, | |||
855 | len - off); | 1030 | len - off); |
856 | if (0 > ret) | 1031 | if (0 > ret) |
857 | { | 1032 | { |
858 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ())) | 1033 | if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()) || |
1034 | MHD_SCKT_ERR_IS_EINTR_ (MHD_socket_get_error_ ())) | ||
859 | { | 1035 | { |
860 | ret = 0; | 1036 | ret = 0; |
861 | continue; | 1037 | continue; |
862 | } | 1038 | } |
863 | abort (); | 1039 | externalErrorExitDesc ("recv() failed"); |
864 | } | 1040 | } |
1041 | if (0 == ret) | ||
1042 | mhdErrorExitDesc ("The server unexpectedly closed connection"); | ||
865 | if (0 != strncmp (text, buf, off + ret)) | 1043 | if (0 != strncmp (text, buf, off + ret)) |
866 | abort (); | 1044 | { |
1045 | fprintf (stderr, "Wrong received text. Expected: '%s' ." | ||
1046 | "Got: '%.*s'. ", text, (int) (off + ret), buf); | ||
1047 | mhdErrorExit (); | ||
1048 | } | ||
867 | } | 1049 | } |
868 | if (0 != strncmp (text, buf, len)) | 1050 | if (0 != strncmp (text, buf, len)) |
869 | abort (); | 1051 | { |
1052 | fprintf (stderr, "Wrong received text. Expected: '%s' ." | ||
1053 | "Got: '%.*s'. ", text, (int) len, buf); | ||
1054 | mhdErrorExit (); | ||
1055 | } | ||
870 | } | 1056 | } |
871 | 1057 | ||
872 | 1058 | ||
@@ -981,12 +1167,12 @@ upgrade_cb (void *cls, | |||
981 | 1167 | ||
982 | usock = wr_create_from_plain_sckt (sock); | 1168 | usock = wr_create_from_plain_sckt (sock); |
983 | if (0 != extra_in_size) | 1169 | if (0 != extra_in_size) |
984 | abort (); | 1170 | mhdErrorExitDesc ("'extra_in_size' is not zero"); |
985 | if (0 != pthread_create (&pt, | 1171 | if (0 != pthread_create (&pt, |
986 | NULL, | 1172 | NULL, |
987 | &run_usock, | 1173 | &run_usock, |
988 | urh)) | 1174 | urh)) |
989 | abort (); | 1175 | externalErrorExitDesc ("pthread_create() failed"); |
990 | } | 1176 | } |
991 | 1177 | ||
992 | 1178 | ||
@@ -1040,7 +1226,6 @@ ahc_upgrade (void *cls, | |||
1040 | void **con_cls) | 1226 | void **con_cls) |
1041 | { | 1227 | { |
1042 | struct MHD_Response *resp; | 1228 | struct MHD_Response *resp; |
1043 | enum MHD_Result ret; | ||
1044 | (void) cls; | 1229 | (void) cls; |
1045 | (void) url; | 1230 | (void) url; |
1046 | (void) method; /* Unused. Silent compiler warning. */ | 1231 | (void) method; /* Unused. Silent compiler warning. */ |
@@ -1048,20 +1233,26 @@ ahc_upgrade (void *cls, | |||
1048 | (void) upload_data; | 1233 | (void) upload_data; |
1049 | (void) upload_data_size; /* Unused. Silent compiler warning. */ | 1234 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
1050 | 1235 | ||
1236 | if (NULL == con_cls) | ||
1237 | mhdErrorExitDesc ("'con_cls' is NULL"); | ||
1051 | if (NULL == *con_cls) | 1238 | if (NULL == *con_cls) |
1052 | abort (); | 1239 | mhdErrorExitDesc ("'*con_cls' value is NULL"); |
1053 | if (! pthread_equal (**((pthread_t **) con_cls), pthread_self ())) | 1240 | if (! pthread_equal (**((pthread_t **) con_cls), pthread_self ())) |
1054 | abort (); | 1241 | mhdErrorExitDesc ("ahc_upgrade() is called in wrong thread"); |
1055 | resp = MHD_create_response_for_upgrade (&upgrade_cb, | 1242 | resp = MHD_create_response_for_upgrade (&upgrade_cb, |
1056 | NULL); | 1243 | NULL); |
1057 | MHD_add_response_header (resp, | 1244 | if (NULL == resp) |
1058 | MHD_HTTP_HEADER_UPGRADE, | 1245 | mhdErrorExitDesc ("MHD_create_response_for_upgrade() failed"); |
1059 | "Hello World Protocol"); | 1246 | if (MHD_YES != MHD_add_response_header (resp, |
1060 | ret = MHD_queue_response (connection, | 1247 | MHD_HTTP_HEADER_UPGRADE, |
1061 | MHD_HTTP_SWITCHING_PROTOCOLS, | 1248 | "Hello World Protocol")) |
1062 | resp); | 1249 | mhdErrorExitDesc ("MHD_add_response_header() failed"); |
1250 | if (MHD_YES != MHD_queue_response (connection, | ||
1251 | MHD_HTTP_SWITCHING_PROTOCOLS, | ||
1252 | resp)) | ||
1253 | mhdErrorExitDesc ("MHD_queue_response() failed"); | ||
1063 | MHD_destroy_response (resp); | 1254 | MHD_destroy_response (resp); |
1064 | return ret; | 1255 | return MHD_YES; |
1065 | } | 1256 | } |
1066 | 1257 | ||
1067 | 1258 | ||
@@ -1095,7 +1286,7 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) | |||
1095 | &ws, | 1286 | &ws, |
1096 | &es, | 1287 | &es, |
1097 | &max_fd)) | 1288 | &max_fd)) |
1098 | abort (); | 1289 | mhdErrorExitDesc ("MHD_get_fdset() failed"); |
1099 | (void) MHD_get_timeout (daemon, | 1290 | (void) MHD_get_timeout (daemon, |
1100 | &to); | 1291 | &to); |
1101 | if (1000 < to) | 1292 | if (1000 < to) |
@@ -1107,7 +1298,17 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) | |||
1107 | &ws, | 1298 | &ws, |
1108 | &es, | 1299 | &es, |
1109 | &tv)) | 1300 | &tv)) |
1110 | abort (); | 1301 | { |
1302 | #ifdef MHD_POSIX_SOCKETS | ||
1303 | if (EINTR != errno) | ||
1304 | externalErrorExitDesc ("Unexpected select() error"); | ||
1305 | #else | ||
1306 | if ((WSAEINVAL != WSAGetLastError ()) || | ||
1307 | (0 != rs.fd_count) || (0 != ws.fd_count) || (0 != es.fd_count) ) | ||
1308 | externalErrorExitDesc ("Unexpected select() error"); | ||
1309 | Sleep (tv.tv_sec * 1000 + tv.tv_usec / 1000); | ||
1310 | #endif | ||
1311 | } | ||
1111 | if (FD_ISSET (MHD_itc_r_fd_ (kicker), &rs)) | 1312 | if (FD_ISSET (MHD_itc_r_fd_ (kicker), &rs)) |
1112 | MHD_itc_clear_ (kicker); | 1313 | MHD_itc_clear_ (kicker); |
1113 | MHD_run_from_select (daemon, | 1314 | MHD_run_from_select (daemon, |
@@ -1129,7 +1330,7 @@ static void | |||
1129 | run_mhd_poll_loop (struct MHD_Daemon *daemon) | 1330 | run_mhd_poll_loop (struct MHD_Daemon *daemon) |
1130 | { | 1331 | { |
1131 | (void) daemon; /* Unused. Silent compiler warning. */ | 1332 | (void) daemon; /* Unused. Silent compiler warning. */ |
1132 | abort (); /* currently not implementable with existing MHD API */ | 1333 | externalErrorExitDesc ("Not implementable with MHD API"); |
1133 | } | 1334 | } |
1134 | 1335 | ||
1135 | 1336 | ||
@@ -1154,6 +1355,8 @@ run_mhd_epoll_loop (struct MHD_Daemon *daemon) | |||
1154 | 1355 | ||
1155 | di = MHD_get_daemon_info (daemon, | 1356 | di = MHD_get_daemon_info (daemon, |
1156 | MHD_DAEMON_INFO_EPOLL_FD); | 1357 | MHD_DAEMON_INFO_EPOLL_FD); |
1358 | if (NULL == di) | ||
1359 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); | ||
1157 | ep = di->listen_fd; | 1360 | ep = di->listen_fd; |
1158 | while (! done) | 1361 | while (! done) |
1159 | { | 1362 | { |
@@ -1172,10 +1375,18 @@ run_mhd_epoll_loop (struct MHD_Daemon *daemon) | |||
1172 | NULL, | 1375 | NULL, |
1173 | NULL, | 1376 | NULL, |
1174 | &tv); | 1377 | &tv); |
1175 | if ( (-1 == ret) && | 1378 | if (0 > ret) |
1176 | (EAGAIN != errno) && | 1379 | { |
1177 | (EINTR != errno) ) | 1380 | #ifdef MHD_POSIX_SOCKETS |
1178 | abort (); | 1381 | if (EINTR != errno) |
1382 | externalErrorExitDesc ("Unexpected select() error"); | ||
1383 | #else | ||
1384 | if ((WSAEINVAL != WSAGetLastError ()) || | ||
1385 | (0 != rs.fd_count) || (0 != ws.fd_count) || (0 != es.fd_count) ) | ||
1386 | externalErrorExitDesc ("Unexpected select() error"); | ||
1387 | Sleep (tv.tv_sec * 1000 + tv.tv_usec / 1000); | ||
1388 | #endif | ||
1389 | } | ||
1179 | if (FD_ISSET (MHD_itc_r_fd_ (kicker), &rs)) | 1390 | if (FD_ISSET (MHD_itc_r_fd_ (kicker), &rs)) |
1180 | MHD_itc_clear_ (kicker); | 1391 | MHD_itc_clear_ (kicker); |
1181 | MHD_run (daemon); | 1392 | MHD_run (daemon); |
@@ -1205,7 +1416,7 @@ run_mhd_loop (struct MHD_Daemon *daemon, | |||
1205 | run_mhd_epoll_loop (daemon); | 1416 | run_mhd_epoll_loop (daemon); |
1206 | #endif | 1417 | #endif |
1207 | else | 1418 | else |
1208 | abort (); | 1419 | externalErrorExitDesc ("Wrong 'flags' value"); |
1209 | } | 1420 | } |
1210 | 1421 | ||
1211 | 1422 | ||
@@ -1268,28 +1479,28 @@ test_upgrade (int flags, | |||
1268 | MHD_OPTION_END); | 1479 | MHD_OPTION_END); |
1269 | #endif /* HTTPS_SUPPORT */ | 1480 | #endif /* HTTPS_SUPPORT */ |
1270 | if (NULL == d) | 1481 | if (NULL == d) |
1271 | return 2; | 1482 | mhdErrorExitDesc ("MHD_start_daemon() failed"); |
1272 | real_flags = MHD_get_daemon_info (d, | 1483 | real_flags = MHD_get_daemon_info (d, |
1273 | MHD_DAEMON_INFO_FLAGS); | 1484 | MHD_DAEMON_INFO_FLAGS); |
1274 | if (NULL == real_flags) | 1485 | if (NULL == real_flags) |
1275 | abort (); | 1486 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); |
1276 | dinfo = MHD_get_daemon_info (d, | 1487 | dinfo = MHD_get_daemon_info (d, |
1277 | MHD_DAEMON_INFO_BIND_PORT); | 1488 | MHD_DAEMON_INFO_BIND_PORT); |
1278 | if ( (NULL == dinfo) || | 1489 | if ( (NULL == dinfo) || |
1279 | (0 == dinfo->port) ) | 1490 | (0 == dinfo->port) ) |
1280 | abort (); | 1491 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); |
1281 | if (! test_tls || (TLS_LIB_GNUTLS == use_tls_tool)) | 1492 | if (! test_tls || (TLS_LIB_GNUTLS == use_tls_tool)) |
1282 | { | 1493 | { |
1283 | sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt (); | 1494 | sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt (); |
1284 | if (NULL == sock) | 1495 | if (NULL == sock) |
1285 | abort (); | 1496 | externalErrorExitDesc ("Create socket failed"); |
1286 | sa.sin_family = AF_INET; | 1497 | sa.sin_family = AF_INET; |
1287 | sa.sin_port = htons (dinfo->port); | 1498 | sa.sin_port = htons (dinfo->port); |
1288 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 1499 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
1289 | if (0 != wr_connect (sock, | 1500 | if (0 != wr_connect (sock, |
1290 | (struct sockaddr *) &sa, | 1501 | (struct sockaddr *) &sa, |
1291 | sizeof (sa))) | 1502 | sizeof (sa))) |
1292 | abort (); | 1503 | externalErrorExitDesc ("Connect socket failed"); |
1293 | } | 1504 | } |
1294 | else | 1505 | else |
1295 | { | 1506 | { |
@@ -1303,30 +1514,27 @@ test_upgrade (int flags, | |||
1303 | sizeof (port)); | 1514 | sizeof (port)); |
1304 | if (-1 == (pid = gnutlscli_connect (&tls_fork_sock, | 1515 | if (-1 == (pid = gnutlscli_connect (&tls_fork_sock, |
1305 | port))) | 1516 | port))) |
1306 | { | 1517 | externalErrorExitDesc ("gnutlscli_connect() failed"); |
1307 | MHD_stop_daemon (d); | ||
1308 | return 4; | ||
1309 | } | ||
1310 | 1518 | ||
1311 | sock = wr_create_from_plain_sckt (tls_fork_sock); | 1519 | sock = wr_create_from_plain_sckt (tls_fork_sock); |
1312 | if (NULL == sock) | 1520 | if (NULL == sock) |
1313 | abort (); | 1521 | externalErrorExitDesc ("wr_create_from_plain_sckt() failed"); |
1314 | #else /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ | 1522 | #else /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ |
1315 | abort (); | 1523 | externalErrorExitDesc ("Unsupported 'use_tls_tool' value"); |
1316 | #endif /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ | 1524 | #endif /* !HTTPS_SUPPORT || !HAVE_FORK || !HAVE_WAITPID */ |
1317 | } | 1525 | } |
1318 | 1526 | ||
1319 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) | 1527 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) |
1320 | { | 1528 | { |
1321 | if (! MHD_itc_init_ (kicker)) | 1529 | if (! MHD_itc_init_ (kicker)) |
1322 | abort (); | 1530 | externalErrorExitDesc ("MHD_itc_init_() failed"); |
1323 | } | 1531 | } |
1324 | 1532 | ||
1325 | if (0 != pthread_create (&pt_client, | 1533 | if (0 != pthread_create (&pt_client, |
1326 | NULL, | 1534 | NULL, |
1327 | &run_usock_client, | 1535 | &run_usock_client, |
1328 | sock)) | 1536 | sock)) |
1329 | abort (); | 1537 | externalErrorExitDesc ("pthread_create() failed"); |
1330 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) | 1538 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) |
1331 | { | 1539 | { |
1332 | enum MHD_FLAG used_flags; | 1540 | enum MHD_FLAG used_flags; |
@@ -1337,13 +1545,18 @@ test_upgrade (int flags, | |||
1337 | sizeof (used_flags)); | 1545 | sizeof (used_flags)); |
1338 | run_mhd_loop (d, used_flags); | 1546 | run_mhd_loop (d, used_flags); |
1339 | } | 1547 | } |
1340 | pthread_join (pt_client, | 1548 | if (0 != pthread_join (pt_client, |
1341 | NULL); | 1549 | NULL)) |
1342 | pthread_join (pt, | 1550 | externalErrorExitDesc ("pthread_join() failed"); |
1343 | NULL); | 1551 | if (0 != pthread_join (pt, |
1552 | NULL)) | ||
1553 | externalErrorExitDesc ("pthread_join() failed"); | ||
1344 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) | 1554 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) |
1345 | if (test_tls && (TLS_LIB_GNUTLS != use_tls_tool)) | 1555 | if (test_tls && (TLS_LIB_GNUTLS != use_tls_tool)) |
1346 | waitpid (pid, NULL, 0); | 1556 | { |
1557 | if ((pid_t) -1 == waitpid (pid, NULL, 0)) | ||
1558 | externalErrorExitDesc ("waitpid() failed"); | ||
1559 | } | ||
1347 | #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ | 1560 | #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ |
1348 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) | 1561 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) |
1349 | { | 1562 | { |
@@ -1400,12 +1613,12 @@ main (int argc, | |||
1400 | printf ("GnuTLS library will be used for testing.\n"); | 1613 | printf ("GnuTLS library will be used for testing.\n"); |
1401 | break; | 1614 | break; |
1402 | default: | 1615 | default: |
1403 | abort (); | 1616 | externalErrorExitDesc ("Wrong 'use_tls_tool' value"); |
1404 | } | 1617 | } |
1405 | } | 1618 | } |
1406 | if ( (TLS_LIB_GNUTLS == use_tls_tool) && | 1619 | if ( (TLS_LIB_GNUTLS == use_tls_tool) && |
1407 | (GNUTLS_E_SUCCESS != gnutls_global_init ()) ) | 1620 | (GNUTLS_E_SUCCESS != gnutls_global_init ()) ) |
1408 | abort (); | 1621 | externalErrorExitDesc ("gnutls_global_init() failed"); |
1409 | 1622 | ||
1410 | #else /* ! HTTPS_SUPPORT */ | 1623 | #else /* ! HTTPS_SUPPORT */ |
1411 | fprintf (stderr, "HTTPS support was disabled by configure.\n"); | 1624 | fprintf (stderr, "HTTPS support was disabled by configure.\n"); |