]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Add program_client_wait() function
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 19 Jan 2022 08:40:55 +0000 (09:40 +0100)
committerKarl Fleischmann <karl.fleischmann@open-xchange.com>
Tue, 1 Feb 2022 06:43:03 +0000 (07:43 +0100)
Akin to program_client_run() this function creates an inner io-loop that
waits but without operating on the available data.

src/lib-program-client/program-client.c
src/lib-program-client/program-client.h

index c6c6ff6ff5bde3ff0d7be4ab4cc5a5f432f90512..62e4fd7dd88aa3664d4b8619fd15a0f365d776a2 100644 (file)
@@ -743,3 +743,21 @@ void program_client_run_async(struct program_client *pclient,
        if (program_client_connect(pclient) < 0)
                program_client_fail(pclient, PROGRAM_CLIENT_ERROR_IO);
 }
+
+void program_client_wait(struct program_client *pclient)
+{
+       if (pclient->disconnected)
+               return;
+
+       struct ioloop *prev_ioloop = current_ioloop;
+       struct ioloop *ioloop = io_loop_create();
+
+       program_client_switch_ioloop(pclient);
+
+       io_loop_run(ioloop);
+
+       io_loop_set_current(prev_ioloop);
+       program_client_switch_ioloop(pclient);
+       io_loop_set_current(ioloop);
+       io_loop_destroy(&ioloop);
+}
index ce6cdf91ebe8aa1e94caa8675e02452807f7df47..f8b4197e5fad29b2291d80430669a660b07b8687 100644 (file)
@@ -98,4 +98,8 @@ void program_client_run_async(struct program_client *pclient,
                1 ? context : CALLBACK_TYPECHECK(callback, \
                        void (*)(enum program_client_exit_status, typeof(context))))
 
+/* wait on program client by running an internal ioloop
+   make sure pclient is not free'd in the program client callback when
+   using this function */
+void program_client_wait(struct program_client *pclient);
 #endif