summaryrefslogtreecommitdiff
path: root/lib/tevent/tevent_fd.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-07-22 14:45:33 +0200
committerRalph Boehme <slow@samba.org>2018-07-11 23:04:21 +0200
commit072e3b28ce029dd103ef2ea9836b6c6254825a8e (patch)
tree06c9a226d0729461cb3000dd47f544865cc18707 /lib/tevent/tevent_fd.c
parent6740718e0e7db82563870ff398de90dac8f09228 (diff)
downloadsamba-072e3b28ce029dd103ef2ea9836b6c6254825a8e.tar.gz
tevent: split out tevent_common_invoke_fd_handler()
We'll undo the 0.9.36 ABI change on the 0.9.37 release at the end of this patchset. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib/tevent/tevent_fd.c')
-rw-r--r--lib/tevent/tevent_fd.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/tevent/tevent_fd.c b/lib/tevent/tevent_fd.c
index f33ae841b39..7859cbb00ef 100644
--- a/lib/tevent/tevent_fd.c
+++ b/lib/tevent/tevent_fd.c
@@ -30,6 +30,12 @@
int tevent_common_fd_destructor(struct tevent_fd *fde)
{
+ if (fde->destroyed) {
+ tevent_common_check_double_free(fde, "tevent_fd double free");
+ goto done;
+ }
+ fde->destroyed = true;
+
if (fde->event_ctx) {
DLIST_REMOVE(fde->event_ctx->fd_events, fde);
}
@@ -37,6 +43,13 @@ int tevent_common_fd_destructor(struct tevent_fd *fde)
if (fde->close_fn) {
fde->close_fn(fde->event_ctx, fde, fde->fd, fde->private_data);
fde->fd = -1;
+ fde->close_fn = NULL;
+ }
+
+ fde->event_ctx = NULL;
+done:
+ if (fde->busy) {
+ return -1;
}
return 0;
@@ -92,3 +105,29 @@ void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
{
fde->close_fn = close_fn;
}
+
+int tevent_common_invoke_fd_handler(struct tevent_fd *fde, uint16_t flags,
+ bool *removed)
+{
+ if (removed != NULL) {
+ *removed = false;
+ }
+
+ if (fde->event_ctx == NULL) {
+ return 0;
+ }
+
+ fde->busy = true;
+ fde->handler(fde->event_ctx, fde, flags, fde->private_data);
+ fde->busy = false;
+
+ if (fde->destroyed) {
+ talloc_set_destructor(fde, NULL);
+ TALLOC_FREE(fde);
+ if (removed != NULL) {
+ *removed = true;
+ }
+ }
+
+ return 0;
+}