poll connection after request completion when using keepalive
authorFelix Fietkau <nbd@openwrt.org>
Sat, 19 Jan 2013 15:00:34 +0000 (16:00 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 19 Jan 2013 15:01:45 +0000 (16:01 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
client.c

index b493e7f0e38010a8ff236bd2dc58955b81a8955b..384f8d4b7cedc03474fc4b01b374237a37a2423b 100644 (file)
--- a/client.c
+++ b/client.c
@@ -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;