diff options
author | Adam Chlipala <adam@chlipala.net> | 2010-10-14 11:35:56 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2010-10-14 11:35:56 -0400 |
commit | cfffcb997d0345f90444725248c7c85b035c30b4 (patch) | |
tree | 3e839cc2566526f3e4a294229c41f88e60e8d24e /src/c | |
parent | 7bf0a0124a6c8a834983a660af53d8789ac0a8ac (diff) |
-limit for running time
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/request.c | 25 | ||||
-rw-r--r-- | src/c/urweb.c | 2 |
2 files changed, 24 insertions, 3 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); diff --git a/src/c/urweb.c b/src/c/urweb.c index 747f62b6..bdaa877f 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -348,7 +348,7 @@ void uw_app_init(uw_app *app) { app->client_init(); } -int uw_time = 0; +int uw_time = 0, uw_time_max = 0; // Single-request state |