]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: connection: Add connection_input_halt() and connection_input_resume().
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 10 Feb 2018 08:55:43 +0000 (09:55 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 16 Feb 2018 12:54:30 +0000 (13:54 +0100)
These are convenience functions that remove and add conn->io respectively.

src/lib/connection.c
src/lib/connection.h

index 17ba4b7edd5a7ada38d8f011fd817cf9467e59f8..866fb7e76d899c947d45de08924f1bd240547902 100644 (file)
@@ -120,6 +120,27 @@ int connection_input_line_default(struct connection *conn, const char *line)
        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 @@ static void connection_init_streams(struct connection *conn)
                        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 @@ static void connection_init_streams(struct connection *conn)
                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 @@ void connection_streams_changed(struct connection *conn)
        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 @@ void connection_init_from_streams(struct connection_list *list,
 
        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 @@ void connection_init_from_streams(struct connection_list *list,
        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);
index 018dcd61b4ffa2aa000338bc94e866bf6a6aac96..b6d1cbc1457b1c8690fd676990c2368aec847c19 100644 (file)
@@ -100,6 +100,7 @@ struct connection {
 
        unsigned int version_received:1;
        unsigned int unix_socket:1;
+       unsigned int from_streams:1;
 };
 
 struct connection_list {
@@ -127,6 +128,8 @@ int connection_client_connect(struct connection *conn);
 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.