1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-client: Factor out function ctdb_client_wait_func_timeout()

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2020-05-04 19:01:09 +10:00 committed by Martin Schwenke
parent 403db5b528
commit 01a8d1a4a4
2 changed files with 49 additions and 3 deletions

View File

@ -170,6 +170,28 @@ uint32_t ctdb_client_pnn(struct ctdb_client_context *client);
*/
void ctdb_client_wait(struct tevent_context *ev, bool *done);
/**
* @brief Client event loop waiting for function to return true with timeout
*
* This can be used to wait for asynchronous computations to complete.
* When this function is called, it will run tevent event loop and wait
* till the done function returns true or if the timeout occurs.
*
* This function will return when either
* - done function returns true, or
* - timeout has occurred.
*
* @param[in] ev Tevent context
* @param[in] done_func Function flag to indicate when to stop waiting
* @param[in] private_data Passed to done function
* @param[in] timeout How long to wait
* @return 0 on success, ETIMEDOUT on timeout, and errno on failure
*/
int ctdb_client_wait_func_timeout(struct tevent_context *ev,
bool (*done_func)(void *private_data),
void *private_data,
struct timeval timeout);
/**
* @brief Client event loop waiting for a flag with timeout
*

View File

@ -336,8 +336,10 @@ static void ctdb_client_wait_timeout_handler(struct tevent_context *ev,
*timed_out = true;
}
int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done,
struct timeval timeout)
int ctdb_client_wait_func_timeout(struct tevent_context *ev,
bool (*done_func)(void *private_data),
void *private_data,
struct timeval timeout)
{
TALLOC_CTX *mem_ctx;
struct tevent_timer *timer;
@ -356,7 +358,7 @@ int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done,
return ENOMEM;
}
while (! (*done) && ! timed_out) {
while (! (done_func(private_data)) && ! timed_out) {
tevent_loop_once(ev);
}
@ -369,6 +371,28 @@ int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done,
return 0;
}
static bool client_wait_done(void *private_data)
{
bool *done = (bool *)private_data;
return *done;
}
int ctdb_client_wait_timeout(struct tevent_context *ev,
bool *done,
struct timeval timeout)
{
int ret;
ret = ctdb_client_wait_func_timeout(ev,
client_wait_done,
done,
timeout);
return ret;
}
struct ctdb_recovery_wait_state {
struct tevent_context *ev;
struct ctdb_client_context *client;