diff src/c/driver.c @ 698:9b29ce0babb8

RoundTrip demo
author Adam Chlipala <adamc@hcoop.net>
date Sun, 05 Apr 2009 11:24:55 -0400
parents a3ddf05fb3e3
children db6ab16cd8f3
line wrap: on
line diff
--- a/src/c/driver.c	Sun Apr 05 10:48:11 2009 -0400
+++ b/src/c/driver.c	Sun Apr 05 11:24:55 2009 -0400
@@ -67,15 +67,14 @@
   return r;
 }
 
-static void *worker(void *data) {
-  int me = *(int *)data, retries_left = MAX_RETRIES;
+static uw_context new_context() {
   uw_context ctx = uw_init();
-  
+  int retries_left = MAX_RETRIES;
+
   while (1) {
     failure_kind fk = uw_begin_init(ctx);
 
     if (fk == SUCCESS) {
-      uw_db_init(ctx);
       printf("Database connection initialized.\n");
       break;
     } else if (fk == BOUNDED_RETRY) {
@@ -94,12 +93,19 @@
       uw_free(ctx);
       return NULL;
     } else {
-      printf("Unknown uw_handle return code!\n");
+      printf("Unknown uw_begin_init return code!\n");
       uw_free(ctx);
       return NULL;
     }
   }
 
+  return ctx;
+}
+
+static void *worker(void *data) {
+  int me = *(int *)data, retries_left = MAX_RETRIES;
+  uw_context ctx = new_context();
+
   while (1) {
     char buf[uw_bufsize+1], *back = buf, *s;
     int sock, dont_close = 0;
@@ -278,8 +284,10 @@
 }
 
 static void *client_pruner(void *data) {
-  uw_context ctx = uw_init();
-  uw_db_init(ctx);
+  uw_context ctx = new_context();
+
+  if (!ctx)
+    exit(1);
 
   while (1) {
     uw_prune_clients(ctx);
@@ -297,9 +305,11 @@
 }
 
 static void initialize() {
-  uw_context ctx = uw_init();
+  uw_context ctx = new_context();
 
-  uw_db_init(ctx);
+  if (!ctx)
+    exit(1);
+
   if (uw_initialize(ctx) != SUCCESS) {
     printf("Failed to initialize database!\n");
     uw_db_rollback(ctx);