http_client_connection_close(_conn);
}
+static void
+http_client_connection_abort_any_requests(struct http_client_connection *conn)
+{
+ struct http_client_request **req;
+
+ if (array_is_created(&conn->request_wait_list)) {
+ array_foreach_modifiable(&conn->request_wait_list, req) {
+ i_assert((*req)->submitted);
+ http_client_request_error(*req,
+ HTTP_CLIENT_REQUEST_ERROR_ABORTED,
+ "Aborting");
+ http_client_request_unref(req);
+ }
+ array_clear(&conn->request_wait_list);
+ }
+ if (conn->pending_request != NULL) {
+ struct http_client_request *pending_req = conn->pending_request;
+ conn->pending_request = NULL;
+ http_client_request_error(pending_req,
+ HTTP_CLIENT_REQUEST_ERROR_ABORTED,
+ "Aborting");
+ http_client_request_unref(&pending_req);
+ }
+}
+
static const char *
http_client_connection_get_timing_info(struct http_client_connection *conn)
{
conn->incoming_payload = NULL;
}
+ http_client_connection_abort_any_requests(conn);
+
+ if (conn->http_parser != NULL)
+ http_response_parser_deinit(&conn->http_parser);
+
if (conn->connect_initialized)
connection_disconnect(&conn->conn);
struct http_client_connection *const *conn_idx;
ARRAY_TYPE(http_client_connection) *conn_arr;
struct http_client_peer *peer = conn->peer;
- struct http_client_request **req;
i_assert(conn->refcount > 0);
http_client_connection_disconnect(conn);
- /* abort all pending requests (not supposed to happen here) */
- if (array_is_created(&conn->request_wait_list)) {
- array_foreach_modifiable(&conn->request_wait_list, req) {
- i_assert((*req)->submitted);
- http_client_request_error(*req,
- HTTP_CLIENT_REQUEST_ERROR_ABORTED,
- "Aborting");
- http_client_request_unref(req);
- }
+ if (array_is_created(&conn->request_wait_list))
array_free(&conn->request_wait_list);
- }
- if (conn->pending_request != NULL) {
- struct http_client_request *pending_req = conn->pending_request;
- conn->pending_request = NULL;
- http_client_request_error(pending_req,
- HTTP_CLIENT_REQUEST_ERROR_ABORTED,
- "Aborting");
- http_client_request_unref(&pending_req);
- }
-
- if (conn->http_parser != NULL)
- http_response_parser_deinit(&conn->http_parser);
if (conn->ssl_iostream != NULL)
ssl_iostream_unref(&conn->ssl_iostream);
if (--req->refcount > 0)
return;
+ http_client_request_debug(req, "Free (requests left=%d)",
+ client->requests_count);
+
/* cannot be destroyed while it is still pending */
i_assert(req->conn == NULL || req->conn->pending_request == NULL);
client->requests_count--;
}
- http_client_request_debug(req, "Destroy (requests left=%d)",
- client->requests_count);
-
- if (req->queue != NULL)
- http_client_queue_drop_request(req->queue, req);
-
if (client->requests_count == 0 && client->ioloop != NULL)
io_loop_stop(client->ioloop);
*_req = NULL;
}
+void http_client_request_destroy(struct http_client_request **_req)
+{
+ struct http_client_request *req = *_req;
+ struct http_client *client = req->client;
+
+ http_client_request_debug(req, "Destroy (requests left=%d)",
+ client->requests_count);
+
+ if (req->queue != NULL)
+ http_client_queue_drop_request(req->queue, req);
+
+ if (req->destroy_callback != NULL) {
+ void (*callback)(void *) = req->destroy_callback;
+
+ req->destroy_callback = NULL;
+ callback(req->destroy_context);
+ }
+
+ http_client_request_unref(_req);
+}
+
void http_client_request_set_port(struct http_client_request *req,
in_port_t port)
{
req->delayed_error);
if (req->queue != NULL)
http_client_queue_drop_request(req->queue, req);
- http_client_request_unref(_req);
+ http_client_request_destroy(_req);
}
void http_client_request_error(struct http_client_request *req,
http_client_delay_request_error(req->client, req);
} else {
http_client_request_send_error(req, status, error);
- http_client_request_unref(&req);
+ http_client_request_destroy(&req);
}
}
http_client_queue_drop_request(req->queue, req);
if (req->payload_wait && req->client->ioloop != NULL)
io_loop_stop(req->client->ioloop);
- http_client_request_unref(_req);
+ http_client_request_destroy(_req);
}
void http_client_request_finish(struct http_client_request **_req)