Mercurial > dovecot > core-2.2
changeset 21424:e94ac3f36692
lib-http: client: Keep connection reference throughout http_client_connection_return_response().
Before, it was held in two intervals.
Next commit requires this change, but it also simplifies this function significantly.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Thu, 19 Jan 2017 02:16:06 +0100 |
parents | eac612cea455 |
children | 70083e131e22 |
files | src/lib-http/http-client-connection.c |
diffstat | 1 files changed, 8 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-client-connection.c Tue Jan 17 19:49:39 2017 +0200 +++ b/src/lib-http/http-client-connection.c Thu Jan 19 02:16:06 2017 +0100 @@ -654,14 +654,14 @@ struct http_client_request *req, struct http_response *response) { - struct http_client_connection *tmp_conn; struct istream *payload; - bool retrying, ret; + bool retrying; i_assert(!conn->in_req_callback); i_assert(conn->incoming_payload == NULL); i_assert(conn->pending_request == NULL); + http_client_connection_ref(conn); http_client_request_ref(req); req->state = HTTP_REQUEST_STATE_GOT_RESPONSE; @@ -683,15 +683,13 @@ } conn->in_req_callback = TRUE; - http_client_connection_ref(conn); retrying = !http_client_request_callback(req, response); - tmp_conn = conn; - if (!http_client_connection_unref(&tmp_conn) || - conn->disconnected) { - /* the callback managed to get this connection destroyed */ + if (conn->disconnected) { + /* the callback managed to get this connection disconnected */ if (!retrying) http_client_request_finish(req); http_client_request_unref(&req); + http_client_connection_unref(&conn); return FALSE; } conn->in_req_callback = FALSE; @@ -707,10 +705,9 @@ &conn->conn); } http_client_request_unref(&req); - return TRUE; + return http_client_connection_unref(&conn); } - http_client_connection_ref(conn); if (response->payload != NULL) { req->state = HTTP_REQUEST_STATE_PAYLOAD_IN; payload = response->payload; @@ -735,12 +732,10 @@ if (conn->incoming_payload == NULL && conn->conn.input != NULL) { i_assert(conn->conn.io != NULL || conn->peer->addr.type == HTTP_CLIENT_PEER_ADDR_RAW); - ret = TRUE; - } else { - ret = FALSE; + return http_client_connection_unref(&conn); } http_client_connection_unref(&conn); - return ret; + return FALSE; } static void http_client_connection_input(struct connection *_conn)