i_assert(array_count(&peer->conns) == 0);
}
-static void http_client_peer_check_idle(struct http_client_peer *peer)
-{
- struct http_client_connection *const *conn_idx;
-
- array_foreach(&peer->conns, conn_idx) {
- http_client_connection_check_idle(*conn_idx);
- }
-}
-
static unsigned int
http_client_peer_requests_pending(struct http_client_peer *peer,
unsigned int *num_urgent_r)
return num_requests;
}
+static void http_client_peer_check_idle(struct http_client_peer *peer)
+{
+ struct http_client_connection *const *conn_idx;
+ unsigned int num_urgent = 0;
+
+ if (array_count(&peer->conns) == 0 &&
+ http_client_peer_requests_pending(peer, &num_urgent) == 0) {
+ /* no connections or pending requests; die immediately */
+ http_client_peer_free(&peer);
+ return;
+ }
+
+ /* check all connections for idle status */
+ array_foreach(&peer->conns, conn_idx) {
+ http_client_connection_check_idle(*conn_idx);
+ }
+}
+
static void
http_client_peer_handle_requests_real(struct http_client_peer *peer)
{
return;
}
+ peer->handling_requests = TRUE;
t_array_init(&conns_avail, array_count(&peer->conns));
do {
array_clear(&conns_avail);
"No more requests to service for this peer "
"(%u connections exist)", array_count(&peer->conns));
http_client_peer_check_idle(peer);
- return;
+ break;
}
} while (statistics_dirty);
+ peer->handling_requests = FALSE;
+
+ if (num_pending == 0)
+ return;
i_assert(idle == 0);
http_client_peer_debug(peer, "Lost a connection (%d connections left)",
array_count(&peer->conns));
- /* if there are pending requests for this peer, create a new connection
- for them. */
- http_client_peer_trigger_request_handler(peer);
+ if (peer->handling_requests) {
+ /* we got here from the request handler loop */
+ return;
+ }
+ /* check if peer is still relevant */
if (array_count(&peer->conns) == 0 &&
- http_client_peer_requests_pending(peer, &num_urgent) == 0)
+ http_client_peer_requests_pending(peer, &num_urgent) == 0) {
http_client_peer_free(&peer);
+ return;
+ }
+
+ /* if there are pending requests for this peer, create a new connection
+ for them. */
+ http_client_peer_trigger_request_handler(peer);
}
unsigned int