Mercurial > urweb
comparison src/c/driver.c @ 687:a3ddf05fb3e3
On start-up, delete/nullify rows mentioning clients or channels
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 02 Apr 2009 11:42:26 -0400 |
parents | 9a2c18dab11d |
children | 9b29ce0babb8 |
comparison
equal
deleted
inserted
replaced
686:3b46548f701b | 687:a3ddf05fb3e3 |
---|---|
67 return r; | 67 return r; |
68 } | 68 } |
69 | 69 |
70 static void *worker(void *data) { | 70 static void *worker(void *data) { |
71 int me = *(int *)data, retries_left = MAX_RETRIES; | 71 int me = *(int *)data, retries_left = MAX_RETRIES; |
72 uw_context ctx = uw_init(0, 0, 1024, 0); | 72 uw_context ctx = uw_init(); |
73 | 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) { |
276 uw_reset(ctx); | 276 uw_reset(ctx); |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 static void *client_pruner(void *data) { | 280 static void *client_pruner(void *data) { |
281 uw_context ctx = uw_init(0, 0, 0, 0); | 281 uw_context ctx = uw_init(); |
282 uw_db_init(ctx); | 282 uw_db_init(ctx); |
283 | 283 |
284 while (1) { | 284 while (1) { |
285 uw_prune_clients(ctx); | 285 uw_prune_clients(ctx); |
286 sleep(5); | 286 sleep(5); |
292 } | 292 } |
293 | 293 |
294 static void sigint(int signum) { | 294 static void sigint(int signum) { |
295 printf("Exiting....\n"); | 295 printf("Exiting....\n"); |
296 exit(0); | 296 exit(0); |
297 } | |
298 | |
299 static void initialize() { | |
300 uw_context ctx = uw_init(); | |
301 | |
302 uw_db_init(ctx); | |
303 if (uw_initialize(ctx) != SUCCESS) { | |
304 printf("Failed to initialize database!\n"); | |
305 uw_db_rollback(ctx); | |
306 exit(1); | |
307 } | |
308 | |
309 uw_free(ctx); | |
297 } | 310 } |
298 | 311 |
299 int main(int argc, char *argv[]) { | 312 int main(int argc, char *argv[]) { |
300 // The skeleton for this function comes from Beej's sockets tutorial. | 313 // The skeleton for this function comes from Beej's sockets tutorial. |
301 int sockfd; // listen on sock_fd | 314 int sockfd; // listen on sock_fd |
340 fprintf(stderr, "Unexpected getopt() behavior\n"); | 353 fprintf(stderr, "Unexpected getopt() behavior\n"); |
341 return 1; | 354 return 1; |
342 } | 355 } |
343 } | 356 } |
344 | 357 |
358 initialize(); | |
359 | |
345 names = calloc(nthreads, sizeof(int)); | 360 names = calloc(nthreads, sizeof(int)); |
346 | 361 |
347 sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking! | 362 sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking! |
348 | 363 |
349 if (sockfd < 0) { | 364 if (sockfd < 0) { |