diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-10-25 19:10:38 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-10-25 19:10:38 +0300 |
commit | c36ac56f38a798c1ae162590de0c9ef17e8a1f3d (patch) | |
tree | 8df4d5b17a7cec2271221e9817fe8112d70678e9 /src/testcurl | |
parent | fa330be735a39d30f4e025c3afdba192e6c2b1bb (diff) | |
download | libmicrohttpd-c36ac56f38a798c1ae162590de0c9ef17e8a1f3d.tar.gz libmicrohttpd-c36ac56f38a798c1ae162590de0c9ef17e8a1f3d.zip |
test_add_conn_cleanup: check whether client connection
sockets were closed by MHD as part of cleanup process
Diffstat (limited to 'src/testcurl')
-rw-r--r-- | src/testcurl/test_add_conn.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/testcurl/test_add_conn.c b/src/testcurl/test_add_conn.c index c7e49b91..dbb1af8b 100644 --- a/src/testcurl/test_add_conn.c +++ b/src/testcurl/test_add_conn.c | |||
@@ -314,6 +314,7 @@ struct addConnParam | |||
314 | 314 | ||
315 | MHD_socket lstn_sk; | 315 | MHD_socket lstn_sk; |
316 | 316 | ||
317 | MHD_socket clent_sk; | ||
317 | /* Non-zero indicate error */ | 318 | /* Non-zero indicate error */ |
318 | volatile int result; | 319 | volatile int result; |
319 | 320 | ||
@@ -325,13 +326,13 @@ struct addConnParam | |||
325 | static int | 326 | static int |
326 | doAcceptAndAddConnInThread (struct addConnParam *p) | 327 | doAcceptAndAddConnInThread (struct addConnParam *p) |
327 | { | 328 | { |
328 | MHD_socket newConn; | ||
329 | struct sockaddr addr; | 329 | struct sockaddr addr; |
330 | socklen_t addr_len = sizeof(addr); | 330 | socklen_t addr_len = sizeof(addr); |
331 | 331 | ||
332 | newConn = acceptTimeLimited (p->lstn_sk, &addr, &addr_len); | 332 | p->clent_sk = acceptTimeLimited (p->lstn_sk, &addr, &addr_len); |
333 | 333 | ||
334 | p->result = (MHD_YES == MHD_add_connection (p->d, newConn, &addr, addr_len)) ? | 334 | p->result = (MHD_YES == MHD_add_connection (p->d, p->clent_sk, |
335 | &addr, addr_len)) ? | ||
335 | 0 : 1; | 336 | 0 : 1; |
336 | if (p->result) | 337 | if (p->result) |
337 | fprintf (stderr, "MHD_add_connection() failed, errno=%d.\n", errno); | 338 | fprintf (stderr, "MHD_add_connection() failed, errno=%d.\n", errno); |
@@ -577,6 +578,7 @@ performTestCleanup (struct MHD_Daemon *d, int num_queries) | |||
577 | struct curlQueryParams *qParamList; | 578 | struct curlQueryParams *qParamList; |
578 | struct addConnParam aParam; | 579 | struct addConnParam aParam; |
579 | MHD_socket lstn_sk; /* Additional listening socket */ | 580 | MHD_socket lstn_sk; /* Additional listening socket */ |
581 | MHD_socket *clntSkList; | ||
580 | int a_port; /* Additional listening socket port */ | 582 | int a_port; /* Additional listening socket port */ |
581 | int i; | 583 | int i; |
582 | int ret = 0; /* Return value */ | 584 | int ret = 0; /* Return value */ |
@@ -589,7 +591,8 @@ performTestCleanup (struct MHD_Daemon *d, int num_queries) | |||
589 | lstn_sk = createListeningSocket (&a_port); /* Sets a_port */ | 591 | lstn_sk = createListeningSocket (&a_port); /* Sets a_port */ |
590 | 592 | ||
591 | qParamList = malloc (sizeof(struct curlQueryParams) * num_queries); | 593 | qParamList = malloc (sizeof(struct curlQueryParams) * num_queries); |
592 | if (NULL == qParamList) | 594 | clntSkList = malloc (sizeof(MHD_socket) * num_queries); |
595 | if ((NULL == qParamList) || (NULL == clntSkList)) | ||
593 | externalErrorExitDesc ("malloc failed"); | 596 | externalErrorExitDesc ("malloc failed"); |
594 | 597 | ||
595 | /* Start CURL queries */ | 598 | /* Start CURL queries */ |
@@ -606,13 +609,32 @@ performTestCleanup (struct MHD_Daemon *d, int num_queries) | |||
606 | aParam.d = d; | 609 | aParam.d = d; |
607 | aParam.lstn_sk = lstn_sk; | 610 | aParam.lstn_sk = lstn_sk; |
608 | for (i = 0; i < num_queries; i++) | 611 | for (i = 0; i < num_queries; i++) |
612 | { | ||
613 | aParam.clent_sk = MHD_INVALID_SOCKET; | ||
609 | ret |= doAcceptAndAddConnInThread (&aParam); | 614 | ret |= doAcceptAndAddConnInThread (&aParam); |
615 | clntSkList[i] = aParam.clent_sk; | ||
616 | } | ||
610 | 617 | ||
611 | /* Stop daemon while some of new connection are not yet | 618 | /* Stop daemon while some of new connection are not yet |
612 | * processed because of slow response to the first queries. */ | 619 | * processed because of slow response to the first queries. */ |
613 | MHD_stop_daemon (d); | 620 | MHD_stop_daemon (d); |
614 | (void) MHD_socket_close_ (aParam.lstn_sk); | 621 | (void) MHD_socket_close_ (aParam.lstn_sk); |
615 | 622 | ||
623 | /* Check whether all client sockets were closed by MHD. | ||
624 | * Closure of socket by MHD indicate valid cleanup performed. */ | ||
625 | for (i = 0; i < num_queries; i++) | ||
626 | { | ||
627 | if (MHD_INVALID_SOCKET != clntSkList[i]) | ||
628 | { /* Check whether socket could be closed one more time. */ | ||
629 | if (MHD_socket_close_ (clntSkList[i])) | ||
630 | { | ||
631 | ret |= 2; | ||
632 | fprintf (stderr, "Client socket was not closed by MHD during" \ | ||
633 | "cleanup process.\n"); | ||
634 | } | ||
635 | } | ||
636 | } | ||
637 | |||
616 | /* Wait for CURL threads to complete. */ | 638 | /* Wait for CURL threads to complete. */ |
617 | /* Ignore soft CURL errors as many connection shouldn't get any response. | 639 | /* Ignore soft CURL errors as many connection shouldn't get any response. |
618 | * Hard failures are detected in processing function. */ | 640 | * Hard failures are detected in processing function. */ |
@@ -1031,6 +1053,7 @@ main (int argc, char *const *argv) | |||
1031 | cleanup_test = has_in_name (argv[0], "_cleanup"); | 1053 | cleanup_test = has_in_name (argv[0], "_cleanup"); |
1032 | /* There are almost nothing that could be tested externally | 1054 | /* There are almost nothing that could be tested externally |
1033 | * for final cleanup. Cleanup test actually just tests that | 1055 | * for final cleanup. Cleanup test actually just tests that |
1056 | * all added client connections were closed by MHD and | ||
1034 | * nothing fails or crashes when final cleanup is performed. | 1057 | * nothing fails or crashes when final cleanup is performed. |
1035 | * Mostly useful when configured with '--enable-asserts. */ | 1058 | * Mostly useful when configured with '--enable-asserts. */ |
1036 | slow_reply = cleanup_test; | 1059 | slow_reply = cleanup_test; |