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);
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)
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;
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;