summaryrefslogtreecommitdiffstats
path: root/lib/tevent/tevent.h
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2013-09-27 02:29:57 +0200
committerStefan Metzmacher <metze@samba.org>2014-01-17 12:38:08 +0100
commit50b9f154d22f5c356e66bba341e9ee0292218cfd (patch)
tree3ead5cfe68d2dad847c8436e7bdd2c9840d78278 /lib/tevent/tevent.h
parent0ed93e099af833045d9d00b9a8faeb5b93b6ef2e (diff)
downloadsamba-50b9f154d22f5c356e66bba341e9ee0292218cfd.tar.gz
samba-50b9f154d22f5c356e66bba341e9ee0292218cfd.tar.xz
samba-50b9f154d22f5c356e66bba341e9ee0292218cfd.zip
tevent: add tevent_req_set_cleanup_fn()
Note that some callers used their own destructor for their tevent_req instance, they'll just overwrite this, which is not intended, but works without problems. The intended way is to specify a cleanup function and handle the TEVENT_REQ_RECEIVED state as destructor. Note that the TEVENT_REQ_RECEIVED cleanup event might be triggered by an explicit tevent_req_received() in the _recv() function. The TEVENT_REQ_RECEIVED event is only triggered once as tevent_req_received() will remove the destructor. So the difference compared to a custom destructor is that the struct tevent_req itself can continue to be there, while tevent_req_received() removed all internal state. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib/tevent/tevent.h')
-rw-r--r--lib/tevent/tevent.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index d7d4f19effd..c54cbe21336 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -934,6 +934,41 @@ bool _tevent_req_cancel(struct tevent_req *req, const char *location);
_tevent_req_cancel(req, __location__)
#endif
+/**
+ * @brief A typedef for a cleanup function for a tevent request.
+ *
+ * @param[in] req The tevent request calling this function.
+ *
+ * @param[in] req_state The current tevent_req_state.
+ *
+ */
+typedef void (*tevent_req_cleanup_fn)(struct tevent_req *req,
+ enum tevent_req_state req_state);
+
+/**
+ * @brief This function sets a cleanup function for the given tevent request.
+ *
+ * This function can be used to setup a cleanup function for the given request.
+ * This will be triggered when the tevent_req_done() or tevent_req_error()
+ * function was called, before notifying the callers callback function,
+ * and also before scheduling the deferred trigger.
+ *
+ * This might be useful if more than one tevent_req belong together
+ * and need to finish both requests at the same time.
+ *
+ * The cleanup function is able to call tevent_req_done() or tevent_req_error()
+ * recursively, the cleanup function is only triggered the first time.
+ *
+ * The cleanup function is also called by tevent_req_received()
+ * (possibly triggered from tevent_req_destructor()) before destroying
+ * the private data of the tevent_req.
+ *
+ * @param[in] req The request to use.
+ *
+ * @param[in] fn A pointer to the cancel function.
+ */
+void tevent_req_set_cleanup_fn(struct tevent_req *req, tevent_req_cleanup_fn fn);
+
#ifdef DOXYGEN
/**
* @brief Create an async tevent request.