Skip to content

Commit

Permalink
lib-http: client: Unlink all queues from peer when it is disconnected.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stephanbosch authored and GitLab committed Nov 2, 2016
1 parent d675ed1 commit c1423bd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib-http/http-client-peer.c
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/lib-http/http-client-private.h
Expand Up @@ -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);

/*
Expand Down
18 changes: 18 additions & 0 deletions src/lib-http/http-client-queue.c
Expand Up @@ -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
*/
Expand Down

0 comments on commit c1423bd

Please sign in to comment.