summaryrefslogtreecommitdiff
path: root/src/c/driver.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-04-05 11:24:55 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-04-05 11:24:55 -0400
commita44e147bbb6686867b425b7cf068d14c5f230f51 (patch)
tree629c88474e3f44efa4384f199ee22debb4e240bd /src/c/driver.c
parent18b7332e738d4b97bf3bb9dfa6600277222aab33 (diff)
RoundTrip demo
Diffstat (limited to 'src/c/driver.c')
-rw-r--r--src/c/driver.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/c/driver.c b/src/c/driver.c
index 52999da3..44465cc3 100644
--- a/src/c/driver.c
+++ b/src/c/driver.c
@@ -67,15 +67,14 @@ static int try_rollback(uw_context ctx) {
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 @@ static void *worker(void *data) {
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 *worker(void *data) {
}
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 sigint(int signum) {
}
static void initialize() {
- uw_context ctx = uw_init();
+ uw_context ctx = new_context();
+
+ if (!ctx)
+ exit(1);
- uw_db_init(ctx);
if (uw_initialize(ctx) != SUCCESS) {
printf("Failed to initialize database!\n");
uw_db_rollback(ctx);