]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Created list of all submitted requests.
authorStephan Bosch <stephan@rename-it.nl>
Mon, 20 Oct 2014 15:54:27 +0000 (08:54 -0700)
committerStephan Bosch <stephan@rename-it.nl>
Mon, 20 Oct 2014 15:54:27 +0000 (08:54 -0700)
Currently only needed to improve debugging of hanging requests.

src/lib-http/http-client-private.h
src/lib-http/http-client-request.c
src/lib-http/http-client.c

index fc149f40de84713167ec52f07859f981f9345190..a9dfe812bec8ba374a0d944769be908e3a7fbd78 100644 (file)
@@ -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);
index e291bdff0e9a30f7466eb9c8bbb375228ead55f7..760a1e67ba0a7f7351372742ff526fa40a384627 100644 (file)
@@ -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
index 8e41e9d894ec50fdc3477aca5e2a64f842d47940..ad8d67ac95f46db7cbb5621c267790f2de2a61cf 100644 (file)
@@ -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)