summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2015-11-10 16:59:21 +1100
committerMartin Schwenke <martins@samba.org>2016-02-24 08:44:37 +0100
commit69113fa02efb9f21592b25a46d000f7fff173453 (patch)
treea8c4cb00a914985f7fb640c5792fcb75a0caa7d9
parentd8c28fc9729b371a9521f959054985749248be26 (diff)
downloadsamba-69113fa02efb9f21592b25a46d000f7fff173453.tar.gz
ctdb-client: Add new API for ctdb_client_wait_timeout()
This is similar to ctdb_client_wait() with additional timeout argument. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
-rw-r--r--ctdb/client/client.h3
-rw-r--r--ctdb/client/client_connect.c43
2 files changed, 46 insertions, 0 deletions
diff --git a/ctdb/client/client.h b/ctdb/client/client.h
index f2f8d6b5328..ec077f7b4e8 100644
--- a/ctdb/client/client.h
+++ b/ctdb/client/client.h
@@ -45,6 +45,9 @@ uint32_t ctdb_client_pnn(struct ctdb_client_context *client);
void ctdb_client_wait(struct tevent_context *ev, bool *done);
+int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done,
+ struct timeval timeout);
+
struct tevent_req *ctdb_recovery_wait_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct ctdb_client_context *client);
diff --git a/ctdb/client/client_connect.c b/ctdb/client/client_connect.c
index 0e144c68caa..88c444d4c93 100644
--- a/ctdb/client/client_connect.c
+++ b/ctdb/client/client_connect.c
@@ -239,6 +239,49 @@ void ctdb_client_wait(struct tevent_context *ev, bool *done)
}
}
+static void ctdb_client_wait_timeout_handler(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval t,
+ void *private_data)
+{
+ bool *timed_out = (bool *)private_data;
+
+ *timed_out = true;
+}
+
+int ctdb_client_wait_timeout(struct tevent_context *ev, bool *done,
+ struct timeval timeout)
+{
+ TALLOC_CTX *mem_ctx;
+ struct tevent_timer *timer;
+ bool timed_out = false;
+
+ mem_ctx = talloc_new(ev);
+ if (mem_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ timer = tevent_add_timer(ev, mem_ctx, timeout,
+ ctdb_client_wait_timeout_handler,
+ &timed_out);
+ if (timer == NULL) {
+ talloc_free(mem_ctx);
+ return ENOMEM;
+ }
+
+ while (! (*done) && ! timed_out) {
+ tevent_loop_once(ev);
+ }
+
+ talloc_free(mem_ctx);
+
+ if (timed_out) {
+ return ETIME;
+ }
+
+ return 0;
+}
+
struct ctdb_recovery_wait_state {
struct tevent_context *ev;
struct ctdb_client_context *client;