poll read data after connect as well
authorFelix Fietkau <nbd@openwrt.org>
Sat, 19 Jan 2013 15:07:15 +0000 (16:07 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 19 Jan 2013 15:07:15 +0000 (16:07 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
client.c
uhttpd.h

index 384f8d4b7cedc03474fc4b01b374237a37a2423b..d1584f917625a5bcca6dbeb642cbe4dc45758f74 100644 (file)
--- a/client.c
+++ b/client.c
@@ -92,11 +92,18 @@ static void uh_set_client_timeout(struct client *cl, int timeout)
 static void uh_keepalive_poll_cb(struct uloop_timeout *timeout)
 {
        struct client *cl = container_of(timeout, struct client, timeout);
+       int sec = cl->requests > 0 ? conf.http_keepalive : conf.network_timeout;
 
-       uh_set_client_timeout(cl, conf.http_keepalive);
+       uh_set_client_timeout(cl, sec);
        cl->us->notify_read(cl->us, 0);
 }
 
+static void uh_poll_connection(struct client *cl)
+{
+       cl->timeout.cb = uh_keepalive_poll_cb;
+       uloop_timeout_set(&cl->timeout, 1);
+}
+
 void uh_request_done(struct client *cl)
 {
        uh_chunk_eof(cl);
@@ -108,8 +115,8 @@ void uh_request_done(struct client *cl)
                return uh_connection_close(cl);
 
        cl->state = CLIENT_STATE_INIT;
-       cl->timeout.cb = uh_keepalive_poll_cb;
-       uloop_timeout_set(&cl->timeout, 1);
+       cl->requests++;
+       uh_poll_connection(cl);
 }
 
 void __printf(4, 5)
@@ -550,7 +557,7 @@ bool uh_accept_client(int fd, bool tls)
        cl->us->string_data = true;
        ustream_fd_init(&cl->sfd, sfd);
 
-       uh_set_client_timeout(cl, conf.network_timeout);
+       uh_poll_connection(cl);
        list_add_tail(&cl->list, &clients);
 
        next_client = NULL;
index e73e2355b3e4676b59cdb87df4f50cb99c9bcf24..38f60d3884dde010c971622ba79d45b7c813a2b4 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -222,6 +222,7 @@ struct client {
        struct ustream_ssl ssl;
 #endif
        struct uloop_timeout timeout;
+       int requests;
 
        enum client_state state;
        bool tls;