]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Make TLS echo server cancelable
authorTobias Brunner <tobias@strongswan.org>
Mon, 5 Sep 2022 15:10:21 +0000 (17:10 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 6 Sep 2022 07:33:00 +0000 (09:33 +0200)
Seems to be required on macOS (libtls tests didn't run before the recent
implicit enabling via pki).  Other platforms apparently let accept() fail
if the socket is shutdown/closed in teardown_creds(), macOS apparently
doesn't do that.

src/libtls/tests/suites/test_socket.c

index a9f44c07c21237d4cfaa49141fb2c36d6e40c5c5..369685fff2cfd6cdaafed1e092ab0d4238dd2ffd 100644 (file)
@@ -20,6 +20,7 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <threading/thread.h>
 #include <processing/jobs/callback_job.h>
 #include <credentials/sets/mem_cred.h>
 
@@ -509,6 +510,7 @@ static job_requeue_t serve_echo(echo_server_config_t *config)
        identification_t *server, *client = NULL;
        ssize_t len, total, done;
        char buf[128];
+       bool oldstate;
 
        server = identification_create_from_string(config->addr);
        if (config->cauth)
@@ -516,9 +518,12 @@ static job_requeue_t serve_echo(echo_server_config_t *config)
                client = server;
        }
        sfd = config->fd;
+       thread_cleanup_push((thread_cleanup_t)server->destroy, server);
        while (TRUE)
        {
+               oldstate = thread_cancelability(TRUE);
                cfd = accept(sfd, NULL, NULL);
+               thread_cancelability(oldstate);
                if (cfd < 0)
                {
                        break;
@@ -548,7 +553,7 @@ static job_requeue_t serve_echo(echo_server_config_t *config)
                tls->destroy(tls);
                close(cfd);
        }
-       server->destroy(server);
+       thread_cleanup_pop(TRUE);
 
        return JOB_REQUEUE_NONE;
 }
@@ -575,7 +580,8 @@ static void start_echo_server(echo_server_config_t *config)
        lib->processor->set_threads(lib->processor, 8);
 
        lib->processor->queue_job(lib->processor, (job_t*)
-                               callback_job_create((void*)serve_echo, config, NULL, NULL));
+                               callback_job_create((void*)serve_echo, config, NULL,
+                                                                       (callback_job_cancel_t)return_false));
 }
 
 /**