comparison src/c/http.c @ 1997:c93fbd139732

Define uw_loggers structure, allow FFI code to access it
author Sergey Mironov <grrwlf@gmail.com>
date Wed, 26 Feb 2014 08:21:52 +0000
parents 6b80900ddc66
children 262dd74df39c
comparison
equal deleted inserted replaced
1996:582ea3a4d622 1997:c93fbd139732
68 68
69 vprintf(fmt, ap); 69 vprintf(fmt, ap);
70 } 70 }
71 } 71 }
72 72
73 static uw_loggers ls = {NULL, log_error, log_debug};
74
73 static void *worker(void *data) { 75 static void *worker(void *data) {
74 int me = *(int *)data; 76 int me = *(int *)data;
75 uw_context ctx = uw_request_new_context(me, &uw_application, NULL, log_error, log_debug); 77 uw_context ctx = uw_request_new_context(me, &uw_application, &ls);
76 size_t buf_size = 1024; 78 size_t buf_size = 1024;
77 char *buf = malloc(buf_size), *back = buf; 79 char *buf = malloc(buf_size), *back = buf;
78 uw_request_context rc = uw_new_request_context(); 80 uw_request_context rc = uw_new_request_context();
79 int sock = 0; 81 int sock = 0;
80 82
305 static void sigint(int signum) { 307 static void sigint(int signum) {
306 printf("Exiting....\n"); 308 printf("Exiting....\n");
307 exit(0); 309 exit(0);
308 } 310 }
309 311
310 static loggers ls = {&uw_application, NULL, log_error, log_debug};
311
312 int main(int argc, char *argv[]) { 312 int main(int argc, char *argv[]) {
313 // The skeleton for this function comes from Beej's sockets tutorial. 313 // The skeleton for this function comes from Beej's sockets tutorial.
314 int sockfd; // listen on sock_fd 314 int sockfd; // listen on sock_fd
315 struct sockaddr_in my_addr; 315 struct sockaddr_in my_addr;
316 struct sockaddr_in their_addr; // connector's address information 316 struct sockaddr_in their_addr; // connector's address information
372 fprintf(stderr, "Unexpected getopt() behavior\n"); 372 fprintf(stderr, "Unexpected getopt() behavior\n");
373 return 1; 373 return 1;
374 } 374 }
375 } 375 }
376 376
377 uw_request_init(&uw_application, NULL, log_error, log_debug); 377 uw_request_init(&uw_application, &ls);
378 378
379 names = calloc(nthreads, sizeof(int)); 379 names = calloc(nthreads, sizeof(int));
380 380
381 sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking! 381 sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!
382 382
409 printf("Listening on port %d....\n", uw_port); 409 printf("Listening on port %d....\n", uw_port);
410 410
411 { 411 {
412 pthread_t thread; 412 pthread_t thread;
413 413
414 if (pthread_create_big(&thread, NULL, client_pruner, &ls)) { 414 pruner_data *pd = (pruner_data *)malloc(sizeof(pruner_data));
415 pd->app = &uw_application;
416 pd->loggers = &ls;
417
418 if (pthread_create_big(&thread, NULL, client_pruner, pd)) {
415 fprintf(stderr, "Error creating pruner thread\n"); 419 fprintf(stderr, "Error creating pruner thread\n");
416 return 1; 420 return 1;
417 } 421 }
418 } 422 }
419 423