comparison src/c/urweb.c @ 1114:01b6c7144a44

Deadlines
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 Jan 2010 15:58:34 -0500
parents 40d48a2b78a7
children 150465f2895c
comparison
equal deleted inserted replaced
1113:40d48a2b78a7 1114:01b6c7144a44
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <setjmp.h> 8 #include <setjmp.h>
9 #include <stdarg.h> 9 #include <stdarg.h>
10 #include <assert.h> 10 #include <assert.h>
11 #include <ctype.h> 11 #include <ctype.h>
12 #include <limits.h>
12 #include <stdint.h> 13 #include <stdint.h>
13 #include <sys/types.h> 14 #include <sys/types.h>
14 #include <sys/socket.h> 15 #include <sys/socket.h>
15 16
16 #include <pthread.h> 17 #include <pthread.h>
335 } 336 }
336 337
337 void uw_app_init(uw_app *app) { 338 void uw_app_init(uw_app *app) {
338 app->client_init(); 339 app->client_init();
339 } 340 }
341
342 int uw_time = 0;
340 343
341 344
342 // Single-request state 345 // Single-request state
343 346
344 #define ERROR_BUF_LEN 1024 347 #define ERROR_BUF_LEN 1024
425 global *globals; 428 global *globals;
426 size_t n_globals; 429 size_t n_globals;
427 430
428 char *current_url; 431 char *current_url;
429 432
433 int deadline;
434
430 char error_message[ERROR_BUF_LEN]; 435 char error_message[ERROR_BUF_LEN];
431 }; 436 };
432 437
433 size_t uw_headers_max = SIZE_MAX; 438 size_t uw_headers_max = SIZE_MAX;
434 size_t uw_page_max = SIZE_MAX; 439 size_t uw_page_max = SIZE_MAX;
481 486
482 ctx->globals = malloc(0); 487 ctx->globals = malloc(0);
483 ctx->n_globals = 0; 488 ctx->n_globals = 0;
484 489
485 ctx->current_url = ""; 490 ctx->current_url = "";
491
492 ctx->deadline = INT_MAX;
486 493
487 return ctx; 494 return ctx;
488 } 495 }
489 496
490 size_t uw_inputs_max = SIZE_MAX; 497 size_t uw_inputs_max = SIZE_MAX;
3341 } 3348 }
3342 3349
3343 void uw_set_currentUrl(uw_context ctx, char *s) { 3350 void uw_set_currentUrl(uw_context ctx, char *s) {
3344 ctx->current_url = s; 3351 ctx->current_url = s;
3345 } 3352 }
3353
3354 void uw_set_deadline(uw_context ctx, int n) {
3355 ctx->deadline = n;
3356 }
3357
3358 void uw_check_deadline(uw_context ctx) {
3359 if (uw_time > ctx->deadline)
3360 uw_error(ctx, FATAL, "Maximum running time exceeded");
3361 }