diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-15 15:31:33 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-15 15:32:17 +0200 |
commit | 7cd83e15139447156ca915ce2d9d19295c146d56 (patch) | |
tree | 277f35dcc6c59d93cf5ef0232daa525079342f97 /src/tcp_server.c | |
parent | command: adjust order of parameters to handlers (diff) | |
download | cimple-7cd83e15139447156ca915ce2d9d19295c146d56.tar.gz cimple-7cd83e15139447156ca915ce2d9d19295c146d56.zip |
rework server-worker communication
OK, this is a major rework.
* tcp_server: connection threads are not detached anymore, the caller has
to clean them up. This was done so that the server can clean up the
threads cleanly.
* run_queue: simple refactoring, run_queue_entry is called just run now.
* server: worker threads are now killed when a run is assigned to a
worker.
* worker: the connection to server is no longer persistent. A worker
sends "new-worker", waits for a task, closes the connection, and when
it's done, sends the "complete" message and waits for a new task.
This is supposed to improve resilience, since the worker-server
connections don't have to be maintained while the worker is doing a CI
run.
Diffstat (limited to 'src/tcp_server.c')
-rw-r--r-- | src/tcp_server.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/tcp_server.c b/src/tcp_server.c index 25a74a7..d840414 100644 --- a/src/tcp_server.c +++ b/src/tcp_server.c @@ -62,19 +62,18 @@ static void *connection_thread(void *_ctx) ret = signal_block_child(); if (ret < 0) - goto close; + goto free_ctx; ctx->handler(ctx->fd, ctx->arg); -close: - log_errno_if(close(ctx->fd), "close"); +free_ctx: free(ctx); + return NULL; } int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler handler, void *arg) { - pthread_attr_t child_attr; sigset_t old_mask; pthread_t child; int ret = 0; @@ -93,23 +92,11 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h goto free_ctx; ctx->fd = ret; - ret = pthread_attr_init(&child_attr); - if (ret) { - pthread_errno(ret, "pthread_attr_init"); - goto close_conn; - } - - ret = pthread_attr_setdetachstate(&child_attr, PTHREAD_CREATE_DETACHED); - if (ret) { - pthread_errno(ret, "pthread_attr_setdetachstate"); - goto destroy_attr; - } - ret = signal_block_parent(&old_mask); if (ret < 0) - goto destroy_attr; + goto close_conn; - ret = pthread_create(&child, &child_attr, connection_thread, ctx); + ret = pthread_create(&child, NULL, connection_thread, ctx); if (ret) { pthread_errno(ret, "pthread_create"); goto restore_mask; @@ -117,16 +104,11 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h signal_set(&old_mask, NULL); - pthread_errno_if(pthread_attr_destroy(&child_attr), "pthread_attr_destroy"); - return ret; restore_mask: signal_set(&old_mask, NULL); -destroy_attr: - pthread_errno_if(pthread_attr_destroy(&child_attr), "pthread_attr_destroy"); - close_conn: log_errno_if(close(ctx->fd), "close"); |