Mercurial > dovecot > core-2.2
changeset 22841:f746d87d3aff
lib: connection: Add connection_input_halt() and connection_input_resume().
These are convenience functions that remove and add conn->io respectively.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Sat, 10 Feb 2018 09:55:43 +0100 |
parents | e88a611656a8 |
children | bf1a68547d67 |
files | src/lib/connection.c src/lib/connection.h |
diffstat | 2 files changed, 29 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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.