diff options
author | default <nobody@localhost> | 2022-10-10 19:50:37 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-10-10 19:50:37 +0200 |
commit | 1e9d21147ba24664bdeb64b49bae52992e2bec4e (patch) | |
tree | 90ee56ebb8fd27f7a602fb0bc2e0c4a18f47e724 | |
parent | 95d0ce838265d07352aa7d8b3ecd344dae3441e3 (diff) |
Connections are now attended by threads.
-rw-r--r-- | httpd.c | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -197,10 +197,10 @@ void term_handler(int s) } -static void *helper_thread(void *arg) -/* helper thread (queue management) */ +static void *queue_thread(void *arg) +/* queue thread (queue management) */ { - srv_log(xs_fmt("subthread start")); + srv_log(xs_fmt("queue thread start")); while (srv_running) { xs *list = user_list(); @@ -219,12 +219,22 @@ static void *helper_thread(void *arg) sleep(3); } - srv_log(xs_fmt("subthread stop")); + srv_log(xs_fmt("queue thread stop")); return NULL; } +static void *connection_thread(void *arg) +/* connection thread */ +{ + httpd_connection((FILE *)arg); + return NULL; +} + + +int threaded_connections = 1; + void httpd(void) /* starts the server */ { @@ -249,13 +259,19 @@ void httpd(void) srv_log(xs_fmt("httpd start %s:%d", address, port)); - pthread_create(&htid, NULL, helper_thread, NULL); + pthread_create(&htid, NULL, queue_thread, NULL); if (setjmp(on_break) == 0) { for (;;) { FILE *f = xs_socket_accept(rs); - httpd_connection(f); + if (threaded_connections) { + pthread_t cth; + + pthread_create(&cth, NULL, connection_thread, f); + } + else + httpd_connection(f); } } |