From a991cfe2157e58ee43bc580f517ce9ef0dfb7acf Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Mon, 20 Oct 2014 08:54:27 -0700 Subject: [PATCH] lib-http: client: Created list of all submitted requests. Currently only needed to improve debugging of hanging requests. --- src/lib-http/http-client-private.h | 5 ++++- src/lib-http/http-client-request.c | 17 ++++++++++++----- src/lib-http/http-client.c | 8 ++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index fc149f40de..a9dfe812be 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -52,6 +52,8 @@ struct http_client_request { unsigned int refcount; const char *label; + struct http_client_request *prev, *next; + const char *method, *target; struct http_url origin_url; @@ -245,7 +247,8 @@ struct http_client { struct http_client_host *hosts_list; HASH_TABLE_TYPE(http_client_peer) peers; struct http_client_peer *peers_list; - unsigned int pending_requests; + struct http_client_request *requests_list; + unsigned int requests_count; }; int http_client_init_ssl_ctx(struct http_client *client, const char **error_r); diff --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index e291bdff0e..760a1e67ba 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -5,6 +5,7 @@ #include "str.h" #include "hash.h" #include "array.h" +#include "llist.h" #include "time-util.h" #include "istream.h" #include "ostream.h" @@ -164,16 +165,18 @@ void http_client_request_unref(struct http_client_request **_req) } /* only decrease pending request counter if this request was submitted */ - if (req->state > HTTP_REQUEST_STATE_NEW) - req->client->pending_requests--; + if (req->submitted) { + DLLIST_REMOVE(&client->requests_list, req); + client->requests_count--; + } http_client_request_debug(req, "Destroy (requests left=%d)", - client->pending_requests); + client->requests_count); if (req->queue != NULL) http_client_queue_drop_request(req->queue, req); - if (client->pending_requests == 0 && client->ioloop != NULL) + if (client->requests_count == 0 && client->ioloop != NULL) io_loop_stop(client->ioloop); if (req->delayed_error != NULL) @@ -483,12 +486,16 @@ static void http_client_request_do_submit(struct http_client_request *req) void http_client_request_submit(struct http_client_request *req) { - req->client->pending_requests++; + struct http_client *client = req->client; + req->submit_time = ioloop_timeval; http_client_request_do_submit(req); http_client_request_debug(req, "Submitted"); + req->submitted = TRUE; + DLLIST_PREPEND(&client->requests_list, req); + client->requests_count++; } static void diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index 8e41e9d894..ad8d67ac95 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -228,7 +228,7 @@ void http_client_wait(struct http_client *client) i_assert(client->ioloop == NULL); - if (client->pending_requests == 0) + if (client->requests_count == 0) return; client->ioloop = io_loop_create(); @@ -242,9 +242,9 @@ void http_client_wait(struct http_client *client) do { http_client_debug(client, - "Waiting for %d requests to finish", client->pending_requests); + "Waiting for %d requests to finish", client->requests_count); io_loop_run(client->ioloop); - } while (client->pending_requests > 0); + } while (client->requests_count > 0); http_client_debug(client, "All requests finished"); @@ -258,7 +258,7 @@ void http_client_wait(struct http_client *client) unsigned int http_client_get_pending_request_count(struct http_client *client) { - return client->pending_requests; + return client->requests_count; } int http_client_init_ssl_ctx(struct http_client *client, const char **error_r) -- 2.47.3