static void
http_client_connection_unlist_pending(struct http_client_connection *conn)
{
+ struct http_client_peer *peer = conn->peer;
struct http_client_peer_pool *ppool = conn->ppool;
ARRAY_TYPE(http_client_connection) *conn_arr;
struct http_client_connection *const *conn_idx;
- /* remove from pending list */
+ /* remove from pending lists */
conn_arr = &ppool->pending_conns;
array_foreach(conn_arr, conn_idx) {
break;
}
}
+
+ if (peer == NULL)
+ return;
+
+ conn_arr = &peer->pending_conns;
+ array_foreach(conn_arr, conn_idx) {
+ if (*conn_idx == conn) {
+ array_delete(conn_arr,
+ array_foreach_idx(conn_arr, conn_idx), 1);
+ break;
+ }
+ }
}
static inline void
break;
}
}
-
i_assert(found);
+ conn_arr = &peer->pending_conns;
+ array_foreach(conn_arr, conn_idx) {
+ if (*conn_idx == conn) {
+ array_delete(conn_arr, array_foreach_idx(conn_arr, conn_idx), 1);
+ break;
+ }
+ }
+
conn->peer = NULL;
e_debug(conn->event, "Detached peer");
array_append(&ppool->pending_conns, &conn, 1);
array_append(&ppool->conns, &conn, 1);
+ array_append(&peer->pending_conns, &conn, 1);
array_append(&peer->conns, &conn, 1);
http_client_peer_pool_ref(ppool);
i_array_init(&peer->queues, 16);
i_array_init(&peer->conns, 16);
+ i_array_init(&peer->pending_conns, 16);
DLLIST_PREPEND_FULL
(&client->peers_list, peer, client_prev, client_next);
array_foreach_modifiable(&conns, conn)
http_client_connection_lost_peer(*conn);
i_assert(array_count(&peer->conns) == 0);
+ array_clear(&peer->pending_conns);
timeout_remove(&peer->to_req_handling);
event_unref(&peer->event);
array_free(&peer->conns);
+ array_free(&peer->pending_conns);
array_free(&peer->queues);
i_free(peer);
if (!http_client_connection_is_active(*conn))
http_client_connection_close(conn);
}
+ i_assert(array_count(&peer->pending_conns) == 0);
}
static unsigned int
bool conn_lost = FALSE;
array_clear(&conns_avail);
- connecting = closing = idle = 0;
+ closing = idle = 0;
/* gather connection statistics */
array_foreach(&peer->conns, conn_idx) {
/* count the number of connecting and closing connections */
if (conn->closing)
closing++;
- else if (!conn->connected)
- connecting++;
}
if (conn_lost) {
return;
i_assert(idle == 0);
+ connecting = array_count(&peer->pending_conns);
/* determine how many new connections we can set up */
if (pshared->last_failure.tv_sec > 0 && working_conn_count > 0 &&
unsigned int
http_client_peer_pending_connections(struct http_client_peer *peer)
{
- struct http_client_connection *const *conn_idx;
- unsigned int pending = 0;
-
- /* find idle connections */
- array_foreach(&peer->conns, conn_idx) {
- if (!(*conn_idx)->closing && !(*conn_idx)->connected)
- pending++;
- }
-
- return pending;
+ return array_count(&peer->pending_conns);
}
void http_client_peer_switch_ioloop(struct http_client_peer *peer)