Skip to content

Commit

Permalink
lib-smtp: server: 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 5c76836 commit 1e3de39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/lib-smtp/smtp-server-connection.c
Expand Up @@ -592,6 +592,27 @@ bool smtp_server_connection_pending_command_data(
* Command reply handling
*/

void smtp_server_connection_handle_output_error(
struct smtp_server_connection *conn)
{
struct ostream *output = conn->conn.output;

if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
smtp_server_connection_error(conn,
"Connection lost: write(%s) failed: %s",
o_stream_get_name(output),
o_stream_get_error(output));
smtp_server_connection_close(&conn,
"Write failure");
} else {
smtp_server_connection_debug(conn,
"Connection lost: Remote disconnected");
smtp_server_connection_close(&conn,
"Remote closed connection unexpectedly");
}
}

static bool
smtp_server_connection_next_reply(struct smtp_server_connection *conn)
{
Expand Down Expand Up @@ -688,22 +709,8 @@ int smtp_server_connection_flush(struct smtp_server_connection *conn)
int ret;

if ((ret = o_stream_flush(output)) <= 0) {
if (ret < 0) {
if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
smtp_server_connection_error(conn,
"Connection lost: write(%s) failed: %s",
o_stream_get_name(output),
o_stream_get_error(output));
smtp_server_connection_close(&conn,
"Write failure");
} else {
smtp_server_connection_debug(conn,
"Connection lost: Remote disconnected");
smtp_server_connection_close(&conn,
"Remote closed connection unexpectedly");
}
}
if (ret < 0)
smtp_server_connection_handle_output_error(conn);
return ret;
}
return 1;
Expand Down
3 changes: 3 additions & 0 deletions src/lib-smtp/smtp-server-private.h
Expand Up @@ -296,6 +296,9 @@ void smtp_server_connection_error(struct smtp_server_connection *conn,
struct connection_list *smtp_server_connection_list_init(void);

void smtp_server_connection_switch_ioloop(struct smtp_server_connection *conn);

void smtp_server_connection_handle_output_error(
struct smtp_server_connection *conn);
void smtp_server_connection_trigger_output(struct smtp_server_connection *conn);
bool smtp_server_connection_pending_payload(struct smtp_server_connection *conn);

Expand Down

0 comments on commit 1e3de39

Please sign in to comment.