summaryrefslogtreecommitdiff
path: root/libcli
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2018-11-16 19:01:57 +0100
committerVolker Lendecke <vl@samba.org>2018-11-21 16:53:41 +0100
commit499d97b38c4477751d2dd38e9882bc7a5c7a8337 (patch)
tree158eb478ed21a675d42387f836d5edb05a8f9cd8 /libcli
parent9c9ccf234989a28e0f3d8f46fa7bce070e44c5a4 (diff)
downloadsamba-499d97b38c4477751d2dd38e9882bc7a5c7a8337.tar.gz
libcli: Make smb2cli_notify_send cancellable
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r--libcli/smb/smb2cli_notify.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/libcli/smb/smb2cli_notify.c b/libcli/smb/smb2cli_notify.c
index 1a2a2793a32..9026a6b1c30 100644
--- a/libcli/smb/smb2cli_notify.c
+++ b/libcli/smb/smb2cli_notify.c
@@ -32,10 +32,12 @@ struct smb2cli_notify_state {
uint32_t data_length;
struct tevent_req *subreq;
+ struct tevent_req *timeout_subreq;
};
static void smb2cli_notify_done(struct tevent_req *subreq);
static void smb2cli_notify_timedout(struct tevent_req *subreq);
+static bool smb2cli_notify_cancel(struct tevent_req *req);
struct tevent_req *smb2cli_notify_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -49,7 +51,7 @@ struct tevent_req *smb2cli_notify_send(TALLOC_CTX *mem_ctx,
uint32_t completion_filter,
bool recursive)
{
- struct tevent_req *req, *subreq;
+ struct tevent_req *req;
struct smb2cli_notify_state *state;
uint8_t *fixed;
uint16_t watch_tree;
@@ -83,16 +85,33 @@ struct tevent_req *smb2cli_notify_send(TALLOC_CTX *mem_ctx,
}
tevent_req_set_callback(state->subreq, smb2cli_notify_done, req);
- subreq = tevent_wakeup_send(state, ev,
- timeval_current_ofs_msec(timeout_msec));
- if (tevent_req_nomem(subreq, req)) {
- return tevent_req_post(req, ev);
+ if (timeout_msec != 0) {
+ state->timeout_subreq = tevent_wakeup_send(
+ state, ev, timeval_current_ofs_msec(timeout_msec));
+ if (tevent_req_nomem(state->timeout_subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(
+ state->timeout_subreq, smb2cli_notify_timedout, req);
}
- tevent_req_set_callback(subreq, smb2cli_notify_timedout, req);
+
+ tevent_req_set_cancel_fn(req, smb2cli_notify_cancel);
return req;
}
+static bool smb2cli_notify_cancel(struct tevent_req *req)
+{
+ struct smb2cli_notify_state *state = tevent_req_data(
+ req, struct smb2cli_notify_state);
+ bool ok;
+
+ TALLOC_FREE(state->timeout_subreq);
+
+ ok = tevent_req_cancel(state->subreq);
+ return ok;
+}
+
static void smb2cli_notify_timedout(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(