diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-01-19 16:00:34 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-01-19 16:01:45 +0100 |
commit | 74476cc006ea6bd8ccf2bed0474113bdad96de02 (patch) | |
tree | f630f95ad8be7138a3cd6b72b76e7b692064e495 /client.c | |
parent | be33c76aee8486ea28c021aca2f6be4293d2e62e (diff) |
poll connection after request completion when using keepalive
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'client.c')
-rw-r--r-- | client.c | 37 |
1 files changed, 25 insertions, 12 deletions
@@ -75,6 +75,28 @@ static void uh_dispatch_done(struct client *cl) cl->dispatch.free(cl); } +static void client_timeout(struct uloop_timeout *timeout) +{ + struct client *cl = container_of(timeout, struct client, timeout); + + cl->state = CLIENT_STATE_CLOSE; + uh_connection_close(cl); +} + +static void uh_set_client_timeout(struct client *cl, int timeout) +{ + cl->timeout.cb = client_timeout; + uloop_timeout_set(&cl->timeout, timeout * 1000); +} + +static void uh_keepalive_poll_cb(struct uloop_timeout *timeout) +{ + struct client *cl = container_of(timeout, struct client, timeout); + + uh_set_client_timeout(cl, conf.http_keepalive); + cl->us->notify_read(cl->us, 0); +} + void uh_request_done(struct client *cl) { uh_chunk_eof(cl); @@ -86,7 +108,8 @@ void uh_request_done(struct client *cl) return uh_connection_close(cl); cl->state = CLIENT_STATE_INIT; - uloop_timeout_set(&cl->timeout, conf.http_keepalive * 1000); + cl->timeout.cb = uh_keepalive_poll_cb; + uloop_timeout_set(&cl->timeout, 1); } void __printf(4, 5) @@ -114,14 +137,6 @@ static void uh_header_error(struct client *cl, int code, const char *summary) uh_connection_close(cl); } -static void client_timeout(struct uloop_timeout *timeout) -{ - struct client *cl = container_of(timeout, struct client, timeout); - - cl->state = CLIENT_STATE_CLOSE; - uh_connection_close(cl); -} - static int find_idx(const char * const *list, int max, const char *str) { int i; @@ -535,9 +550,7 @@ bool uh_accept_client(int fd, bool tls) cl->us->string_data = true; ustream_fd_init(&cl->sfd, sfd); - cl->timeout.cb = client_timeout; - uloop_timeout_set(&cl->timeout, conf.network_timeout * 1000); - + uh_set_client_timeout(cl, conf.network_timeout); list_add_tail(&cl->list, &clients); next_client = NULL; |