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

index 4b5ba96fd197376ca3ea730444d985d3a6f2cfc8..037588704d466c636df1bfb9f1707371fe15fe0f 100644 (file)
@@ -270,6 +270,23 @@ http_client_connection_lost(struct http_client_connection **_conn,
                HTTP_CLIENT_REQUEST_ERROR_CONNECTION_LOST, error);
 }
 
+void http_client_connection_handle_output_error(
+       struct http_client_connection *conn)
+{
+       struct ostream *output = conn->conn.output;
+
+       if (output->stream_errno != EPIPE &&
+           output->stream_errno != ECONNRESET) {
+               http_client_connection_lost(&conn,
+                       t_strdup_printf("write(%s) failed: %s",
+                                       o_stream_get_name(output),
+                                       o_stream_get_error(output)));
+       } else {
+               http_client_connection_lost(&conn,
+                       "Remote disconnected");
+       }
+}
+
 int http_client_connection_check_ready(struct http_client_connection *conn)
 {
        const struct http_client_settings *set = &conn->peer->client->set;
@@ -1192,12 +1209,8 @@ int http_client_connection_output(struct http_client_connection *conn)
        http_client_connection_reset_request_timeout(conn);
 
        if ((ret = o_stream_flush(output)) <= 0) {
-               if (ret < 0) {
-                       http_client_connection_lost(&conn,
-                               t_strdup_printf("write(%s) failed: %s",
-                                               o_stream_get_name(output),
-                                               o_stream_get_error(output)));
-               }
+               if (ret < 0)
+                       http_client_connection_handle_output_error(conn);
                return ret;
        }
 
index 626d82552b8373b5b1dc20197d069d36d58565c2..43463f4e42fdb43b68b5e12b5d8f79113d40c95e 100644 (file)
@@ -519,6 +519,8 @@ void http_client_connection_peer_closed(struct http_client_connection **_conn);
 void http_client_connection_request_destroyed(
        struct http_client_connection *conn, struct http_client_request *req);
 
+void http_client_connection_handle_output_error(
+       struct http_client_connection *conn);
 int http_client_connection_output(struct http_client_connection *conn);
 void http_client_connection_start_request_timeout(
        struct http_client_connection *conn);