pool = pool_alloconly_create("doveadm client", 1024*16);
conn = p_new(pool, struct client_connection_http, 1);
conn->client.pool = pool;
+ conn->client.http = TRUE;
if (client_connection_init(&conn->client, fd) < 0)
return NULL;
return &conn->client;
}
+void client_connection_destroy_http(struct client_connection *conn)
+{
+ struct client_connection_http *hconn =
+ (struct client_connection_http *)conn;
+
+ if (hconn->http_client != NULL) {
+ /* We're not in the lib-http/server's connection destroy callback. */
+ http_server_connection_close(&hconn->http_client,
+ "Server shutting down");
+ }
+}
+
static void
-doveadm_http_server_connection_destroy(void *context, const char *reason ATTR_UNUSED)
+doveadm_http_server_connection_destroy(void *context,
+ const char *reason ATTR_UNUSED)
{
- struct client_connection *conn = context;
+ struct client_connection_http *hconn =
+ (struct client_connection_http *)context;
+ struct client_connection *conn = &hconn->client;
+
+ if (hconn->http_client == NULL) {
+ /* already destroying client directly */
+ return;
+ }
+
+ /* HTTP connection is destroyed already now */
+ hconn->http_client = NULL;
+
+ /* destroy the connection itself */
client_connection_destroy(&conn);
}