summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authorGravatar default2022-10-01 20:57:06 +0200
committerGravatar default2022-10-01 20:57:06 +0200
commit8bb758206289ad85ebd4624c2673eef42660df9f (patch)
tree40525be70f3ff396b308adf9eb018ca1a3756c5e /httpd.c
parentUpdated TODO. (diff)
downloadsnac2-8bb758206289ad85ebd4624c2673eef42660df9f.tar.gz
snac2-8bb758206289ad85ebd4624c2673eef42660df9f.tar.xz
snac2-8bb758206289ad85ebd4624c2673eef42660df9f.zip
Implemented the helper thread.
Diffstat (limited to 'httpd.c')
-rw-r--r--httpd.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/httpd.c b/httpd.c
index a57b4c1..f6f9a18 100644
--- a/httpd.c
+++ b/httpd.c
@@ -11,6 +11,7 @@
11#include "snac.h" 11#include "snac.h"
12 12
13#include <setjmp.h> 13#include <setjmp.h>
14#include <pthread.h>
14 15
15/* susie.png */ 16/* susie.png */
16const char *susie = 17const char *susie =
@@ -199,12 +200,41 @@ void term_handler(int s)
199} 200}
200 201
201 202
203static void *helper_thread(void *arg)
204/* helper thread (queue management) */
205{
206 srv_log(xs_fmt("subthread start"));
207
208 while (srv_running) {
209 xs *list = user_list();
210 char *p, *uid;
211
212 p = list;
213 while (xs_list_iter(&p, &uid)) {
214 snac snac;
215
216 if (user_open(&snac, uid)) {
217 process_queue(&snac);
218 user_free(&snac);
219 }
220 }
221
222 sleep(3);
223 }
224
225 srv_log(xs_fmt("subthread stop"));
226
227 return NULL;
228}
229
230
202void httpd(void) 231void httpd(void)
203/* starts the server */ 232/* starts the server */
204{ 233{
205 char *address; 234 char *address;
206 int port; 235 int port;
207 int rs; 236 int rs;
237 pthread_t htid;
208 238
209 address = xs_dict_get(srv_config, "address"); 239 address = xs_dict_get(srv_config, "address");
210 port = xs_number_get(xs_dict_get(srv_config, "port")); 240 port = xs_number_get(xs_dict_get(srv_config, "port"));
@@ -222,6 +252,8 @@ void httpd(void)
222 252
223 srv_log(xs_fmt("httpd start %s:%d", address, port)); 253 srv_log(xs_fmt("httpd start %s:%d", address, port));
224 254
255 pthread_create(&htid, NULL, helper_thread, NULL);
256
225 if (setjmp(on_break) == 0) { 257 if (setjmp(on_break) == 0) {
226 for (;;) { 258 for (;;) {
227 httpd_connection(rs); 259 httpd_connection(rs);
@@ -231,7 +263,7 @@ void httpd(void)
231 srv_running = 0; 263 srv_running = 0;
232 264
233 /* wait for the helper thread to end */ 265 /* wait for the helper thread to end */
234 /* ... */ 266 pthread_join(htid, NULL);
235 267
236 srv_log(xs_fmt("httpd stop %s:%d", address, port)); 268 srv_log(xs_fmt("httpd stop %s:%d", address, port));
237} 269}