summaryrefslogtreecommitdiff
path: root/lib/async_req
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2015-05-21 22:28:14 +0200
committerStefan Metzmacher <metze@samba.org>2015-06-12 17:08:18 +0200
commit64640cc99c7b8543ee8d35ca243c57c048cdb490 (patch)
treea00b234eaf4566e6174df6731789dcaad16f3689 /lib/async_req
parenta2a7cbc66c4713493e6ade45d0cdde25f64c9007 (diff)
downloadsamba-64640cc99c7b8543ee8d35ca243c57c048cdb490.tar.gz
lib/async_req: remove the tevent_fd as early as possible via a wait_for_read_cleanup() hook
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib/async_req')
-rw-r--r--lib/async_req/async_sock.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c
index adb8f87d0cc..03bda588661 100644
--- a/lib/async_req/async_sock.c
+++ b/lib/async_req/async_sock.c
@@ -522,10 +522,11 @@ ssize_t read_packet_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
}
struct wait_for_read_state {
- struct tevent_req *req;
struct tevent_fd *fde;
};
+static void wait_for_read_cleanup(struct tevent_req *req,
+ enum tevent_req_state req_state);
static void wait_for_read_done(struct tevent_context *ev,
struct tevent_fd *fde,
uint16_t flags,
@@ -542,36 +543,47 @@ struct tevent_req *wait_for_read_send(TALLOC_CTX *mem_ctx,
if (req == NULL) {
return NULL;
}
- state->req = req;
+
+ tevent_req_set_cleanup_fn(req, wait_for_read_cleanup);
+
state->fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ,
- wait_for_read_done, state);
+ wait_for_read_done, req);
if (tevent_req_nomem(state->fde, req)) {
return tevent_req_post(req, ev);
}
return req;
}
+static void wait_for_read_cleanup(struct tevent_req *req,
+ enum tevent_req_state req_state)
+{
+ struct wait_for_read_state *state =
+ tevent_req_data(req, struct wait_for_read_state);
+
+ TALLOC_FREE(state->fde);
+}
+
static void wait_for_read_done(struct tevent_context *ev,
struct tevent_fd *fde,
uint16_t flags,
void *private_data)
{
- struct wait_for_read_state *state = talloc_get_type_abort(
- private_data, struct wait_for_read_state);
+ struct tevent_req *req = talloc_get_type_abort(
+ private_data, struct tevent_req);
if (flags & TEVENT_FD_READ) {
- TALLOC_FREE(state->fde);
- tevent_req_done(state->req);
+ tevent_req_done(req);
}
}
bool wait_for_read_recv(struct tevent_req *req, int *perr)
{
- int err;
+ int err = tevent_req_simple_recv_unix(req);
- if (tevent_req_is_unix_error(req, &err)) {
+ if (err != 0) {
*perr = err;
return false;
}
+
return true;
}