]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: client: Handle output stream errors in a separate function.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 16 Feb 2018 22:40:29 +0000 (23:40 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 08:42:26 +0000 (10:42 +0200)
src/lib-smtp/smtp-client-connection.c
src/lib-smtp/smtp-client-private.h

index 765bcd38d75e2bd498869a52e4ac17866461f3b4..2221f7de40cdfeff24619819d21753afbf537f61 100644 (file)
@@ -344,6 +344,31 @@ void smtp_client_connection_fail(struct smtp_client_connection *conn,
        smtp_client_connection_fail_reply(conn, &reply);
 }
 
+void smtp_client_connection_handle_output_error(
+       struct smtp_client_connection *conn)
+{
+       struct ostream *output = conn->conn.output;
+
+       if (output->stream_errno != EPIPE &&
+           output->stream_errno != ECONNRESET) {
+               smtp_client_connection_error(conn,
+                       "Connection lost: write(%s) failed: %s",
+                       o_stream_get_name(conn->conn.output),
+                       o_stream_get_error(conn->conn.output));
+               smtp_client_connection_fail(conn,
+                       SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST,
+                       "Lost connection to remote server: "
+                       "Write failure");
+       } else {
+               smtp_client_connection_error(conn,
+                       "Connection lost: Remote disconnected");
+               smtp_client_connection_fail(conn,
+                       SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST,
+                       "Lost connection to remote server: "
+                       "Remote closed connection unexpectedly");
+       }
+}
+
 static void stmp_client_connection_ready(struct smtp_client_connection *conn,
                                         const struct smtp_reply *reply)
 {
@@ -1071,16 +1096,8 @@ static int smtp_client_connection_output(struct smtp_client_connection *conn)
                timeout_reset(conn->to_connect);
 
        if ((ret=o_stream_flush(conn->conn.output)) <= 0) {
-               if (ret < 0) {
-                       smtp_client_connection_error(conn,
-                               "Connection lost: write(%s) failed: %s",
-                               o_stream_get_name(conn->conn.output),
-                               o_stream_get_error(conn->conn.output));
-                       smtp_client_connection_fail(conn,
-                               SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST,
-                               "Lost connection to remote server "
-                               "(write failure)");
-               }
+               if (ret < 0)
+                       smtp_client_connection_handle_output_error(conn);
                return ret;
        }
 
index a6425b5b8c7b66383cd5c378c337a0376183c890..603d6148847da1b8abd70028e0f9a1a5c2f4f06c 100644 (file)
@@ -217,6 +217,8 @@ smpt_client_connection_label(struct smtp_client_connection *conn);
 void smtp_client_connection_fail(struct smtp_client_connection *conn,
                                 unsigned int status, const char *error);
 
+void smtp_client_connection_handle_output_error(
+       struct smtp_client_connection *conn);
 void smtp_client_connection_trigger_output(
        struct smtp_client_connection *conn);