2 Unix SMB/CIFS implementation.
4 generalised event loop handling
6 Copyright (C) Andrew Tridgell 2005
7 Copyright (C) Stefan Metzmacher 2005-2009
8 Copyright (C) Volker Lendecke 2008
10 ** NOTE! The following LGPL license applies to the tevent
11 ** library. This does NOT imply that all of Samba is released
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Lesser General Public
16 License as published by the Free Software Foundation; either
17 version 3 of the License, or (at your option) any later version.
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, see <http://www.gnu.org/licenses/>.
36 struct tevent_context;
40 struct tevent_immediate;
44 * @defgroup tevent The tevent API
46 * The tevent low-level API
48 * This API provides the public interface to manage events in the tevent
49 * mainloop. Functions are provided for managing low-level events such
50 * as timer events, fd events and signal handling.
55 /* event handler types */
57 * Called when a file descriptor monitored by tevent has
58 * data to be read or written on it.
60 typedef void (*tevent_fd_handler_t)(struct tevent_context *ev,
61 struct tevent_fd *fde,
66 * Called when tevent is ceasing the monitoring of a file descriptor.
68 typedef void (*tevent_fd_close_fn_t)(struct tevent_context *ev,
69 struct tevent_fd *fde,
74 * Called when a tevent timer has fired.
76 typedef void (*tevent_timer_handler_t)(struct tevent_context *ev,
77 struct tevent_timer *te,
78 struct timeval current_time,
82 * Called when a tevent immediate event is invoked.
84 typedef void (*tevent_immediate_handler_t)(struct tevent_context *ctx,
85 struct tevent_immediate *im,
89 * Called after tevent detects the specified signal.
91 typedef void (*tevent_signal_handler_t)(struct tevent_context *ev,
92 struct tevent_signal *se,
99 * @brief Create a event_context structure.
101 * This must be the first events call, and all subsequent calls pass this
102 * event_context as the first element. Event handlers also receive this as
103 * their first argument.
105 * @param[in] mem_ctx The memory context to use.
107 * @return An allocated tevent context, NULL on error.
109 * @see tevent_context_init()
111 struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
114 * @brief Create a event_context structure and name it.
116 * This must be the first events call, and all subsequent calls pass this
117 * event_context as the first element. Event handlers also receive this as
118 * their first argument.
120 * @param[in] mem_ctx The memory context to use.
122 * @param[in] name The name for the tevent context.
124 * @return An allocated tevent context, NULL on error.
126 struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx, const char *name);
129 * @brief List available backends.
131 * @param[in] mem_ctx The memory context to use.
133 * @return A string vector with a terminating NULL element, NULL
136 const char **tevent_backend_list(TALLOC_CTX *mem_ctx);
139 * @brief Set the default tevent backent.
141 * @param[in] backend The name of the backend to set.
143 void tevent_set_default_backend(const char *backend);
147 * @brief Add a file descriptor based event.
149 * @param[in] ev The event context to work on.
151 * @param[in] mem_ctx The talloc memory context to use.
153 * @param[in] fd The file descriptor to base the event on.
155 * @param[in] flags #TEVENT_FD_READ or #TEVENT_FD_WRITE
157 * @param[in] handler The callback handler for the event.
159 * @param[in] private_data The private data passed to the callback handler.
161 * @return The file descriptor based event, NULL on error.
163 * @note To cancel the monitoring of a file descriptor, call talloc_free()
164 * on the object returned by this function.
166 struct tevent_fd *tevent_add_fd(struct tevent_context *ev,
170 tevent_fd_handler_t handler,
173 struct tevent_fd *_tevent_add_fd(struct tevent_context *ev,
177 tevent_fd_handler_t handler,
179 const char *handler_name,
180 const char *location);
181 #define tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \
182 _tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data, \
183 #handler, __location__)
188 * @brief Add a timed event
190 * @param[in] ev The event context to work on.
192 * @param[in] mem_ctx The talloc memory context to use.
194 * @param[in] next_event Timeval specifying the absolute time to fire this
195 * event. This is not an offset.
197 * @param[in] handler The callback handler for the event.
199 * @param[in] private_data The private data passed to the callback handler.
201 * @return The newly-created timer event, or NULL on error.
203 * @note To cancel a timer event before it fires, call talloc_free() on the
204 * event returned from this function. This event is automatically
205 * talloc_free()-ed after its event handler files, if it hasn't been freed yet.
207 * @note Unlike some mainloops, tevent timers are one-time events. To set up
208 * a recurring event, it is necessary to call tevent_add_timer() again during
209 * the handler processing.
211 * @note Due to the internal mainloop processing, a timer set to run
212 * immediately will do so after any other pending timers fire, but before
213 * any further file descriptor or signal handling events fire. Callers should
214 * not rely on this behavior!
216 struct tevent_timer *tevent_add_timer(struct tevent_context *ev,
218 struct timeval next_event,
219 tevent_timer_handler_t handler,
222 struct tevent_timer *_tevent_add_timer(struct tevent_context *ev,
224 struct timeval next_event,
225 tevent_timer_handler_t handler,
227 const char *handler_name,
228 const char *location);
229 #define tevent_add_timer(ev, mem_ctx, next_event, handler, private_data) \
230 _tevent_add_timer(ev, mem_ctx, next_event, handler, private_data, \
231 #handler, __location__)
236 * Initialize an immediate event object
238 * This object can be used to trigger an event to occur immediately after
239 * returning from the current event (before any other event occurs)
241 * @param[in] mem_ctx The talloc memory context to use as the parent
243 * @return An empty tevent_immediate object. Use tevent_schedule_immediate
244 * to populate and use it.
246 * @note Available as of tevent 0.9.8
248 struct tevent_immediate *tevent_create_immediate(TALLOC_CTX *mem_ctx);
250 struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx,
251 const char *location);
252 #define tevent_create_immediate(mem_ctx) \
253 _tevent_create_immediate(mem_ctx, __location__)
259 * Schedule an event for immediate execution. This event will occur
260 * immediately after returning from the current event (before any other
263 * @param[in] im The tevent_immediate object to populate and use
264 * @param[in] ctx The tevent_context to run this event
265 * @param[in] handler The event handler to run when this event fires
266 * @param[in] private_data Data to pass to the event handler
268 void tevent_schedule_immediate(struct tevent_immediate *im,
269 struct tevent_context *ctx,
270 tevent_immediate_handler_t handler,
273 void _tevent_schedule_immediate(struct tevent_immediate *im,
274 struct tevent_context *ctx,
275 tevent_immediate_handler_t handler,
277 const char *handler_name,
278 const char *location);
279 #define tevent_schedule_immediate(im, ctx, handler, private_data) \
280 _tevent_schedule_immediate(im, ctx, handler, private_data, \
281 #handler, __location__);
286 * @brief Add a tevent signal handler
288 * tevent_add_signal() creates a new event for handling a signal the next
289 * time through the mainloop. It implements a very simple traditional signal
290 * handler whose only purpose is to add the handler event into the mainloop.
292 * @param[in] ev The event context to work on.
294 * @param[in] mem_ctx The talloc memory context to use.
296 * @param[in] signum The signal to trap
298 * @param[in] handler The callback handler for the signal.
300 * @param[in] sa_flags sigaction flags for this signal handler.
302 * @param[in] private_data The private data passed to the callback handler.
304 * @return The newly-created signal handler event, or NULL on error.
306 * @note To cancel a signal handler, call talloc_free() on the event returned
307 * from this function.
309 struct tevent_signal *tevent_add_signal(struct tevent_context *ev,
313 tevent_signal_handler_t handler,
316 struct tevent_signal *_tevent_add_signal(struct tevent_context *ev,
320 tevent_signal_handler_t handler,
322 const char *handler_name,
323 const char *location);
324 #define tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \
325 _tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data, \
326 #handler, __location__)
331 * @brief Pass a single time through the mainloop
333 * This will process any appropriate signal, immediate, fd and timer events
335 * @param[in] ev The event context to process
337 * @return Zero on success, nonzero if an internal error occurred
339 int tevent_loop_once(struct tevent_context *ev);
341 int _tevent_loop_once(struct tevent_context *ev, const char *location);
342 #define tevent_loop_once(ev) \
343 _tevent_loop_once(ev, __location__)
348 * @brief Run the mainloop
350 * The mainloop will run until there are no events remaining to be processed
352 * @param[in] ev The event context to process
354 * @return Zero if all events have been processed. Nonzero if an internal
357 int tevent_loop_wait(struct tevent_context *ev);
359 int _tevent_loop_wait(struct tevent_context *ev, const char *location);
360 #define tevent_loop_wait(ev) \
361 _tevent_loop_wait(ev, __location__)
366 * Assign a function to run when a tevent_fd is freed
368 * This function is a destructor for the tevent_fd. It does not automatically
369 * close the file descriptor. If this is the desired behavior, then it must be
370 * performed by the close_fn.
372 * @param[in] fde File descriptor event on which to set the destructor
373 * @param[in] close_fn Destructor to execute when fde is freed
375 void tevent_fd_set_close_fn(struct tevent_fd *fde,
376 tevent_fd_close_fn_t close_fn);
379 * Automatically close the file descriptor when the tevent_fd is freed
381 * This function calls close(fd) internally.
383 * @param[in] fde File descriptor event to auto-close
385 void tevent_fd_set_auto_close(struct tevent_fd *fde);
388 * Return the flags set on this file descriptor event
390 * @param[in] fde File descriptor event to query
392 * @return The flags set on the event. See #TEVENT_FD_READ and
395 uint16_t tevent_fd_get_flags(struct tevent_fd *fde);
398 * Set flags on a file descriptor event
400 * @param[in] fde File descriptor event to set
401 * @param[in] flags Flags to set on the event. See #TEVENT_FD_READ and
404 void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
407 * Query whether tevent supports signal handling
409 * @param[in] ev An initialized tevent context
411 * @return True if this platform and tevent context support signal handling
413 bool tevent_signal_support(struct tevent_context *ev);
415 void tevent_set_abort_fn(void (*abort_fn)(const char *reason));
417 /* bits for file descriptor event flags */
420 * Monitor a file descriptor for write availability
422 #define TEVENT_FD_READ 1
424 * Monitor a file descriptor for data to be read
426 #define TEVENT_FD_WRITE 2
429 * Convenience function for declaring a tevent_fd writable
431 #define TEVENT_FD_WRITEABLE(fde) \
432 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) | TEVENT_FD_WRITE)
435 * Convenience function for declaring a tevent_fd readable
437 #define TEVENT_FD_READABLE(fde) \
438 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) | TEVENT_FD_READ)
441 * Convenience function for declaring a tevent_fd non-writable
443 #define TEVENT_FD_NOT_WRITEABLE(fde) \
444 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_WRITE)
447 * Convenience function for declaring a tevent_fd non-readable
449 #define TEVENT_FD_NOT_READABLE(fde) \
450 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_READ)
453 * Debug level of tevent
455 enum tevent_debug_level {
458 TEVENT_DEBUG_WARNING,
463 * @brief The tevent debug callbac.
465 * @param[in] context The memory context to use.
467 * @param[in] level The debug level.
469 * @param[in] fmt The format string.
471 * @param[in] ap The arguments for the format string.
473 typedef void (*tevent_debug_fn)(void *context,
474 enum tevent_debug_level level,
476 va_list ap) PRINTF_ATTRIBUTE(3,0);
479 * Set destination for tevent debug messages
481 * @param[in] ev Event context to debug
482 * @param[in] debug Function to handle output printing
483 * @param[in] context The context to pass to the debug function.
485 * @return Always returns 0 as of version 0.9.8
487 * @note Default is to emit no debug messages
489 int tevent_set_debug(struct tevent_context *ev,
490 tevent_debug_fn debug,
494 * Designate stderr for debug message output
496 * @param[in] ev Event context to debug
498 * @note This function will only output TEVENT_DEBUG_FATAL, TEVENT_DEBUG_ERROR
499 * and TEVENT_DEBUG_WARNING messages. For TEVENT_DEBUG_TRACE, please define a
500 * function for tevent_set_debug()
502 int tevent_set_debug_stderr(struct tevent_context *ev);
509 * @defgroup tevent_request The tevent request functions.
512 * This represents an async request being processed by callbacks via an event
513 * context. A user can issue for example a write request to a socket, giving
514 * an implementation function the fd, the buffer and the number of bytes to
515 * transfer. The function issuing the request will immediately return without
516 * blocking most likely without having sent anything. The API user then fills
517 * in req->async.fn and req->async.private_data, functions that are called
518 * when the request is finished.
520 * It is up to the user of the async request to talloc_free it after it has
521 * finished. This can happen while the completion function is called.
527 * An async request moves between the following 4 states:
529 enum tevent_req_state {
531 * we are creating the request
535 * we are waiting the request to complete
537 TEVENT_REQ_IN_PROGRESS,
539 * the request is finished
543 * A user error has occurred
545 TEVENT_REQ_USER_ERROR,
549 TEVENT_REQ_TIMED_OUT,
551 * No memory in between
553 TEVENT_REQ_NO_MEMORY,
555 * the request is already received by the caller
561 * @brief An async request
566 * @brief A tevent request callback function.
568 * @param[in] req The tevent async request which executed this callback.
570 typedef void (*tevent_req_fn)(struct tevent_req *req);
573 * @brief Set an async request callback.
575 * @param[in] req The async request to set the callback.
577 * @param[in] fn The callback function to set.
579 * @param[in] pvt A pointer to private data to pass to the async request
582 void tevent_req_set_callback(struct tevent_req *req, tevent_req_fn fn, void *pvt);
586 * @brief Get the private data casted to the given type for a callback from
587 * a tevent request structure.
589 * @param[in] req The structure to get the callback data from.
591 * @param[in] type The type of the private callback data to get.
593 * @return The type casted private data set NULL if not set.
595 void *tevent_req_callback_data(struct tevent_req *req, #type);
597 void *_tevent_req_callback_data(struct tevent_req *req);
598 #define tevent_req_callback_data(_req, _type) \
599 talloc_get_type_abort(_tevent_req_callback_data(_req), _type)
604 * @brief Get the private data for a callback from a tevent request structure.
606 * @param[in] req The structure to get the callback data from.
608 * @param[in] req The structure to get the data from.
610 * @return The private data or NULL if not set.
612 void *tevent_req_callback_data_void(struct tevent_req *req);
614 #define tevent_req_callback_data_void(_req) \
615 _tevent_req_callback_data(_req)
620 * @brief Get the private data from a tevent request structure.
622 * @param[in] req The structure to get the private data from.
624 * @return The private data or NULL if not set.
626 void *tevent_req_data(struct tevent_req *req);
628 void *_tevent_req_data(struct tevent_req *req);
629 #define tevent_req_data(_req, _type) \
630 talloc_get_type_abort(_tevent_req_data(_req), _type)
633 typedef char *(*tevent_req_print_fn)(struct tevent_req *, TALLOC_CTX *);
636 * @brief This function sets a print function for the given request.
638 * This function can be used to setup a print function for the given request.
639 * This will be triggered if the tevent_req_print() function was
640 * called on the given request.
642 * @param[in] req The request to use.
644 * @param[in] fn A pointer to the print function
646 * @note This function should only be used for debugging.
648 void tevent_req_set_print_fn(struct tevent_req *req, tevent_req_print_fn fn);
651 * @brief The default print function for creating debug messages.
653 * The function should not be used by users of the async API,
654 * but custom print function can use it and append custom text
657 * @param[in] req The request to be printed.
659 * @param[in] mem_ctx The memory context for the result.
661 * @return Text representation of request.
664 char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx);
667 * @brief Print an tevent_req structure in debug messages.
669 * This function should be used by callers of the async API.
671 * @param[in] mem_ctx The memory context for the result.
673 * @param[in] req The request to be printed.
675 * @return Text representation of request.
677 char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req);
679 typedef bool (*tevent_req_cancel_fn)(struct tevent_req *);
682 * @brief This function sets a cancel function for the given tevent request.
684 * This function can be used to setup a cancel function for the given request.
685 * This will be triggered if the tevent_req_cancel() function was
686 * called on the given request.
688 * @param[in] req The request to use.
690 * @param[in] fn A pointer to the cancel function.
692 void tevent_req_set_cancel_fn(struct tevent_req *req, tevent_req_cancel_fn fn);
696 * @brief Try to cancel the given tevent request.
698 * This function can be used to cancel the given request.
700 * It is only possible to cancel a request when the implementation
701 * has registered a cancel function via the tevent_req_set_cancel_fn().
703 * @param[in] req The request to use.
705 * @return This function returns true is the request is cancelable,
706 * othererwise false is returned.
708 * @note Even if the function returns true, the caller need to wait
709 * for the function to complete normally.
710 * Only the _recv() function of the given request indicates
711 * if the request was really canceled.
713 bool tevent_req_cancel(struct tevent_req *req);
715 bool _tevent_req_cancel(struct tevent_req *req, const char *location);
716 #define tevent_req_cancel(req) \
717 _tevent_req_cancel(req, __location__)
722 * @brief Create an async tevent request.
724 * The new async request will be initialized in state ASYNC_REQ_IN_PROGRESS.
726 * @param[in] mem_ctx The memory context for the result.
728 * @param[in] pstate The private state of the request.
730 * @param[in] state_size The size of the private state of the request.
732 * @param[in] type The name of the request.
734 * @return A new async request. NULL on error.
736 struct tevent_req *tevent_req_create(TALLOC_CTX *mem_ctx,
741 struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx,
745 const char *location);
747 #define tevent_req_create(_mem_ctx, _pstate, _type) \
748 _tevent_req_create((_mem_ctx), (_pstate), sizeof(_type), \
749 #_type, __location__)
753 * @brief Set a timeout for an async request.
755 * @param[in] req The request to set the timeout for.
757 * @param[in] ev The event context to use for the timer.
759 * @param[in] endtime The endtime of the request.
761 * @return True if succeeded, false if not.
763 bool tevent_req_set_endtime(struct tevent_req *req,
764 struct tevent_context *ev,
765 struct timeval endtime);
769 * @brief Call the notify callback of the given tevent request manually.
771 * @param[in] req The tevent request to call the notify function from.
773 * @see tevent_req_set_callback()
775 void tevent_req_notify_callback(struct tevent_req *req);
777 void _tevent_req_notify_callback(struct tevent_req *req, const char *location);
778 #define tevent_req_notify_callback(req) \
779 _tevent_req_notify_callback(req, __location__)
784 * @brief An async request has successfully finished.
786 * This function is to be used by implementors of async requests. When a
787 * request is successfully finished, this function calls the user's completion
790 * @param[in] req The finished request.
792 void tevent_req_done(struct tevent_req *req);
794 void _tevent_req_done(struct tevent_req *req,
795 const char *location);
796 #define tevent_req_done(req) \
797 _tevent_req_done(req, __location__)
802 * @brief An async request has seen an error.
804 * This function is to be used by implementors of async requests. When a
805 * request can not successfully completed, the implementation should call this
806 * function with the appropriate status code.
808 * If error is 0 the function returns false and does nothing more.
810 * @param[in] req The request with an error.
812 * @param[in] error The error code.
814 * @return On success true is returned, false if error is 0.
817 * int error = first_function();
818 * if (tevent_req_error(req, error)) {
822 * error = second_function();
823 * if (tevent_req_error(req, error)) {
827 * tevent_req_done(req);
831 bool tevent_req_error(struct tevent_req *req,
834 bool _tevent_req_error(struct tevent_req *req,
836 const char *location);
837 #define tevent_req_error(req, error) \
838 _tevent_req_error(req, error, __location__)
843 * @brief Helper function for nomem check.
845 * Convenience helper to easily check alloc failure within a callback
846 * implementing the next step of an async request.
848 * @param[in] p The pointer to be checked.
850 * @param[in] req The request being processed.
853 * p = talloc(mem_ctx, bla);
854 * if (tevent_req_nomem(p, req)) {
859 bool tevent_req_nomem(const void *p,
860 struct tevent_req *req);
862 bool _tevent_req_nomem(const void *p,
863 struct tevent_req *req,
864 const char *location);
865 #define tevent_req_nomem(p, req) \
866 _tevent_req_nomem(p, req, __location__)
870 * @brief Finish a request before the caller had the change to set the callback.
872 * An implementation of an async request might find that it can either finish
873 * the request without waiting for an external event, or it can't even start
874 * the engine. To present the illusion of a callback to the user of the API,
875 * the implementation can call this helper function which triggers an
876 * immediate timed event. This way the caller can use the same calling
877 * conventions, independent of whether the request was actually deferred.
879 * @param[in] req The finished request.
881 * @param[in] ev The tevent_context for the timed event.
883 * @return The given request will be returned.
885 struct tevent_req *tevent_req_post(struct tevent_req *req,
886 struct tevent_context *ev);
889 * @brief Check if the given request is still in progress.
891 * It is typically used by sync wrapper functions.
893 * This function destroys the attached private data.
895 * @param[in] req The request to poll.
897 * @return The boolean form of "is in progress".
899 bool tevent_req_is_in_progress(struct tevent_req *req);
902 * @brief Actively poll for the given request to finish.
904 * This function is typically used by sync wrapper functions.
906 * @param[in] req The request to poll.
908 * @param[in] ev The tevent_context to be used.
910 * @return On success true is returned. If a critical error has
911 * happened in the tevent loop layer false is returned.
912 * This is not the return value of the given request!
914 * @note This should only be used if the given tevent context was created by the
915 * caller, to avoid event loop nesting.
918 * req = tstream_writev_queue_send(mem_ctx,
923 * ok = tevent_req_poll(req, tctx->ev);
924 * rc = tstream_writev_queue_recv(req, &sys_errno);
928 bool tevent_req_poll(struct tevent_req *req,
929 struct tevent_context *ev);
932 * @brief Get the tevent request and the actual error code you've set.
934 * @param[in] req The tevent request to get the error from.
936 * @param[out] state A pointer to store the tevent request error state.
938 * @param[out] error A pointer to store the error set by tevent_req_error().
940 * @return True if the function could set error and state, false
943 * @see tevent_req_error()
945 bool tevent_req_is_error(struct tevent_req *req,
946 enum tevent_req_state *state,
950 * @brief Use as the last action of a _recv() function.
952 * This function destroys the attached private data.
954 * @param[in] req The finished request.
956 void tevent_req_received(struct tevent_req *req);
959 * @brief Create a tevent subrequest at a given time.
961 * The idea is that always the same syntax for tevent requests.
963 * @param[in] mem_ctx The talloc memory context to use.
965 * @param[in] ev The event handle to setup the request.
967 * @param[in] wakeup_time The time to wakeup and execute the request.
969 * @return The new subrequest, NULL on error.
973 * static my_callback_wakeup_done(tevent_req *req)
975 * struct tevent_req *req = tevent_req_callback_data(subreq,
976 * struct tevent_req);
979 * ok = tevent_wakeup_recv(subreq);
980 * TALLOC_FREE(subreq);
982 * tevent_req_error(req, -1);
990 * subreq = tevent_wakeup_send(mem_ctx, ev, wakeup_time);
991 * if (tevent_req_nomem(subreq, req)) {
994 * tevent_set_callback(subreq, my_callback_wakeup_done, req);
997 * @see tevent_wakeup_recv()
999 struct tevent_req *tevent_wakeup_send(TALLOC_CTX *mem_ctx,
1000 struct tevent_context *ev,
1001 struct timeval wakeup_time);
1004 * @brief Check if the wakeup has been correctly executed.
1006 * This function needs to be called in the callback function set after calling
1007 * tevent_wakeup_send().
1009 * @param[in] req The tevent request to check.
1011 * @return True on success, false otherwise.
1013 * @see tevent_wakeup_recv()
1015 bool tevent_wakeup_recv(struct tevent_req *req);
1020 * @defgroup tevent_helpers The tevent helper functiions
1028 int tevent_timeval_compare(const struct timeval *tv1,
1029 const struct timeval *tv2);
1031 struct timeval tevent_timeval_zero(void);
1033 struct timeval tevent_timeval_current(void);
1035 struct timeval tevent_timeval_set(uint32_t secs, uint32_t usecs);
1037 struct timeval tevent_timeval_until(const struct timeval *tv1,
1038 const struct timeval *tv2);
1040 bool tevent_timeval_is_zero(const struct timeval *tv);
1042 struct timeval tevent_timeval_add(const struct timeval *tv, uint32_t secs,
1045 struct timeval tevent_timeval_current_ofs(uint32_t secs, uint32_t usecs);
1051 * @defgroup tevent_queue The tevent queue functions
1057 struct tevent_queue;
1059 struct tevent_queue *_tevent_queue_create(TALLOC_CTX *mem_ctx,
1061 const char *location);
1063 #define tevent_queue_create(_mem_ctx, _name) \
1064 _tevent_queue_create((_mem_ctx), (_name), __location__)
1066 typedef void (*tevent_queue_trigger_fn_t)(struct tevent_req *req,
1067 void *private_data);
1068 bool tevent_queue_add(struct tevent_queue *queue,
1069 struct tevent_context *ev,
1070 struct tevent_req *req,
1071 tevent_queue_trigger_fn_t trigger,
1072 void *private_data);
1073 void tevent_queue_start(struct tevent_queue *queue);
1074 void tevent_queue_stop(struct tevent_queue *queue);
1076 size_t tevent_queue_length(struct tevent_queue *queue);
1078 typedef int (*tevent_nesting_hook)(struct tevent_context *ev,
1083 const char *location);
1084 #ifdef TEVENT_DEPRECATED
1085 #ifndef _DEPRECATED_
1086 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
1087 #define _DEPRECATED_ __attribute__ ((deprecated))
1089 #define _DEPRECATED_
1092 void tevent_loop_allow_nesting(struct tevent_context *ev) _DEPRECATED_;
1093 void tevent_loop_set_nesting_hook(struct tevent_context *ev,
1094 tevent_nesting_hook hook,
1095 void *private_data) _DEPRECATED_;
1096 int _tevent_loop_until(struct tevent_context *ev,
1097 bool (*finished)(void *private_data),
1099 const char *location) _DEPRECATED_;
1100 #define tevent_loop_until(ev, finished, private_data) \
1101 _tevent_loop_until(ev, finished, private_data, __location__)
1104 int tevent_re_initialise(struct tevent_context *ev);
1109 * @defgroup tevent_ops The tevent operation functions
1112 * The following structure and registration functions are exclusively
1113 * needed for people writing and pluggin a different event engine.
1114 * There is nothing useful for normal tevent user in here.
1120 int (*context_init)(struct tevent_context *ev);
1122 /* fd_event functions */
1123 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
1124 TALLOC_CTX *mem_ctx,
1125 int fd, uint16_t flags,
1126 tevent_fd_handler_t handler,
1128 const char *handler_name,
1129 const char *location);
1130 void (*set_fd_close_fn)(struct tevent_fd *fde,
1131 tevent_fd_close_fn_t close_fn);
1132 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
1133 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
1135 /* timed_event functions */
1136 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
1137 TALLOC_CTX *mem_ctx,
1138 struct timeval next_event,
1139 tevent_timer_handler_t handler,
1141 const char *handler_name,
1142 const char *location);
1144 /* immediate event functions */
1145 void (*schedule_immediate)(struct tevent_immediate *im,
1146 struct tevent_context *ev,
1147 tevent_immediate_handler_t handler,
1149 const char *handler_name,
1150 const char *location);
1152 /* signal functions */
1153 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
1154 TALLOC_CTX *mem_ctx,
1155 int signum, int sa_flags,
1156 tevent_signal_handler_t handler,
1158 const char *handler_name,
1159 const char *location);
1161 /* loop functions */
1162 int (*loop_once)(struct tevent_context *ev, const char *location);
1163 int (*loop_wait)(struct tevent_context *ev, const char *location);
1166 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
1171 * @defgroup tevent_compat The tevent compatibility functions
1174 * The following definitions are usueful only for compatibility with the
1175 * implementation originally developed within the samba4 code and will be
1176 * soon removed. Please NEVER use in new code.
1183 #ifdef TEVENT_COMPAT_DEFINES
1185 #define event_context tevent_context
1186 #define event_ops tevent_ops
1187 #define fd_event tevent_fd
1188 #define timed_event tevent_timer
1189 #define signal_event tevent_signal
1191 #define event_fd_handler_t tevent_fd_handler_t
1192 #define event_timed_handler_t tevent_timer_handler_t
1193 #define event_signal_handler_t tevent_signal_handler_t
1195 #define event_context_init(mem_ctx) \
1196 tevent_context_init(mem_ctx)
1198 #define event_context_init_byname(mem_ctx, name) \
1199 tevent_context_init_byname(mem_ctx, name)
1201 #define event_backend_list(mem_ctx) \
1202 tevent_backend_list(mem_ctx)
1204 #define event_set_default_backend(backend) \
1205 tevent_set_default_backend(backend)
1207 #define event_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \
1208 tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data)
1210 #define event_add_timed(ev, mem_ctx, next_event, handler, private_data) \
1211 tevent_add_timer(ev, mem_ctx, next_event, handler, private_data)
1213 #define event_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \
1214 tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data)
1216 #define event_loop_once(ev) \
1217 tevent_loop_once(ev)
1219 #define event_loop_wait(ev) \
1220 tevent_loop_wait(ev)
1222 #define event_get_fd_flags(fde) \
1223 tevent_fd_get_flags(fde)
1225 #define event_set_fd_flags(fde, flags) \
1226 tevent_fd_set_flags(fde, flags)
1228 #define EVENT_FD_READ TEVENT_FD_READ
1229 #define EVENT_FD_WRITE TEVENT_FD_WRITE
1231 #define EVENT_FD_WRITEABLE(fde) \
1232 TEVENT_FD_WRITEABLE(fde)
1234 #define EVENT_FD_READABLE(fde) \
1235 TEVENT_FD_READABLE(fde)
1237 #define EVENT_FD_NOT_WRITEABLE(fde) \
1238 TEVENT_FD_NOT_WRITEABLE(fde)
1240 #define EVENT_FD_NOT_READABLE(fde) \
1241 TEVENT_FD_NOT_READABLE(fde)
1243 #define ev_debug_level tevent_debug_level
1245 #define EV_DEBUG_FATAL TEVENT_DEBUG_FATAL
1246 #define EV_DEBUG_ERROR TEVENT_DEBUG_ERROR
1247 #define EV_DEBUG_WARNING TEVENT_DEBUG_WARNING
1248 #define EV_DEBUG_TRACE TEVENT_DEBUG_TRACE
1250 #define ev_set_debug(ev, debug, context) \
1251 tevent_set_debug(ev, debug, context)
1253 #define ev_set_debug_stderr(_ev) tevent_set_debug_stderr(ev)
1255 #endif /* TEVENT_COMPAT_DEFINES */
1259 #endif /* __TEVENT_H__ */