diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-06-27 12:38:23 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-06-27 12:38:23 -0400 |
commit | 74103b6a0ede67d270bb6850ae12578df62032fd (patch) | |
tree | b3a424dbabd630f63bba97a1f80919800ee093fc /src/c/http.c | |
parent | 756283988dd7d7235c228b3b99e6c7f6c73bf122 (diff) |
Successfully starting FastCGI sessions with Apache
Diffstat (limited to 'src/c/http.c')
-rw-r--r-- | src/c/http.c | 50 |
1 files changed, 3 insertions, 47 deletions
diff --git a/src/c/http.c b/src/c/http.c index a8f2efd4..e4e79848 100644 --- a/src/c/http.c +++ b/src/c/http.c @@ -14,45 +14,10 @@ #include "urweb.h" #include "request.h" +#include "queue.h" int uw_backlog = 10; -typedef struct node { - int fd; - struct node *next; -} *node; - -static node front = NULL, back = NULL; - -static int empty() { - return front == NULL; -} - -static void enqueue(int fd) { - node n = malloc(sizeof(struct node)); - - n->fd = fd; - n->next = NULL; - if (back) - back->next = n; - else - front = n; - back = n; -} - -static int dequeue() { - int ret = front->fd; - - front = front->next; - if (!front) - back = NULL; - - return ret; -} - -static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER; - static char *get_header(void *data, const char *h) { char *s = data; int len = strlen(h); @@ -103,13 +68,7 @@ static void *worker(void *data) { while (1) { char *back = buf; - int sock; - - pthread_mutex_lock(&queue_mutex); - while (empty()) - pthread_cond_wait(&queue_cond, &queue_mutex); - sock = dequeue(); - pthread_mutex_unlock(&queue_mutex); + int sock = uw_dequeue(); printf("Handling connection with thread #%d.\n", me); @@ -367,9 +326,6 @@ int main(int argc, char *argv[]) { printf("Accepted connection.\n"); - pthread_mutex_lock(&queue_mutex); - enqueue(new_fd); - pthread_cond_broadcast(&queue_cond); - pthread_mutex_unlock(&queue_mutex); + uw_enqueue(new_fd); } } |