]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
driver-pgsql: Keep a list of pending query results
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Mon, 27 Sep 2021 18:43:54 +0000 (19:43 +0100)
committerSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Wed, 29 Sep 2021 08:46:27 +0000 (09:46 +0100)
To be used in wait() to determine if there are pending operations.

src/lib-sql/driver-pgsql.c

index 52831801368aefcbe38418b7f7397e4a37667463..74aa7f996f9c4fd5ed67ee15d8af6db36ee7a31c 100644 (file)
@@ -7,6 +7,7 @@
 #include "str.h"
 #include "time-util.h"
 #include "sql-api-private.h"
+#include "llist.h"
 
 #ifdef BUILD_PGSQL
 #include <libpq-fe.h>
@@ -25,6 +26,7 @@ struct pgsql_db {
        struct timeout *to_connect;
        enum io_condition io_dir;
 
+       struct pgsql_result *pending_results;
        struct pgsql_result *cur_result;
        struct ioloop *ioloop, *orig_ioloop;
        struct sql_result *sync_result;
@@ -45,6 +47,9 @@ struct pgsql_binary_value {
 
 struct pgsql_result {
        struct sql_result api;
+
+       struct pgsql_result *prev, *next;
+
        PGresult *pgres;
        struct timeout *to;
 
@@ -411,6 +416,7 @@ static void result_finish(struct pgsql_result *result)
 
        i_assert(db->io == NULL);
        timeout_remove(&result->to);
+       DLLIST_REMOVE(&db->pending_results, result);
 
        /* if connection to server was lost, we don't yet see that the
           connection is bad. we only see the fatal error, so assume it also
@@ -522,6 +528,7 @@ static void do_query(struct pgsql_result *result, const char *query)
 
        driver_pgsql_set_state(db, SQL_DB_STATE_BUSY);
        db->cur_result = result;
+       DLLIST_PREPEND(&db->pending_results, result);
        result->to = timeout_add(SQL_QUERY_TIMEOUT_SECS * 1000,
                                 query_timeout, result);
        result->query = i_strdup(query);