comparison src/c/driver.c @ 272:4d80d6122df1

Initializing database connection
author Adam Chlipala <adamc@hcoop.net>
date Tue, 02 Sep 2008 11:57:25 -0400
parents 71bafe66dbe1
children 9ad92047a499
comparison
equal deleted inserted replaced
271:42dfb0d61cf0 272:4d80d6122df1
50 static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER; 50 static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER;
51 51
52 #define MAX_RETRIES 5 52 #define MAX_RETRIES 5
53 53
54 static void *worker(void *data) { 54 static void *worker(void *data) {
55 int me = *(int *)data; 55 int me = *(int *)data, retries_left = MAX_RETRIES;;
56 lw_context ctx = lw_init(1024, 1024); 56 lw_context ctx = lw_init(1024, 1024);
57
58 while (1) {
59 failure_kind fk = lw_begin_init(ctx);
60
61 if (fk == SUCCESS) {
62 lw_db_init(ctx);
63 printf("Database connection initialized.\n");
64 break;
65 } else if (fk == BOUNDED_RETRY) {
66 if (retries_left) {
67 printf("Initialization error triggers bounded retry: %s\n", lw_error_message(ctx));
68 --retries_left;
69 } else {
70 printf("Fatal initialization error (out of retries): %s\n", lw_error_message(ctx));
71 lw_free(ctx);
72 return NULL;
73 }
74 } else if (fk == UNLIMITED_RETRY)
75 printf("Initialization error triggers unlimited retry: %s\n", lw_error_message(ctx));
76 else if (fk == FATAL) {
77 printf("Fatal initialization error: %s\n", lw_error_message(ctx));
78 lw_free(ctx);
79 return NULL;
80 } else {
81 printf("Unknown lw_handle return code!\n");
82 lw_free(ctx);
83 return NULL;
84 }
85 }
57 86
58 while (1) { 87 while (1) {
59 char buf[lw_bufsize+1], *back = buf, *s; 88 char buf[lw_bufsize+1], *back = buf, *s;
60 int sock; 89 int sock;
61 90