Mercurial > urweb
comparison src/c/driver.c @ 667:a93d5324f400
Dummy message delivery to clients
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 19 Mar 2009 16:34:13 -0400 |
parents | 162d5308e34f |
children | b0c1a46b1f15 |
comparison
equal
deleted
inserted
replaced
666:5130228d2b29 | 667:a93d5324f400 |
---|---|
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 while (1) { | 107 while (1) { |
108 char buf[uw_bufsize+1], *back = buf, *s; | 108 char buf[uw_bufsize+1], *back = buf, *s; |
109 int sock; | 109 int sock, dont_close = 0; |
110 | 110 |
111 pthread_mutex_lock(&queue_mutex); | 111 pthread_mutex_lock(&queue_mutex); |
112 while (empty()) | 112 while (empty()) |
113 pthread_cond_wait(&queue_cond, &queue_mutex); | 113 pthread_cond_wait(&queue_cond, &queue_mutex); |
114 sock = dequeue(); | 114 sock = dequeue(); |
136 *back = 0; | 136 *back = 0; |
137 | 137 |
138 if (s = strstr(buf, "\r\n\r\n")) { | 138 if (s = strstr(buf, "\r\n\r\n")) { |
139 failure_kind fk; | 139 failure_kind fk; |
140 char *cmd, *path, *headers, path_copy[uw_bufsize+1], *inputs; | 140 char *cmd, *path, *headers, path_copy[uw_bufsize+1], *inputs; |
141 int id, pass; | |
141 | 142 |
142 s[2] = 0; | 143 s[2] = 0; |
143 | 144 |
144 if (!(s = strstr(buf, "\r\n"))) { | 145 if (!(s = strstr(buf, "\r\n"))) { |
145 fprintf(stderr, "No newline in buf\n"); | 146 fprintf(stderr, "No newline in buf\n"); |
163 } | 164 } |
164 | 165 |
165 path = s; | 166 path = s; |
166 if (!strsep(&s, " ")) { | 167 if (!strsep(&s, " ")) { |
167 fprintf(stderr, "No second space in HTTP command\n"); | 168 fprintf(stderr, "No second space in HTTP command\n"); |
169 break; | |
170 } | |
171 | |
172 if (sscanf(path, "/.msgs/%d/%d", &id, &pass) == 2) { | |
173 uw_client_connect(id, pass, sock); | |
174 dont_close = 1; | |
168 break; | 175 break; |
169 } | 176 } |
170 | 177 |
171 if (inputs = strchr(path, '?')) { | 178 if (inputs = strchr(path, '?')) { |
172 char *name, *value; | 179 char *name, *value; |
284 uw_memstats(ctx); | 291 uw_memstats(ctx); |
285 break; | 292 break; |
286 } | 293 } |
287 } | 294 } |
288 | 295 |
289 close(sock); | 296 if (!dont_close) |
297 close(sock); | |
290 uw_reset(ctx); | 298 uw_reset(ctx); |
299 } | |
300 } | |
301 | |
302 static void *client_pruner(void *data) { | |
303 while (1) { | |
304 uw_prune_clients(5); | |
305 sleep(5); | |
291 } | 306 } |
292 } | 307 } |
293 | 308 |
294 static void help(char *cmd) { | 309 static void help(char *cmd) { |
295 printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd); | 310 printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd); |
375 return 1; | 390 return 1; |
376 } | 391 } |
377 | 392 |
378 sin_size = sizeof their_addr; | 393 sin_size = sizeof their_addr; |
379 | 394 |
395 uw_global_init(); | |
396 | |
380 printf("Listening on port %d....\n", uw_port); | 397 printf("Listening on port %d....\n", uw_port); |
398 | |
399 { | |
400 pthread_t thread; | |
401 int name; | |
402 | |
403 if (pthread_create(&thread, NULL, client_pruner, &name)) { | |
404 fprintf(stderr, "Error creating pruner thread\n"); | |
405 return 1; | |
406 } | |
407 } | |
381 | 408 |
382 for (i = 0; i < nthreads; ++i) { | 409 for (i = 0; i < nthreads; ++i) { |
383 pthread_t thread; | 410 pthread_t thread; |
384 names[i] = i; | 411 names[i] = i; |
385 if (pthread_create(&thread, NULL, worker, &names[i])) { | 412 if (pthread_create(&thread, NULL, worker, &names[i])) { |