From: Aki Tuomi Date: Wed, 19 Jan 2022 08:40:55 +0000 (+0100) Subject: lib-program-client: Add program_client_wait() function X-Git-Tag: 2.4.0~4586 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a9e72ab694edde88d857a77d87bfd2b864d9986;p=thirdparty%2Fdovecot%2Fcore.git lib-program-client: Add program_client_wait() function Akin to program_client_run() this function creates an inner io-loop that waits but without operating on the available data. --- diff --git a/src/lib-program-client/program-client.c b/src/lib-program-client/program-client.c index c6c6ff6ff5..62e4fd7dd8 100644 --- a/src/lib-program-client/program-client.c +++ b/src/lib-program-client/program-client.c @@ -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); +} diff --git a/src/lib-program-client/program-client.h b/src/lib-program-client/program-client.h index ce6cdf91eb..f8b4197e5f 100644 --- a/src/lib-program-client/program-client.h +++ b/src/lib-program-client/program-client.h @@ -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