diff options
author | 2009-03-19 16:34:13 -0400 | |
---|---|---|
committer | 2009-03-19 16:34:13 -0400 | |
commit | 9e730b9a1aa4db311088a355e7e8601c6a998467 (patch) | |
tree | 286b56b8fe24a04c3c2a26f13d6fdc9c845d7452 /src/c/driver.c | |
parent | 1f530c51813cbeee1b166e5e75058eacb313f306 (diff) |
Dummy message delivery to clients
Diffstat (limited to 'src/c/driver.c')
-rw-r--r-- | src/c/driver.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/c/driver.c b/src/c/driver.c index 34e57a6d..12905ede 100644 --- a/src/c/driver.c +++ b/src/c/driver.c @@ -106,7 +106,7 @@ static void *worker(void *data) { while (1) { char buf[uw_bufsize+1], *back = buf, *s; - int sock; + int sock, dont_close = 0; pthread_mutex_lock(&queue_mutex); while (empty()) @@ -138,6 +138,7 @@ static void *worker(void *data) { if (s = strstr(buf, "\r\n\r\n")) { failure_kind fk; char *cmd, *path, *headers, path_copy[uw_bufsize+1], *inputs; + int id, pass; s[2] = 0; @@ -168,6 +169,12 @@ static void *worker(void *data) { break; } + if (sscanf(path, "/.msgs/%d/%d", &id, &pass) == 2) { + uw_client_connect(id, pass, sock); + dont_close = 1; + break; + } + if (inputs = strchr(path, '?')) { char *name, *value; *inputs++ = 0; @@ -286,11 +293,19 @@ static void *worker(void *data) { } } - close(sock); + if (!dont_close) + close(sock); uw_reset(ctx); } } +static void *client_pruner(void *data) { + while (1) { + uw_prune_clients(5); + sleep(5); + } +} + static void help(char *cmd) { printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd); } @@ -377,8 +392,20 @@ int main(int argc, char *argv[]) { sin_size = sizeof their_addr; + uw_global_init(); + printf("Listening on port %d....\n", uw_port); + { + pthread_t thread; + int name; + + if (pthread_create(&thread, NULL, client_pruner, &name)) { + fprintf(stderr, "Error creating pruner thread\n"); + return 1; + } + } + for (i = 0; i < nthreads; ++i) { pthread_t thread; names[i] = i; |