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;
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;
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;
(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);
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;
unsigned int refcount;
struct http_client_settings set;
+
+ struct connection_list *conn_list;
};
/*
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
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);
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);
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);
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)
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;
}
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);
+ }
+}