Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
697:755a71c99be5 | 698:9b29ce0babb8 |
---|---|
65 } | 65 } |
66 | 66 |
67 return r; | 67 return r; |
68 } | 68 } |
69 | 69 |
70 static void *worker(void *data) { | 70 static uw_context new_context() { |
71 int me = *(int *)data, retries_left = MAX_RETRIES; | |
72 uw_context ctx = uw_init(); | 71 uw_context ctx = uw_init(); |
73 | 72 int retries_left = MAX_RETRIES; |
73 | |
74 while (1) { | 74 while (1) { |
75 failure_kind fk = uw_begin_init(ctx); | 75 failure_kind fk = uw_begin_init(ctx); |
76 | 76 |
77 if (fk == SUCCESS) { | 77 if (fk == SUCCESS) { |
78 uw_db_init(ctx); | |
79 printf("Database connection initialized.\n"); | 78 printf("Database connection initialized.\n"); |
80 break; | 79 break; |
81 } else if (fk == BOUNDED_RETRY) { | 80 } else if (fk == BOUNDED_RETRY) { |
82 if (retries_left) { | 81 if (retries_left) { |
83 printf("Initialization error triggers bounded retry: %s\n", uw_error_message(ctx)); | 82 printf("Initialization error triggers bounded retry: %s\n", uw_error_message(ctx)); |
92 else if (fk == FATAL) { | 91 else if (fk == FATAL) { |
93 printf("Fatal initialization error: %s\n", uw_error_message(ctx)); | 92 printf("Fatal initialization error: %s\n", uw_error_message(ctx)); |
94 uw_free(ctx); | 93 uw_free(ctx); |
95 return NULL; | 94 return NULL; |
96 } else { | 95 } else { |
97 printf("Unknown uw_handle return code!\n"); | 96 printf("Unknown uw_begin_init return code!\n"); |
98 uw_free(ctx); | 97 uw_free(ctx); |
99 return NULL; | 98 return NULL; |
100 } | 99 } |
101 } | 100 } |
101 | |
102 return ctx; | |
103 } | |
104 | |
105 static void *worker(void *data) { | |
106 int me = *(int *)data, retries_left = MAX_RETRIES; | |
107 uw_context ctx = new_context(); | |
102 | 108 |
103 while (1) { | 109 while (1) { |
104 char buf[uw_bufsize+1], *back = buf, *s; | 110 char buf[uw_bufsize+1], *back = buf, *s; |
105 int sock, dont_close = 0; | 111 int sock, dont_close = 0; |
106 | 112 |
276 uw_reset(ctx); | 282 uw_reset(ctx); |
277 } | 283 } |
278 } | 284 } |
279 | 285 |
280 static void *client_pruner(void *data) { | 286 static void *client_pruner(void *data) { |
281 uw_context ctx = uw_init(); | 287 uw_context ctx = new_context(); |
282 uw_db_init(ctx); | 288 |
289 if (!ctx) | |
290 exit(1); | |
283 | 291 |
284 while (1) { | 292 while (1) { |
285 uw_prune_clients(ctx); | 293 uw_prune_clients(ctx); |
286 sleep(5); | 294 sleep(5); |
287 } | 295 } |
295 printf("Exiting....\n"); | 303 printf("Exiting....\n"); |
296 exit(0); | 304 exit(0); |
297 } | 305 } |
298 | 306 |
299 static void initialize() { | 307 static void initialize() { |
300 uw_context ctx = uw_init(); | 308 uw_context ctx = new_context(); |
301 | 309 |
302 uw_db_init(ctx); | 310 if (!ctx) |
311 exit(1); | |
312 | |
303 if (uw_initialize(ctx) != SUCCESS) { | 313 if (uw_initialize(ctx) != SUCCESS) { |
304 printf("Failed to initialize database!\n"); | 314 printf("Failed to initialize database!\n"); |
305 uw_db_rollback(ctx); | 315 uw_db_rollback(ctx); |
306 exit(1); | 316 exit(1); |
307 } | 317 } |