diff 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
line wrap: on
line diff
--- a/src/c/urweb.c	Sun Jan 03 15:32:11 2010 -0500
+++ b/src/c/urweb.c	Sun Jan 03 15:58:34 2010 -0500
@@ -9,6 +9,7 @@
 #include <stdarg.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -338,6 +339,8 @@
   app->client_init();
 }
 
+int uw_time = 0;
+
 
 // Single-request state
 
@@ -427,6 +430,8 @@
 
   char *current_url;
 
+  int deadline;
+
   char error_message[ERROR_BUF_LEN];
 };
 
@@ -484,6 +489,8 @@
 
   ctx->current_url = "";
 
+  ctx->deadline = INT_MAX;
+
   return ctx;
 }
 
@@ -3343,3 +3350,12 @@
 void uw_set_currentUrl(uw_context ctx, char *s) {
   ctx->current_url = s;
 }
+
+void uw_set_deadline(uw_context ctx, int n) {
+  ctx->deadline = n;
+}
+
+void uw_check_deadline(uw_context ctx) {
+  if (uw_time > ctx->deadline)
+    uw_error(ctx, FATAL, "Maximum running time exceeded");
+}