Skip to content

Commit

Permalink
lib-http: http-client-connection - Use connection_init() immediately …
Browse files Browse the repository at this point in the history
…upon creation.

This avoids the need to remember whether the connection was initialized.
  • Loading branch information
stephanbosch committed Mar 1, 2019
1 parent 20845c7 commit c472d87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/lib-http/http-client-connection.c
Expand Up @@ -1638,7 +1638,6 @@ http_client_connection_tunnel_response(const struct http_response *response,
connection_switch_ioloop_to(&conn->conn, cctx->ioloop);
i_stream_unref(&tunnel.input);
o_stream_unref(&tunnel.output);
conn->connect_initialized = TRUE;
}

static void
Expand Down Expand Up @@ -1714,10 +1713,12 @@ http_client_connection_create(struct http_client_peer *peer)
conn->label = i_strdup_printf("%s [%d]",
http_client_peer_shared_label(pshared), conn->id);
conn->event = event_create(ppool->peer->cctx->event);
conn->conn.event_parent = conn->event;
event_set_append_log_prefix(conn->event,
t_strdup_printf("conn %s: ", conn->label));

conn->conn.event_parent = conn->event;
connection_init(cctx->conn_list, &conn->conn, NULL);

switch (pshared->addr.type) {
case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL:
http_client_connection_connect_tunnel
Expand All @@ -1727,14 +1728,12 @@ http_client_connection_create(struct http_client_peer *peer)
connection_init_client_unix(cctx->conn_list, &conn->conn,
addr->a.un.path);
connection_switch_ioloop_to(&conn->conn, cctx->ioloop);
conn->connect_initialized = TRUE;
http_client_connection_connect(conn, timeout_msecs);
break;
default:
connection_init_client_ip(cctx->conn_list, &conn->conn, NULL,
&addr->a.tcp.ip, addr->a.tcp.port);
connection_switch_ioloop_to(&conn->conn, cctx->ioloop);
conn->connect_initialized = TRUE;
http_client_connection_connect(conn, timeout_msecs);
}

Expand Down Expand Up @@ -1788,8 +1787,7 @@ http_client_connection_disconnect(struct http_client_connection *conn)
if (conn->http_parser != NULL)
http_response_parser_deinit(&conn->http_parser);

if (conn->connect_initialized)
connection_disconnect(&conn->conn);
connection_disconnect(&conn->conn);

io_remove(&conn->io_req_payload);
timeout_remove(&conn->to_requests);
Expand Down Expand Up @@ -1845,8 +1843,7 @@ bool http_client_connection_unref(struct http_client_connection **_conn)
array_free(&conn->request_wait_list);

ssl_iostream_destroy(&conn->ssl_iostream);
if (conn->connect_initialized)
connection_deinit(&conn->conn);
connection_deinit(&conn->conn);
io_wait_timer_remove(&conn->io_wait_timer);

event_unref(&conn->event);
Expand Down Expand Up @@ -1874,8 +1871,7 @@ void http_client_connection_switch_ioloop(struct http_client_connection *conn)
struct http_client_context *cctx = pshared->cctx;
struct ioloop *ioloop = cctx->ioloop;

if (conn->connect_initialized)
connection_switch_ioloop_to(&conn->conn, ioloop);
connection_switch_ioloop_to(&conn->conn, ioloop);
if (conn->io_req_payload != NULL) {
conn->io_req_payload =
io_loop_move_io_to(ioloop, &conn->io_req_payload);
Expand Down
1 change: 0 additions & 1 deletion src/lib-http/http-client-private.h
Expand Up @@ -193,7 +193,6 @@ struct http_client_connection {
bool connected:1; /* connection is connected */
bool tunneling:1; /* last sent request turns this
connection into tunnel */
bool connect_initialized:1; /* connection was initialized */
bool connect_succeeded:1; /* connection succeeded including SSL */
bool connect_failed:1; /* connection failed */
bool lost_prematurely:1; /* lost connection before receiving any data */
Expand Down

0 comments on commit c472d87

Please sign in to comment.