diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | TODO.md | 6 | ||||
| -rw-r--r-- | httpd.c | 34 |
3 files changed, 38 insertions, 4 deletions
| @@ -3,7 +3,7 @@ CFLAGS=-g -Wall | |||
| 3 | all: snac | 3 | all: snac |
| 4 | 4 | ||
| 5 | snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o html.o | 5 | snac: 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 $< |
| @@ -2,14 +2,14 @@ | |||
| 2 | 2 | ||
| 3 | ## Open | 3 | ## Open |
| 4 | 4 | ||
| 5 | Implement the helper thread. | ||
| 6 | |||
| 7 | Import the man pages. | 5 | Import the man pages. |
| 8 | 6 | ||
| 9 | Implement the 'init' command-line option. | 7 | Implement the 'init' command-line option. |
| 10 | 8 | ||
| 11 | Implement the 'adduser' command-line option. | 9 | Implement the 'adduser' command-line option. |
| 12 | 10 | ||
| 11 | Implement the local timeline cache. | ||
| 12 | |||
| 13 | Show dates in local time and not UTC. | 13 | Show dates in local time and not UTC. |
| 14 | 14 | ||
| 15 | Add web interface for private messages. | 15 | Add web interface for private messages. |
| @@ -131,3 +131,5 @@ Add a user configuration flag to hide likes from the timeline (2022-10-01T20:27: | |||
| 131 | Implement an input queue (2022-10-01T20:27:52+0200). | 131 | Implement an input queue (2022-10-01T20:27:52+0200). |
| 132 | 132 | ||
| 133 | Refactor 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). | 133 | Refactor 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 | |||
| 135 | Implement the helper thread (2022-10-01T20:56:46+0200). | ||
| @@ -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 */ |
| 16 | const char *susie = | 17 | const char *susie = |
| @@ -199,12 +200,41 @@ void term_handler(int s) | |||
| 199 | } | 200 | } |
| 200 | 201 | ||
| 201 | 202 | ||
| 203 | static 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 | |||
| 202 | void httpd(void) | 231 | void 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 | } |