]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 9 Nov 2016 12:17:37 +0000 (14:17 +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 2a5b9d11963e01371c008533d6a1df2e20edafce..c20a1e89cbb999cbf787f309d9c07f3c73b9b4f6 100644 (file)
@@ -538,6 +538,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;
@@ -558,9 +559,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)
@@ -583,6 +590,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 332f69501b39fe9f90b08ea00f27a12ddeb7e384..876be910a4a24a004ea3267e433dc5e07314e2ec 100644 (file)
@@ -399,6 +399,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);
 
 struct http_client_host *
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
  */