Skip to content

Commit

Permalink
lib-http: client: Moved connection list from client to shared context.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and cmouse committed Dec 7, 2017
1 parent fab1a1c commit 9fe6a55
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/lib-http/http-client-connection.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions src/lib-http/http-client-private.h
Expand Up @@ -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;
Expand All @@ -315,6 +313,8 @@ struct http_client_context {
unsigned int refcount;

struct http_client_settings set;

struct connection_list *conn_list;
};

/*
Expand Down Expand Up @@ -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
38 changes: 22 additions & 16 deletions src/lib-http/http-client.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}

0 comments on commit 9fe6a55

Please sign in to comment.