summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-10-17 11:18:09 +0200
committerdefault <nobody@localhost>2022-10-17 11:18:09 +0200
commitc7ff714710f42368b15f7f778c6b8528e045ab77 (patch)
tree1e5abd6b50735acfe27687bc2ad0b47575424147 /httpd.c
parent3462ecc950676be944766b0ef7999e1382682e19 (diff)
New thread for purge.
Diffstat (limited to 'httpd.c')
-rw-r--r--httpd.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/httpd.c b/httpd.c
index 4233057..a365b4d 100644
--- a/httpd.c
+++ b/httpd.c
@@ -207,18 +207,37 @@ void term_handler(int s)
}
+static void *purge_thread(void *arg)
+/* spawned purge */
+{
+ srv_log(xs_dup("purge start"));
+
+ purge_all();
+
+ srv_log(xs_dup("purge end"));
+
+ return NULL;
+}
+
+
static void *queue_thread(void *arg)
/* queue thread (queue management) */
{
pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER;
+ time_t purge_time;
+
+ /* first purge time */
+ purge_time = time(NULL) + 15 * 60;
srv_log(xs_fmt("queue thread start"));
while (srv_running) {
xs *list = user_list();
char *p, *uid;
+ time_t t;
+ /* process queues for all users */
p = list;
while (xs_list_iter(&p, &uid)) {
snac snac;
@@ -229,6 +248,16 @@ static void *queue_thread(void *arg)
}
}
+ /* time to purge? */
+ if ((t = time(NULL)) > purge_time) {
+ pthread_t pth;
+
+ pthread_create(&pth, NULL, purge_thread, NULL);
+
+ /* next purge time is tomorrow */
+ purge_time = t + 24 * 60 * 60;
+ }
+
/* sleep 3 seconds */
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);