# HG changeset patch # User Stephan Bosch # Date 1518252943 -3600 # Node ID f746d87d3aff0d861de3bf1b93766bae24942e56 # Parent e88a611656a82130d24d22d36f9ac65bbf9c364a lib: connection: Add connection_input_halt() and connection_input_resume(). These are convenience functions that remove and add conn->io respectively. diff -r e88a611656a8 -r f746d87d3aff src/lib/connection.c --- a/src/lib/connection.c Mon Feb 12 12:28:37 2018 +0200 +++ b/src/lib/connection.c Sat Feb 10 09:55:43 2018 +0100 @@ -120,6 +120,27 @@ return conn->list->v.input_args(conn, args); } +void connection_input_halt(struct connection *conn) +{ + if (conn->io != NULL) + io_remove(&conn->io); +} + +void connection_input_resume(struct connection *conn) +{ + const struct connection_settings *set = &conn->list->set; + + if (conn->io != NULL) + return; + if (conn->from_streams || set->input_max_size != 0) { + conn->io = io_add_istream(conn->input, + *conn->list->v.input, conn); + } else { + conn->io = io_add(conn->fd_in, IO_READ, + *conn->list->v.input, conn); + } +} + static void connection_init_streams(struct connection *conn) { const struct connection_settings *set = &conn->list->set; @@ -139,9 +160,6 @@ conn->input = i_stream_create_fd(conn->fd_in, set->input_max_size, FALSE); i_stream_set_name(conn->input, conn->name); - conn->io = io_add_istream(conn->input, *conn->list->v.input, conn); - } else { - conn->io = io_add(conn->fd_in, IO_READ, *conn->list->v.input, conn); } if (set->output_max_size != 0) { if (conn->unix_socket) @@ -153,6 +171,7 @@ o_stream_set_no_error_handling(conn->output, TRUE); o_stream_set_name(conn->output, conn->name); } + connection_input_resume(conn); if (set->input_idle_timeout_secs != 0) { conn->to = timeout_add(set->input_idle_timeout_secs*1000, connection_idle_timeout, conn); @@ -169,8 +188,8 @@ const struct connection_settings *set = &conn->list->set; if (set->input_max_size != 0 && conn->io != NULL) { - io_remove(&conn->io); - conn->io = io_add_istream(conn->input, *conn->list->v.input, conn); + connection_input_halt(conn); + connection_input_resume(conn); } } @@ -246,6 +265,7 @@ conn->list = list; conn->name = i_strdup(name); + conn->from_streams = TRUE; conn->fd_in = i_stream_get_fd(input); conn->fd_out = o_stream_get_fd(output); @@ -265,10 +285,9 @@ o_stream_set_no_error_handling(conn->output, TRUE); o_stream_set_name(conn->output, conn->name); - conn->io = io_add_istream(conn->input, *list->v.input, conn); - DLLIST_PREPEND(&list->connections, conn); list->connections_count++; + connection_input_resume(conn); if (list->v.client_connected != NULL) list->v.client_connected(conn, TRUE); diff -r e88a611656a8 -r f746d87d3aff src/lib/connection.h --- a/src/lib/connection.h Mon Feb 12 12:28:37 2018 +0200 +++ b/src/lib/connection.h Sat Feb 10 09:55:43 2018 +0100 @@ -100,6 +100,7 @@ unsigned int version_received:1; unsigned int unix_socket:1; + unsigned int from_streams:1; }; struct connection_list { @@ -127,6 +128,8 @@ void connection_disconnect(struct connection *conn); void connection_deinit(struct connection *conn); +void connection_input_halt(struct connection *conn); +void connection_input_resume(struct connection *conn); void connection_streams_changed(struct connection *conn); /* Returns -1 = disconnected, 0 = nothing new, 1 = something new.