diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index ab0c5c1e8c..be9eadb8a2 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -1390,6 +1390,7 @@ static void http_client_connection_tunnel_response(const struct http_response *response, struct http_client_connection *conn) { + struct http_client_context *cctx = conn->client->cctx; struct http_client_tunnel tunnel; const char *name = http_client_peer_addr2str(&conn->peer->addr); struct http_client_request *req = conn->connect_request; @@ -1406,7 +1407,7 @@ http_client_connection_tunnel_response(const struct http_response *response, http_client_request_start_tunnel(req, &tunnel); connection_init_from_streams - (conn->client->conn_list, &conn->conn, name, tunnel.input, tunnel.output); + (cctx->conn_list, &conn->conn, name, tunnel.input, tunnel.output); i_stream_unref(&tunnel.input); o_stream_unref(&tunnel.output); conn->connect_initialized = TRUE; @@ -1439,6 +1440,7 @@ http_client_connection_connect_tunnel(struct http_client_connection *conn, struct http_client_connection * http_client_connection_create(struct http_client_peer *peer) { + struct http_client_context *cctx = peer->client->cctx; struct http_client_connection *conn; static unsigned int id = 0; const struct http_client_peer_addr *addr = &peer->addr; @@ -1480,13 +1482,13 @@ http_client_connection_create(struct http_client_peer *peer) (conn, &addr->a.tcp.ip, addr->a.tcp.port); break; case HTTP_CLIENT_PEER_ADDR_UNIX: - connection_init_client_unix(peer->client->conn_list, &conn->conn, + connection_init_client_unix(cctx->conn_list, &conn->conn, addr->a.un.path); conn->connect_initialized = TRUE; http_client_connection_connect(conn); break; default: - connection_init_client_ip(peer->client->conn_list, &conn->conn, + connection_init_client_ip(cctx->conn_list, &conn->conn, &addr->a.tcp.ip, addr->a.tcp.port); conn->connect_initialized = TRUE; http_client_connection_connect(conn); diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 28d3ef2411..18b8602ae1 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -299,8 +299,6 @@ struct http_client { ARRAY(struct http_client_request *) delayed_failing_requests; struct timeout *to_failing_requests; - struct connection_list *conn_list; - HASH_TABLE_TYPE(http_client_host) hosts; struct http_client_host *unix_host; struct http_client_host *hosts_list; @@ -315,6 +313,8 @@ struct http_client_context { unsigned int refcount; struct http_client_settings set; + + struct connection_list *conn_list; }; /* @@ -566,4 +566,10 @@ void http_client_delay_request_error(struct http_client *client, void http_client_remove_request_error(struct http_client *client, struct http_client_request *req); +/* + * Client shared context + */ + +void http_client_context_switch_ioloop(struct http_client_context *cctx); + #endif diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index ada2573d04..c7b76c5aaa 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -188,8 +188,6 @@ http_client_init_shared(struct http_client_context *cctx, i_array_init(&client->delayed_failing_requests, 1); - client->conn_list = http_client_connection_list_init(); - hash_table_create(&client->hosts, default_pool, 0, str_hash, strcmp); hash_table_create(&client->peers, default_pool, 0, http_client_peer_addr_hash, http_client_peer_addr_cmp); @@ -238,8 +236,6 @@ void http_client_deinit(struct http_client **_client) array_free(&client->delayed_failing_requests); timeout_remove(&client->to_failing_requests); - connection_list_deinit(&client->conn_list); - if (client->ssl_ctx != NULL) ssl_iostream_context_unref(&client->ssl_ctx); http_client_context_unref(&client->cctx); @@ -248,21 +244,9 @@ void http_client_deinit(struct http_client **_client) void http_client_switch_ioloop(struct http_client *client) { - struct connection *_conn = client->conn_list->connections; struct http_client_host *host; struct http_client_peer *peer; - /* move connections */ - /* FIXME: we wouldn't necessarily need to switch all of them - immediately, only those that have requests now. but also connections - that get new requests before ioloop is switched again.. */ - for (; _conn != NULL; _conn = _conn->next) { - struct http_client_connection *conn = - (struct http_client_connection *)_conn; - - http_client_connection_switch_ioloop(conn); - } - /* move peers */ for (peer = client->peers_list; peer != NULL; peer = peer->next) http_client_peer_switch_ioloop(peer); @@ -276,6 +260,8 @@ void http_client_switch_ioloop(struct http_client *client) client->to_failing_requests = io_loop_move_timeout(&client->to_failing_requests); } + + http_client_context_switch_ioloop(client->cctx); } void http_client_wait(struct http_client *client) @@ -455,6 +441,8 @@ http_client_context_create(const struct http_client_settings *set) cctx->set.socket_recv_buffer_size = set->socket_recv_buffer_size; cctx->set.debug = set->debug; + cctx->conn_list = http_client_connection_list_init(); + return cctx; } @@ -473,5 +461,23 @@ void http_client_context_unref(struct http_client_context **_cctx) if (--cctx->refcount > 0) return; + connection_list_deinit(&cctx->conn_list); + pool_unref(&cctx->pool); } + +void http_client_context_switch_ioloop(struct http_client_context *cctx) +{ + struct connection *_conn = cctx->conn_list->connections; + + /* move connections */ + /* FIXME: we wouldn't necessarily need to switch all of them + immediately, only those that have requests now. but also connections + that get new requests before ioloop is switched again.. */ + for (; _conn != NULL; _conn = _conn->next) { + struct http_client_connection *conn = + (struct http_client_connection *)_conn; + + http_client_connection_switch_ioloop(conn); + } +}