From: Stephan Bosch Date: Wed, 12 Aug 2020 16:00:45 +0000 (+0200) Subject: lib-http: http-client-connection - Start idle state in a common function. X-Git-Tag: 2.3.13~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09acd5c1eb87d7e8fd5f2698f33448398515da18;p=thirdparty%2Fdovecot%2Fcore.git lib-http: http-client-connection - Start idle state in a common function. Removes code duplication. --- diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index 9e73f844d6..d4fecd8215 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -461,43 +461,46 @@ http_client_connection_start_idle_timeout(struct http_client_connection *conn) return timeout; } -void http_client_connection_lost_peer(struct http_client_connection *conn) +static void +http_client_connection_start_idle(struct http_client_connection *conn, + const char *reason) { struct http_client_peer_pool *ppool = conn->ppool; + unsigned int timeout; - if (!conn->connected) { - http_client_connection_unref(&conn); + if (conn->idle) { + e_debug(conn->event, "%s; already idle", reason); return; } - i_assert(!conn->in_req_callback); - - if (!conn->idle) { - unsigned int timeout; - - timeout = http_client_connection_start_idle_timeout(conn); + timeout = http_client_connection_start_idle_timeout(conn); + if (timeout == UINT_MAX) + e_debug(conn->event, "%s; going idle", reason); + else { + e_debug(conn->event, "%s; going idle (timeout = %u msecs)", + reason, timeout); + } - if (timeout == UINT_MAX) - e_debug(conn->event, "Lost peer; going idle"); - else { - e_debug(conn->event, - "Lost peer; going idle (timeout = %u msecs)", - timeout); - } + conn->idle = TRUE; + array_push_back(&ppool->idle_conns, &conn); +} - conn->idle = TRUE; - array_push_back(&ppool->idle_conns, &conn); - } else { - e_debug(conn->event, "Lost peer; already idle"); +void http_client_connection_lost_peer(struct http_client_connection *conn) +{ + if (!conn->connected) { + http_client_connection_unref(&conn); + return; } + i_assert(!conn->in_req_callback); + + http_client_connection_start_idle(conn, "Lost peer"); http_client_connection_detach_peer(conn); } void http_client_connection_check_idle(struct http_client_connection *conn) { struct http_client_peer *peer; - struct http_client_peer_pool *ppool = conn->ppool; peer = conn->peer; if (peer == NULL) { @@ -515,26 +518,14 @@ void http_client_connection_check_idle(struct http_client_connection *conn) array_count(&conn->request_wait_list) == 0 && !conn->in_req_callback && conn->incoming_payload == NULL) { struct http_client *client = peer->client; - unsigned int timeout; i_assert(conn->to_requests == NULL); if (client->waiting) io_loop_stop(client->ioloop); - timeout = http_client_connection_start_idle_timeout(conn); - - if (timeout == UINT_MAX) { - e_debug(conn->event, - "No more requests queued; going idle"); - } else { - e_debug(conn->event, - "No more requests queued; going idle " - "(timeout = %u msecs)", timeout); - } - - conn->idle = TRUE; - array_push_back(&ppool->idle_conns, &conn); + http_client_connection_start_idle( + conn, "No more requests queued"); } }