Skip to content

Commit

Permalink
lib-smtp: client: Handle output stream errors in a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch committed Feb 17, 2018
1 parent 2f07c9a commit a02b8d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/lib-smtp/smtp-client-connection.c
Expand Up @@ -318,6 +318,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)
{
Expand Down Expand Up @@ -1045,16 +1070,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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib-smtp/smtp-client-private.h
Expand Up @@ -224,6 +224,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);

Expand Down

0 comments on commit a02b8d9

Please sign in to comment.