Implemented the helper thread.

This commit is contained in:
default 2022-10-01 20:57:06 +02:00
parent 31f29258a1
commit 8bb7582062
3 changed files with 38 additions and 4 deletions

View file

@ -3,7 +3,7 @@ CFLAGS=-g -Wall
all: snac all: snac
snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o html.o snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o html.o
$(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@ $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -pthread -o $@
.c.o: .c.o:
$(CC) $(CFLAGS) -I/usr/local/include -c $< $(CC) $(CFLAGS) -I/usr/local/include -c $<

View file

@ -2,14 +2,14 @@
## Open ## Open
Implement the helper thread.
Import the man pages. Import the man pages.
Implement the 'init' command-line option. Implement the 'init' command-line option.
Implement the 'adduser' command-line option. Implement the 'adduser' command-line option.
Implement the local timeline cache.
Show dates in local time and not UTC. Show dates in local time and not UTC.
Add web interface for private messages. 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:
Implement an input queue (2022-10-01T20:27:52+0200). Implement an input queue (2022-10-01T20:27:52+0200).
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). 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).
Implement the helper thread (2022-10-01T20:56:46+0200).

34
httpd.c
View file

@ -11,6 +11,7 @@
#include "snac.h" #include "snac.h"
#include <setjmp.h> #include <setjmp.h>
#include <pthread.h>
/* susie.png */ /* susie.png */
const char *susie = const char *susie =
@ -199,12 +200,41 @@ void term_handler(int s)
} }
static void *helper_thread(void *arg)
/* helper thread (queue management) */
{
srv_log(xs_fmt("subthread start"));
while (srv_running) {
xs *list = user_list();
char *p, *uid;
p = list;
while (xs_list_iter(&p, &uid)) {
snac snac;
if (user_open(&snac, uid)) {
process_queue(&snac);
user_free(&snac);
}
}
sleep(3);
}
srv_log(xs_fmt("subthread stop"));
return NULL;
}
void httpd(void) void httpd(void)
/* starts the server */ /* starts the server */
{ {
char *address; char *address;
int port; int port;
int rs; int rs;
pthread_t htid;
address = xs_dict_get(srv_config, "address"); address = xs_dict_get(srv_config, "address");
port = xs_number_get(xs_dict_get(srv_config, "port")); port = xs_number_get(xs_dict_get(srv_config, "port"));
@ -222,6 +252,8 @@ void httpd(void)
srv_log(xs_fmt("httpd start %s:%d", address, port)); srv_log(xs_fmt("httpd start %s:%d", address, port));
pthread_create(&htid, NULL, helper_thread, NULL);
if (setjmp(on_break) == 0) { if (setjmp(on_break) == 0) {
for (;;) { for (;;) {
httpd_connection(rs); httpd_connection(rs);
@ -231,7 +263,7 @@ void httpd(void)
srv_running = 0; srv_running = 0;
/* wait for the helper thread to end */ /* wait for the helper thread to end */
/* ... */ pthread_join(htid, NULL);
srv_log(xs_fmt("httpd stop %s:%d", address, port)); srv_log(xs_fmt("httpd stop %s:%d", address, port));
} }