]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: server: Handle output stream errors in a separate function.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 13:28:36 +0000 (14:28 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 08:42:26 +0000 (10:42 +0200)
src/lib-http/http-server-connection.c
src/lib-http/http-server-private.h

index c2e46483d53ff1ed0fef218510e886057fa2ab3c..9f64a5035d82e03ad2ee26f6334f92b344f0ad80 100644 (file)
@@ -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)
 {
@@ -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;
                        }
 
@@ -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;
        }
 
index 94a6ac51b627d4a6c23773d8d4f0155662b45936..b21fae423fa7ef572f4511470e5a49a59d710cc9 100644 (file)
@@ -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);