Mercurial > urweb
comparison src/c/urweb.c @ 673:a8effb6159c2
Variable timeouts and client keep-alive
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 24 Mar 2009 15:35:46 -0400 |
parents | df6eb58de040 |
children | 5ff1ff38e2db |
comparison
equal
deleted
inserted
replaced
672:df6eb58de040 | 673:a8effb6159c2 |
---|---|
218 fprintf(stderr, "Wrong client password (%d)\n", (int)id); | 218 fprintf(stderr, "Wrong client password (%d)\n", (int)id); |
219 return; | 219 return; |
220 } | 220 } |
221 | 221 |
222 if (c->data.used.sock != -1) { | 222 if (c->data.used.sock != -1) { |
223 pthread_mutex_unlock(&c->data.used.lock); | 223 close(c->data.used.sock); |
224 close(sock); | 224 c->data.used.sock = -1; |
225 fprintf(stderr, "Duplicate client connection (%d)\n", (int)id); | |
226 return; | |
227 } | 225 } |
228 | 226 |
229 c->data.used.last_contact = time(NULL); | 227 c->data.used.last_contact = time(NULL); |
230 | 228 |
231 if (buf_used(&c->data.used.msgs) > 0) { | 229 if (buf_used(&c->data.used.msgs) > 0) { |
286 c->data.next = clients_free; | 284 c->data.next = clients_free; |
287 clients_free = c; | 285 clients_free = c; |
288 } | 286 } |
289 } | 287 } |
290 | 288 |
291 void uw_prune_clients(time_t timeout) { | 289 extern int uw_timeout; |
290 | |
291 void uw_prune_clients() { | |
292 size_t i; | 292 size_t i; |
293 time_t cutoff; | 293 time_t cutoff; |
294 | 294 |
295 cutoff = time(NULL) - timeout; | 295 cutoff = time(NULL) - uw_timeout; |
296 | 296 |
297 pthread_mutex_lock(&clients_mutex); | 297 pthread_mutex_lock(&clients_mutex); |
298 | 298 |
299 for (i = 0; i < n_clients; ++i) { | 299 for (i = 0; i < n_clients; ++i) { |
300 if (clients[i]->mode == USED && clients[i]->data.used.last_contact < cutoff | 300 if (clients[i]->mode == USED && clients[i]->data.used.last_contact < cutoff |
505 const char *script_header, *url_prefix; | 505 const char *script_header, *url_prefix; |
506 | 506 |
507 size_t n_deltas; | 507 size_t n_deltas; |
508 channel_delta *deltas; | 508 channel_delta *deltas; |
509 | 509 |
510 int timeout; | |
511 | |
510 char error_message[ERROR_BUF_LEN]; | 512 char error_message[ERROR_BUF_LEN]; |
511 }; | 513 }; |
512 | 514 |
513 extern int uw_inputs_len; | 515 extern int uw_inputs_len; |
514 | 516 |
538 | 540 |
539 ctx->source_count = 0; | 541 ctx->source_count = 0; |
540 | 542 |
541 ctx->n_deltas = 0; | 543 ctx->n_deltas = 0; |
542 ctx->deltas = malloc(0); | 544 ctx->deltas = malloc(0); |
545 | |
546 ctx->timeout = uw_timeout; | |
543 | 547 |
544 return ctx; | 548 return ctx; |
545 } | 549 } |
546 | 550 |
547 void uw_set_db(uw_context ctx, void *db) { | 551 void uw_set_db(uw_context ctx, void *db) { |
832 return ""; | 836 return ""; |
833 else { | 837 else { |
834 int pass; | 838 int pass; |
835 client *c = uw_new_client(&pass); | 839 client *c = uw_new_client(&pass); |
836 | 840 |
837 char *r = uw_malloc(ctx, strlen(ctx->script_header) + 56 + 2 * INTS_MAX + buf_used(&ctx->script) | 841 char *r = uw_malloc(ctx, strlen(ctx->script_header) + 65 + 3 * INTS_MAX + buf_used(&ctx->script) |
838 + strlen(ctx->url_prefix)); | 842 + strlen(ctx->url_prefix)); |
839 sprintf(r, "%s<script>client_id=%d;client_pass=%d;url_prefix=\"%s\";%s</script>", | 843 sprintf(r, "%s<script>client_id=%d;client_pass=%d;url_prefix=\"%s\";timeout=%d;%s</script>", |
840 ctx->script_header, (int)c->id, c->data.used.pass, ctx->url_prefix, ctx->script.start); | 844 ctx->script_header, |
845 (int)c->id, | |
846 c->data.used.pass, | |
847 ctx->url_prefix, | |
848 ctx->timeout, | |
849 ctx->script.start); | |
841 return r; | 850 return r; |
842 } | 851 } |
843 } | 852 } |
844 | 853 |
845 const char *uw_Basis_get_listener(uw_context ctx, uw_Basis_string onload) { | 854 const char *uw_Basis_get_listener(uw_context ctx, uw_Basis_string onload) { |