Skip to content

Commit

Permalink
lib-http: server: Handle output stream errors in a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and villesavolainen committed Mar 12, 2018
1 parent 27d3781 commit aeadb8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/lib-http/http-server-connection.c
Expand Up @@ -836,6 +836,22 @@ void http_server_connection_write_failed(struct http_server_connection *conn,
}
}

void http_server_connection_handle_output_error(
struct http_server_connection *conn)
{
struct ostream *output = conn->conn.output;
const char *error = NULL;

if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
error = t_strdup_printf("write(%s) failed: %s",
o_stream_get_name(output),
o_stream_get_error(output));
}

http_server_connection_write_failed(conn, error);
}

static bool
http_server_connection_next_response(struct http_server_connection *conn)
{
Expand Down Expand Up @@ -876,13 +892,7 @@ http_server_connection_next_response(struct http_server_connection *conn)
struct ostream *output = conn->conn.output;

if (o_stream_send(output, response, strlen(response)) < 0) {
if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
error = t_strdup_printf("write(%s) failed: %s",
o_stream_get_name(output),
o_stream_get_error(output));
}
http_server_connection_write_failed(conn, error);
http_server_connection_handle_output_error(conn);
return FALSE;
}

Expand Down Expand Up @@ -940,17 +950,8 @@ int http_server_connection_flush(struct http_server_connection *conn)
int ret;

if ((ret = o_stream_flush(output)) <= 0) {
if (ret < 0) {
const char *error = NULL;

if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
error = t_strdup_printf("write(%s) failed: %s",
o_stream_get_name(output),
o_stream_get_error(output));
}
http_server_connection_write_failed(conn, error);
}
if (ret < 0)
http_server_connection_handle_output_error(conn);
return -1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib-http/http-server-private.h
Expand Up @@ -264,6 +264,8 @@ void http_server_connection_switch_ioloop(struct http_server_connection *conn);

void http_server_connection_write_failed(struct http_server_connection *conn,
const char *error);
void http_server_connection_handle_output_error(
struct http_server_connection *conn);

void http_server_connection_trigger_responses(
struct http_server_connection *conn);
Expand Down

0 comments on commit aeadb8e

Please sign in to comment.