diff src/c/driver.c @ 667:a93d5324f400

Dummy message delivery to clients
author Adam Chlipala <adamc@hcoop.net>
date Thu, 19 Mar 2009 16:34:13 -0400
parents 162d5308e34f
children b0c1a46b1f15
line wrap: on
line diff
--- a/src/c/driver.c	Thu Mar 19 13:47:02 2009 -0400
+++ b/src/c/driver.c	Thu Mar 19 16:34:13 2009 -0400
@@ -106,7 +106,7 @@
 
   while (1) {
     char buf[uw_bufsize+1], *back = buf, *s;
-    int sock;
+    int sock, dont_close = 0;
 
     pthread_mutex_lock(&queue_mutex);
     while (empty())
@@ -138,6 +138,7 @@
       if (s = strstr(buf, "\r\n\r\n")) {
         failure_kind fk;
         char *cmd, *path, *headers, path_copy[uw_bufsize+1], *inputs;
+        int id, pass;
 
         s[2] = 0;
 
@@ -168,6 +169,12 @@
           break;
         }
 
+        if (sscanf(path, "/.msgs/%d/%d", &id, &pass) == 2) {
+          uw_client_connect(id, pass, sock);
+          dont_close = 1;
+          break;
+        }
+
         if (inputs = strchr(path, '?')) {
           char *name, *value;
           *inputs++ = 0;
@@ -286,11 +293,19 @@
       }
     }
 
-    close(sock);
+    if (!dont_close)
+      close(sock);
     uw_reset(ctx);
   }
 }
 
+static void *client_pruner(void *data) {
+  while (1) {
+    uw_prune_clients(5);
+    sleep(5);
+  }
+}
+
 static void help(char *cmd) {
   printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd);
 }
@@ -377,8 +392,20 @@
 
   sin_size = sizeof their_addr;
 
+  uw_global_init();
+
   printf("Listening on port %d....\n", uw_port);
 
+  {
+    pthread_t thread;
+    int name;
+
+    if (pthread_create(&thread, NULL, client_pruner, &name)) {
+      fprintf(stderr, "Error creating pruner thread\n");
+      return 1;
+    }
+  }
+
   for (i = 0; i < nthreads; ++i) {
     pthread_t thread;    
     names[i] = i;