summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--TODO.md6
-rw-r--r--httpd.c34
3 files changed, 38 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index d0e09d2..9f729b5 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ CFLAGS=-g -Wall
3all: snac 3all: snac
4 4
5snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o html.o 5snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o html.o
6 $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@ 6 $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -pthread -o $@
7 7
8.c.o: 8.c.o:
9 $(CC) $(CFLAGS) -I/usr/local/include -c $< 9 $(CC) $(CFLAGS) -I/usr/local/include -c $<
diff --git a/TODO.md b/TODO.md
index 49c3771..ea37fe2 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,14 +2,14 @@
2 2
3## Open 3## Open
4 4
5Implement the helper thread.
6
7Import the man pages. 5Import the man pages.
8 6
9Implement the 'init' command-line option. 7Implement the 'init' command-line option.
10 8
11Implement the 'adduser' command-line option. 9Implement the 'adduser' command-line option.
12 10
11Implement the local timeline cache.
12
13Show dates in local time and not UTC. 13Show dates in local time and not UTC.
14 14
15Add web interface for private messages. 15Add web interface for private messages.
@@ -131,3 +131,5 @@ Add a user configuration flag to hide likes from the timeline (2022-10-01T20:27:
131Implement an input queue (2022-10-01T20:27:52+0200). 131Implement an input queue (2022-10-01T20:27:52+0200).
132 132
133Refactor HTML rendering because it's a mess and write build_timeline(), that generates a big structure with everything to show in a timeline, to be passed to the HTML renderer (2022-10-01T20:27:52+0200). 133Refactor HTML rendering because it's a mess and write build_timeline(), that generates a big structure with everything to show in a timeline, to be passed to the HTML renderer (2022-10-01T20:27:52+0200).
134
135Implement the helper thread (2022-10-01T20:56:46+0200).
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}