comparison src/c/http.c @ 1094:db52c32dbe42

All three current protocols work with move to using uw_app
author Adam Chlipala <adamc@hcoop.net>
date Sun, 27 Dec 2009 10:37:24 -0500
parents 305bc0a431de
children 951fced704d6
comparison
equal deleted inserted replaced
1093:8d3aa6c7cee0 1094:db52c32dbe42
14 14
15 #include "urweb.h" 15 #include "urweb.h"
16 #include "request.h" 16 #include "request.h"
17 #include "queue.h" 17 #include "queue.h"
18 18
19 extern uw_app uw_application;
20
19 int uw_backlog = 10; 21 int uw_backlog = 10;
20 22
21 static char *get_header(void *data, const char *h) { 23 static char *get_header(void *data, const char *h) {
22 char *s = data; 24 char *s = data;
23 int len = strlen(h); 25 int len = strlen(h);
59 vprintf(fmt, ap); 61 vprintf(fmt, ap);
60 } 62 }
61 63
62 static void *worker(void *data) { 64 static void *worker(void *data) {
63 int me = *(int *)data; 65 int me = *(int *)data;
64 uw_context ctx = uw_request_new_context(NULL, log_error, log_debug); 66 uw_context ctx = uw_request_new_context(&uw_application, NULL, log_error, log_debug);
65 size_t buf_size = 2; 67 size_t buf_size = 2;
66 char *buf = malloc(buf_size); 68 char *buf = malloc(buf_size);
67 uw_request_context rc = uw_new_request_context(); 69 uw_request_context rc = uw_new_request_context();
68 70
69 while (1) { 71 while (1) {
212 static void sigint(int signum) { 214 static void sigint(int signum) {
213 printf("Exiting....\n"); 215 printf("Exiting....\n");
214 exit(0); 216 exit(0);
215 } 217 }
216 218
217 static loggers ls = {NULL, log_error, log_debug}; 219 static loggers ls = {&uw_application, NULL, log_error, log_debug};
218 220
219 int main(int argc, char *argv[]) { 221 int main(int argc, char *argv[]) {
220 // The skeleton for this function comes from Beej's sockets tutorial. 222 // The skeleton for this function comes from Beej's sockets tutorial.
221 int sockfd; // listen on sock_fd 223 int sockfd; // listen on sock_fd
222 struct sockaddr_in my_addr; 224 struct sockaddr_in my_addr;
260 fprintf(stderr, "Unexpected getopt() behavior\n"); 262 fprintf(stderr, "Unexpected getopt() behavior\n");
261 return 1; 263 return 1;
262 } 264 }
263 } 265 }
264 266
265 uw_request_init(NULL, log_error, log_debug); 267 uw_request_init(&uw_application, NULL, log_error, log_debug);
266 268
267 names = calloc(nthreads, sizeof(int)); 269 names = calloc(nthreads, sizeof(int));
268 270
269 sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking! 271 sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!
270 272