aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/c/request.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-10-14 11:35:56 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2010-10-14 11:35:56 -0400
commitcfffcb997d0345f90444725248c7c85b035c30b4 (patch)
tree3e839cc2566526f3e4a294229c41f88e60e8d24e /src/c/request.c
parent7bf0a0124a6c8a834983a660af53d8789ac0a8ac (diff)
-limit for running time
Diffstat (limited to 'src/c/request.c')
-rw-r--r--src/c/request.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/c/request.c b/src/c/request.c
index f72a3199..190a327f 100644
--- a/src/c/request.c
+++ b/src/c/request.c
@@ -70,6 +70,15 @@ uw_context uw_request_new_context(uw_app *app, void *logger_data, uw_logger log_
return ctx;
}
+static void *ticker(void *data) {
+ while (1) {
+ usleep(100000);
+ ++uw_time;
+ }
+
+ return NULL;
+}
+
void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) {
uw_context ctx;
failure_kind fk;
@@ -77,6 +86,15 @@ void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_log
uw_global_init();
uw_app_init(app);
+ {
+ pthread_t thread;
+
+ if (uw_time_max && pthread_create(&thread, NULL, ticker, NULL)) {
+ fprintf(stderr, "Error creating ticker thread\n");
+ exit(1);
+ }
+ }
+
ctx = uw_request_new_context(app, logger_data, log_error, log_debug);
if (!ctx)
@@ -348,15 +366,18 @@ request_result uw_request(uw_request_context rc, uw_context ctx,
rc->path_copy = realloc(rc->path_copy, rc->path_copy_size);
}
strcpy(rc->path_copy, path);
+
+ uw_set_deadline(ctx, uw_time + uw_time_max);
fk = uw_begin(ctx, rc->path_copy);
- } else
+ } else {
+ uw_set_deadline(ctx, uw_time + uw_time_max);
fk = uw_begin_onError(ctx, errmsg);
+ }
if (fk == SUCCESS || fk == RETURN_INDIRECTLY) {
uw_commit(ctx);
if (uw_has_error(ctx) && !had_error) {
log_error(logger_data, "Fatal error: %s\n", uw_error_message(ctx));
-
uw_reset_keep_error_message(ctx);
on_failure(ctx);