aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tcp_server.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 15:45:23 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 11:46:32 +0200
commitfef10b7a84804b937375bc996df32da6cfab4dab (patch)
tree722cbabc7f1b0cf5091b3b7c04b3f9a87b37c8c5 /src/tcp_server.c
parentcame up with a new name: cimple (diff)
downloadcimple-fef10b7a84804b937375bc996df32da6cfab4dab.tar.gz
cimple-fef10b7a84804b937375bc996df32da6cfab4dab.zip
server: shutting down more gracefully
Diffstat (limited to '')
-rw-r--r--src/tcp_server.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/tcp_server.c b/src/tcp_server.c
index 633b7f2..47317e7 100644
--- a/src/tcp_server.c
+++ b/src/tcp_server.c
@@ -1,6 +1,7 @@
#include "tcp_server.h"
#include "log.h"
#include "net.h"
+#include "signal.h"
#include <pthread.h>
#include <stdlib.h>
@@ -43,10 +44,8 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h
int conn_fd, ret = 0;
ret = net_accept(server->fd);
- if (ret < 0) {
- print_errno("accept");
+ if (ret < 0)
return ret;
- }
conn_fd = ret;
ctx = malloc(sizeof(*ctx));
@@ -69,6 +68,10 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h
goto destroy_attr;
}
+ ret = signal_set_thread_attr(&child_attr);
+ if (ret < 0)
+ goto destroy_attr;
+
ret = pthread_create(&child, &child_attr, connection_thread, ctx);
if (ret) {
pthread_print_errno(ret, "pthread_create");