summaryrefslogtreecommitdiff
path: root/src/c/request.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c/request.c')
-rw-r--r--src/c/request.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/c/request.c b/src/c/request.c
index e51f95ae..b49a524e 100644
--- a/src/c/request.c
+++ b/src/c/request.c
@@ -79,9 +79,44 @@ static void *ticker(void *data) {
return NULL;
}
+typedef struct {
+ uw_app *app;
+ void *logger_data;
+ uw_logger log_error, log_debug;
+} loggers;
+
+typedef struct {
+ loggers *ls;
+ uw_periodic pdic;
+} periodic;
+
+static void *periodic_loop(void *data) {
+ periodic *p = (periodic *)data;
+ uw_context ctx = uw_request_new_context(p->ls->app, p->ls->logger_data, p->ls->log_error, p->ls->log_debug);
+
+ if (!ctx)
+ exit(1);
+
+ while (1) {
+ failure_kind r;
+ do {
+ r = uw_runCallback(ctx, p->pdic.callback);
+ } while (r == UNLIMITED_RETRY);
+
+ sleep(p->pdic.period);
+ };
+}
+
void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) {
uw_context ctx;
failure_kind fk;
+ uw_periodic *ps;
+ loggers *ls = malloc(sizeof(loggers));
+
+ ls->app = app;
+ ls->logger_data = logger_data;
+ ls->log_error = log_error;
+ ls->log_debug = log_debug;
uw_global_init();
uw_app_init(app);
@@ -113,6 +148,18 @@ void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_log
}
uw_free(ctx);
+
+ for (ps = app->periodics; ps->callback; ++ps) {
+ pthread_t thread;
+ periodic *arg = malloc(sizeof(periodic));
+ arg->ls = ls;
+ arg->pdic = *ps;
+
+ if (pthread_create(&thread, NULL, periodic_loop, arg)) {
+ fprintf(stderr, "Error creating periodic thread\n");
+ exit(1);
+ }
+ }
}
@@ -468,12 +515,6 @@ request_result uw_request(uw_request_context rc, uw_context ctx,
}
}
-typedef struct {
- uw_app *app;
- void *logger_data;
- uw_logger log_error, log_debug;
-} loggers;
-
void *client_pruner(void *data) {
loggers *ls = (loggers *)data;
uw_context ctx = uw_request_new_context(ls->app, ls->logger_data, ls->log_error, ls->log_debug);