]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add connection_input_read_stream()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 4 Jan 2022 16:39:24 +0000 (18:39 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 8 Feb 2022 09:48:24 +0000 (10:48 +0100)
src/lib/connection.c
src/lib/connection.h

index dae5c92340fcc6e20af2bfebddb2f5d461dc9dda..638c28ce2b1a94e3f9064e1fcaf3c467891abd6a 100644 (file)
@@ -793,14 +793,15 @@ void connection_deinit(struct connection *conn)
        conn->list = NULL;
 }
 
-int connection_input_read(struct connection *conn)
+int connection_input_read_stream(struct connection *conn,
+                                struct istream *input)
 {
        conn->last_input = ioloop_time;
        conn->last_input_tv = ioloop_timeval;
        if (conn->to != NULL)
                timeout_reset(conn->to);
 
-       switch (i_stream_read(conn->input)) {
+       switch (i_stream_read(input)) {
        case -2:
                /* buffer full */
                switch (conn->list->set.input_full_behavior) {
@@ -814,6 +815,10 @@ int connection_input_read(struct connection *conn)
                i_unreached();
        case -1:
                /* disconnected */
+               if (input != conn->input) {
+                       i_stream_set_error(conn->input, input->stream_errno,
+                                          "%s", i_stream_get_error(input));
+               }
                connection_closed(conn, CONNECTION_DISCONNECT_CONN_CLOSED);
                return -1;
        case 0:
@@ -825,6 +830,11 @@ int connection_input_read(struct connection *conn)
        }
 }
 
+int connection_input_read(struct connection *conn)
+{
+       return connection_input_read_stream(conn, conn->input);
+}
+
 const char *connection_disconnect_reason(struct connection *conn)
 {
        switch (conn->disconnect_reason) {
index 2dafacc053742681e4a82d94ba2197c0a744a521..efe82808e9712d0279fd3057916df538c7d7d0e0 100644 (file)
@@ -225,6 +225,11 @@ void connection_streams_changed(struct connection *conn);
 /* Returns -1 = disconnected, 0 = nothing new, 1 = something new.
    If input_full_behavior is ALLOW, may return also -2 = buffer full. */
 int connection_input_read(struct connection *conn);
+/* Same as connection_input_read(), but read from a different input stream.
+   On failures, copy the error to the main istream. This is mainly intended
+   to be used with multiplex istream. */
+int connection_input_read_stream(struct connection *conn,
+                                struct istream *input);
 /* Verify that VERSION input matches what we expect. */
 int connection_verify_version(struct connection *conn,
                              const char *service_name,