]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Unlink all queues from peer when it is disconnected.
authorStephan Bosch <stephan@dovecot.fi>
Thu, 15 Sep 2016 00:09:47 +0000 (02:09 +0200)
committerGitLab <gitlab@git.dovecot.net>
Wed, 2 Nov 2016 11:42:18 +0000 (13:42 +0200)
Before, queues were only destroyed when the whole client was destroyed.
This change and subsequent changes prepare for being able to destroy a queue when it becomes unused.

src/lib-http/http-client-peer.c
src/lib-http/http-client-private.h
src/lib-http/http-client-queue.c

index ea0283938dc533e3bb161cb4e7e580368a3c5768..f4d14e573d462195244e55bc60970dacba36a6e4 100644 (file)
@@ -555,6 +555,7 @@ http_client_peer_disconnect(struct http_client_peer *peer)
 {
        struct http_client_connection **conn;
        ARRAY_TYPE(http_client_connection) conns;
+       struct http_client_queue *const *queue;
 
        if (peer->disconnected)
                return;
@@ -575,9 +576,15 @@ http_client_peer_disconnect(struct http_client_peer *peer)
        if (peer->to_backoff != NULL)
                timeout_remove(&peer->to_backoff);
 
+       /* unlist in client */
        hash_table_remove
                (peer->client->peers, (const struct http_client_peer_addr *)&peer->addr);
        DLLIST_REMOVE(&peer->client->peers_list, peer);
+
+       /* unlink all queues */
+       array_foreach(&peer->queues, queue)
+               http_client_queue_peer_disconnected(*queue, peer);
+       array_clear(&peer->queues);
 }
 
 void http_client_peer_ref(struct http_client_peer *peer)
@@ -600,6 +607,8 @@ bool http_client_peer_unref(struct http_client_peer **_peer)
 
        http_client_peer_disconnect(peer);
 
+       i_assert(array_count(&peer->queues) == 0);
+
        array_free(&peer->conns);
        array_free(&peer->queues);
        i_free(peer->addr_name);
index 1c1ec8aa7aace69aa027779379f8fc5cf36d2482..f01820d5dd140d12e699d0ebf34e48c6692bcf30 100644 (file)
@@ -491,6 +491,8 @@ http_client_queue_connection_success(struct http_client_queue *queue,
                                         const struct http_client_peer_addr *addr);
 void http_client_queue_connection_failure(struct http_client_queue *queue,
        const struct http_client_peer_addr *addr, const char *reason);
+void http_client_queue_peer_disconnected(struct http_client_queue *queue,
+       struct http_client_peer *peer);
 void http_client_queue_switch_ioloop(struct http_client_queue *queue);
 
 /*
index 7b7e921b133988758e437a19d277d6b16a9fe067..56e6499c98823846fae0898087ae37fdf371970f 100644 (file)
@@ -422,6 +422,24 @@ http_client_queue_connection_failure(struct http_client_queue *queue,
        return;
 }
 
+void
+http_client_queue_peer_disconnected(struct http_client_queue *queue,
+       struct http_client_peer *peer)
+{
+       struct http_client_peer *const *peer_idx;
+
+       if (!array_is_created(&queue->pending_peers))
+               return;
+
+       array_foreach(&queue->pending_peers, peer_idx) {
+               if (*peer_idx == peer) {
+                       array_delete(&queue->pending_peers,
+                               array_foreach_idx(&queue->pending_peers, peer_idx), 1);
+                       break;
+               }
+       }
+}
+
 /*
  * Main request queue
  */