Skip to content

Commit

Permalink
lib: connection - Use the connection event for all connection types d…
Browse files Browse the repository at this point in the history
…irectly.

This way, the common event fields for the connection are available to each
connection type and its descendant events for objects like commands, requests,
and transactions.

This also creates a standard log prefix used by all connection types.
  • Loading branch information
stephanbosch committed Mar 1, 2019
1 parent 2c67ab2 commit 88ff981
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
7 changes: 2 additions & 5 deletions src/lib-auth/auth-client-connection.c
Expand Up @@ -329,12 +329,10 @@ auth_client_connection_init(struct auth_client *client)

conn->client = client;

conn->event = client->event;
event_ref(conn->event);

conn->conn.event_parent = conn->event;
conn->conn.event_parent = client->event;
connection_init_client_unix(client->clist, &conn->conn,
client->auth_socket_path);
conn->event = conn->conn.event;

hash_table_create_direct(&conn->requests, pool, 100);
i_array_init(&conn->available_auth_mechs, 8);
Expand Down Expand Up @@ -465,7 +463,6 @@ void auth_client_connection_deinit(struct auth_client_connection **_conn)
timeout_remove(&conn->to);
array_free(&conn->available_auth_mechs);
connection_deinit(&conn->conn);
event_unref(&conn->event);
pool_unref(&conn->pool);
}

Expand Down
12 changes: 4 additions & 8 deletions src/lib-http/http-client-connection.c
Expand Up @@ -1709,13 +1709,10 @@ http_client_connection_create(struct http_client_peer *peer)
i_array_init(&conn->request_wait_list, 16);
conn->io_wait_timer = io_wait_timer_add_to(cctx->ioloop);

conn->event = event_create(ppool->peer->cctx->event);

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

event_set_append_log_prefix(
conn->event, t_strdup_printf("conn %s: ", conn->conn.label));
conn->conn.event_parent = ppool->peer->cctx->event;
connection_init(cctx->conn_list, &conn->conn,
http_client_peer_shared_label(pshared));
conn->event = conn->conn.event;

switch (pshared->addr.type) {
case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL:
Expand Down Expand Up @@ -1844,7 +1841,6 @@ bool http_client_connection_unref(struct http_client_connection **_conn)
connection_deinit(&conn->conn);
io_wait_timer_remove(&conn->io_wait_timer);

event_unref(&conn->event);
i_free(conn);

http_client_peer_pool_unref(&ppool);
Expand Down
12 changes: 2 additions & 10 deletions src/lib-smtp/smtp-client-connection.c
Expand Up @@ -1838,15 +1838,11 @@ smtp_client_connection_do_create(struct smtp_client *client, const char *name,
smtp_protocol_name(conn->protocol));
event_set_forced_debug(conn_event, (set != NULL && set->debug));

conn->event = event_create(conn_event);

conn->conn.event_parent = conn->event;
conn->conn.event_parent = conn_event;
connection_init(conn->client->conn_list, &conn->conn, name);
conn->event = conn->conn.event;
event_unref(&conn_event);

event_set_append_log_prefix(
conn->event, t_strdup_printf("conn %s: ", conn->conn.label));

return conn;
}

Expand All @@ -1865,7 +1861,6 @@ smtp_client_connection_create(struct smtp_client *client,
conn->ssl_mode = ssl_mode;

event_add_str(conn->event, "host", host);
event_add_int(conn->event, "port", port);

e_debug(conn->event, "Connection created");

Expand Down Expand Up @@ -1907,8 +1902,6 @@ smtp_client_connection_create_unix(struct smtp_client *client,
conn = smtp_client_connection_do_create(client, name, protocol, set);
conn->path = p_strdup(conn->pool, path);

event_add_str(conn->event, "socket_path", path);

e_debug(conn->event, "Connection created");

return conn;
Expand Down Expand Up @@ -1955,7 +1948,6 @@ void smtp_client_connection_unref(struct smtp_client_connection **_conn)

connection_deinit(&conn->conn);

event_unref(&conn->event);
i_free(conn->ips);
pool_unref(&conn->cap_pool);
pool_unref(&conn->pool);
Expand Down
18 changes: 15 additions & 3 deletions src/lib/connection.c
Expand Up @@ -339,6 +339,20 @@ static void connection_update_stream_names(struct connection *conn)
}
}

void connection_update_event(struct connection *conn)
{
string_t *prefix;

prefix = t_str_new(64);
str_append(prefix, "conn");
if (strlen(conn->label) > 0) {
str_append_c(prefix, ' ');
str_append(prefix, conn->label);
}
str_append(prefix, ": ");
event_set_append_log_prefix(conn->event, str_c(prefix));
}

static void
connection_update_properties(struct connection *conn)
{
Expand Down Expand Up @@ -373,6 +387,7 @@ connection_update_properties(struct connection *conn)
connection_update_property_label(conn);
connection_update_label(conn);
connection_update_stream_names(conn);
connection_update_event(conn);
}

static void connection_init_streams(struct connection *conn)
Expand Down Expand Up @@ -564,9 +579,6 @@ void connection_init_client_ip_from(struct connection_list *list,
{
i_assert(list->set.client);

if (name == NULL)
name = t_strdup_printf("%s:%u", net_ip2addr(ip), port);

conn->remote_ip = *ip;
conn->remote_port = port;

Expand Down
3 changes: 3 additions & 0 deletions src/lib/connection.h
Expand Up @@ -202,6 +202,9 @@ void connection_deinit(struct connection *conn);
void connection_input_halt(struct connection *conn);
void connection_input_resume(struct connection *conn);

/* Update event fields and log prefix based on connection properties. */
void connection_update_event(struct connection *conn);

/* This needs to be called if the input/output streams are changed */
void connection_streams_changed(struct connection *conn);

Expand Down

0 comments on commit 88ff981

Please sign in to comment.