smbXsrv_session:idl: remove the preauth and gensec members
[Samba.git] / lib / tevent / tevent.h
blobb6c39d1037b2c8f2c88d29b049d93fec542b0bae
1 /*
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
12 ** under the LGPL
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/>.
28 #ifndef __TEVENT_H__
29 #define __TEVENT_H__
31 #include <stdint.h>
32 #include <talloc.h>
33 #include <sys/time.h>
34 #include <stdbool.h>
36 struct tevent_context;
37 struct tevent_ops;
38 struct tevent_fd;
39 struct tevent_timer;
40 struct tevent_immediate;
41 struct tevent_signal;
43 /**
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.
52 * @{
55 /* event handler types */
56 /**
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,
62 uint16_t flags,
63 void *private_data);
65 /**
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,
70 int fd,
71 void *private_data);
73 /**
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,
79 void *private_data);
81 /**
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,
86 void *private_data);
88 /**
89 * Called after tevent detects the specified signal.
91 typedef void (*tevent_signal_handler_t)(struct tevent_context *ev,
92 struct tevent_signal *se,
93 int signum,
94 int count,
95 void *siginfo,
96 void *private_data);
98 /**
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 select a specific backend.
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 of the backend to use.
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 Create a custom event context
131 * @param[in] mem_ctx The memory context to use.
132 * @param[in] ops The function pointer table of the backend.
133 * @param[in] additional_data The additional/private data to this instance
135 * @return An allocated tevent context, NULL on error.
138 struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
139 const struct tevent_ops *ops,
140 void *additional_data);
143 * @brief List available backends.
145 * @param[in] mem_ctx The memory context to use.
147 * @return A string vector with a terminating NULL element, NULL
148 * on error.
150 const char **tevent_backend_list(TALLOC_CTX *mem_ctx);
153 * @brief Set the default tevent backend.
155 * @param[in] backend The name of the backend to set.
157 void tevent_set_default_backend(const char *backend);
159 #ifdef DOXYGEN
161 * @brief Add a file descriptor based event.
163 * @param[in] ev The event context to work on.
165 * @param[in] mem_ctx The talloc memory context to use.
167 * @param[in] fd The file descriptor to base the event on.
169 * @param[in] flags #TEVENT_FD_READ or #TEVENT_FD_WRITE
171 * @param[in] handler The callback handler for the event.
173 * @param[in] private_data The private data passed to the callback handler.
175 * @return The file descriptor based event, NULL on error.
177 * @note To cancel the monitoring of a file descriptor, call talloc_free()
178 * on the object returned by this function.
180 * @note The caller should avoid closing the file descriptor before
181 * calling talloc_free()! Otherwise the behaviour is undefined which
182 * might result in crashes. See https://bugzilla.samba.org/show_bug.cgi?id=11141
183 * for an example.
185 struct tevent_fd *tevent_add_fd(struct tevent_context *ev,
186 TALLOC_CTX *mem_ctx,
187 int fd,
188 uint16_t flags,
189 tevent_fd_handler_t handler,
190 void *private_data);
191 #else
192 struct tevent_fd *_tevent_add_fd(struct tevent_context *ev,
193 TALLOC_CTX *mem_ctx,
194 int fd,
195 uint16_t flags,
196 tevent_fd_handler_t handler,
197 void *private_data,
198 const char *handler_name,
199 const char *location);
200 #define tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \
201 _tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data, \
202 #handler, __location__)
203 #endif
205 #ifdef DOXYGEN
207 * @brief Add a timed event
209 * @param[in] ev The event context to work on.
211 * @param[in] mem_ctx The talloc memory context to use.
213 * @param[in] next_event Timeval specifying the absolute time to fire this
214 * event. This is not an offset.
216 * @param[in] handler The callback handler for the event.
218 * @param[in] private_data The private data passed to the callback handler.
220 * @return The newly-created timer event, or NULL on error.
222 * @note To cancel a timer event before it fires, call talloc_free() on the
223 * event returned from this function. This event is automatically
224 * talloc_free()-ed after its event handler files, if it hasn't been freed yet.
226 * @note Unlike some mainloops, tevent timers are one-time events. To set up
227 * a recurring event, it is necessary to call tevent_add_timer() again during
228 * the handler processing.
230 * @note Due to the internal mainloop processing, a timer set to run
231 * immediately will do so after any other pending timers fire, but before
232 * any further file descriptor or signal handling events fire. Callers should
233 * not rely on this behavior!
235 struct tevent_timer *tevent_add_timer(struct tevent_context *ev,
236 TALLOC_CTX *mem_ctx,
237 struct timeval next_event,
238 tevent_timer_handler_t handler,
239 void *private_data);
240 #else
241 struct tevent_timer *_tevent_add_timer(struct tevent_context *ev,
242 TALLOC_CTX *mem_ctx,
243 struct timeval next_event,
244 tevent_timer_handler_t handler,
245 void *private_data,
246 const char *handler_name,
247 const char *location);
248 #define tevent_add_timer(ev, mem_ctx, next_event, handler, private_data) \
249 _tevent_add_timer(ev, mem_ctx, next_event, handler, private_data, \
250 #handler, __location__)
251 #endif
253 #ifdef DOXYGEN
255 * Initialize an immediate event object
257 * This object can be used to trigger an event to occur immediately after
258 * returning from the current event (before any other event occurs)
260 * @param[in] mem_ctx The talloc memory context to use as the parent
262 * @return An empty tevent_immediate object. Use tevent_schedule_immediate
263 * to populate and use it.
265 * @note Available as of tevent 0.9.8
267 struct tevent_immediate *tevent_create_immediate(TALLOC_CTX *mem_ctx);
268 #else
269 struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx,
270 const char *location);
271 #define tevent_create_immediate(mem_ctx) \
272 _tevent_create_immediate(mem_ctx, __location__)
273 #endif
275 #ifdef DOXYGEN
278 * Schedule an event for immediate execution. This event will occur
279 * immediately after returning from the current event (before any other
280 * event occurs)
282 * @param[in] im The tevent_immediate object to populate and use
283 * @param[in] ctx The tevent_context to run this event
284 * @param[in] handler The event handler to run when this event fires
285 * @param[in] private_data Data to pass to the event handler
287 void tevent_schedule_immediate(struct tevent_immediate *im,
288 struct tevent_context *ctx,
289 tevent_immediate_handler_t handler,
290 void *private_data);
291 #else
292 void _tevent_schedule_immediate(struct tevent_immediate *im,
293 struct tevent_context *ctx,
294 tevent_immediate_handler_t handler,
295 void *private_data,
296 const char *handler_name,
297 const char *location);
298 #define tevent_schedule_immediate(im, ctx, handler, private_data) \
299 _tevent_schedule_immediate(im, ctx, handler, private_data, \
300 #handler, __location__);
301 #endif
303 #ifdef DOXYGEN
305 * @brief Add a tevent signal handler
307 * tevent_add_signal() creates a new event for handling a signal the next
308 * time through the mainloop. It implements a very simple traditional signal
309 * handler whose only purpose is to add the handler event into the mainloop.
311 * @param[in] ev The event context to work on.
313 * @param[in] mem_ctx The talloc memory context to use.
315 * @param[in] signum The signal to trap
317 * @param[in] handler The callback handler for the signal.
319 * @param[in] sa_flags sigaction flags for this signal handler.
321 * @param[in] private_data The private data passed to the callback handler.
323 * @return The newly-created signal handler event, or NULL on error.
325 * @note To cancel a signal handler, call talloc_free() on the event returned
326 * from this function.
328 * @see tevent_num_signals, tevent_sa_info_queue_count
330 struct tevent_signal *tevent_add_signal(struct tevent_context *ev,
331 TALLOC_CTX *mem_ctx,
332 int signum,
333 int sa_flags,
334 tevent_signal_handler_t handler,
335 void *private_data);
336 #else
337 struct tevent_signal *_tevent_add_signal(struct tevent_context *ev,
338 TALLOC_CTX *mem_ctx,
339 int signum,
340 int sa_flags,
341 tevent_signal_handler_t handler,
342 void *private_data,
343 const char *handler_name,
344 const char *location);
345 #define tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \
346 _tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data, \
347 #handler, __location__)
348 #endif
351 * @brief the number of supported signals
353 * This returns value of the configure time TEVENT_NUM_SIGNALS constant.
355 * The 'signum' argument of tevent_add_signal() must be less than
356 * TEVENT_NUM_SIGNALS.
358 * @see tevent_add_signal
360 size_t tevent_num_signals(void);
363 * @brief the number of pending realtime signals
365 * This returns value of TEVENT_SA_INFO_QUEUE_COUNT.
367 * The tevent internals remember the last TEVENT_SA_INFO_QUEUE_COUNT
368 * siginfo_t structures for SA_SIGINFO signals. If the system generates
369 * more some signals get lost.
371 * @see tevent_add_signal
373 size_t tevent_sa_info_queue_count(void);
375 #ifdef DOXYGEN
377 * @brief Pass a single time through the mainloop
379 * This will process any appropriate signal, immediate, fd and timer events
381 * @param[in] ev The event context to process
383 * @return Zero on success, nonzero if an internal error occurred
385 int tevent_loop_once(struct tevent_context *ev);
386 #else
387 int _tevent_loop_once(struct tevent_context *ev, const char *location);
388 #define tevent_loop_once(ev) \
389 _tevent_loop_once(ev, __location__)
390 #endif
392 #ifdef DOXYGEN
394 * @brief Run the mainloop
396 * The mainloop will run until there are no events remaining to be processed
398 * @param[in] ev The event context to process
400 * @return Zero if all events have been processed. Nonzero if an internal
401 * error occurred.
403 int tevent_loop_wait(struct tevent_context *ev);
404 #else
405 int _tevent_loop_wait(struct tevent_context *ev, const char *location);
406 #define tevent_loop_wait(ev) \
407 _tevent_loop_wait(ev, __location__)
408 #endif
412 * Assign a function to run when a tevent_fd is freed
414 * This function is a destructor for the tevent_fd. It does not automatically
415 * close the file descriptor. If this is the desired behavior, then it must be
416 * performed by the close_fn.
418 * @param[in] fde File descriptor event on which to set the destructor
419 * @param[in] close_fn Destructor to execute when fde is freed
421 void tevent_fd_set_close_fn(struct tevent_fd *fde,
422 tevent_fd_close_fn_t close_fn);
425 * Automatically close the file descriptor when the tevent_fd is freed
427 * This function calls close(fd) internally.
429 * @param[in] fde File descriptor event to auto-close
431 void tevent_fd_set_auto_close(struct tevent_fd *fde);
434 * Return the flags set on this file descriptor event
436 * @param[in] fde File descriptor event to query
438 * @return The flags set on the event. See #TEVENT_FD_READ and
439 * #TEVENT_FD_WRITE
441 uint16_t tevent_fd_get_flags(struct tevent_fd *fde);
444 * Set flags on a file descriptor event
446 * @param[in] fde File descriptor event to set
447 * @param[in] flags Flags to set on the event. See #TEVENT_FD_READ and
448 * #TEVENT_FD_WRITE
450 void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
453 * Query whether tevent supports signal handling
455 * @param[in] ev An initialized tevent context
457 * @return True if this platform and tevent context support signal handling
459 bool tevent_signal_support(struct tevent_context *ev);
461 void tevent_set_abort_fn(void (*abort_fn)(const char *reason));
463 /* bits for file descriptor event flags */
466 * Monitor a file descriptor for write availability
468 #define TEVENT_FD_READ 1
470 * Monitor a file descriptor for data to be read
472 #define TEVENT_FD_WRITE 2
475 * Convenience function for declaring a tevent_fd writable
477 #define TEVENT_FD_WRITEABLE(fde) \
478 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) | TEVENT_FD_WRITE)
481 * Convenience function for declaring a tevent_fd readable
483 #define TEVENT_FD_READABLE(fde) \
484 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) | TEVENT_FD_READ)
487 * Convenience function for declaring a tevent_fd non-writable
489 #define TEVENT_FD_NOT_WRITEABLE(fde) \
490 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_WRITE)
493 * Convenience function for declaring a tevent_fd non-readable
495 #define TEVENT_FD_NOT_READABLE(fde) \
496 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_READ)
499 * Debug level of tevent
501 enum tevent_debug_level {
502 TEVENT_DEBUG_FATAL,
503 TEVENT_DEBUG_ERROR,
504 TEVENT_DEBUG_WARNING,
505 TEVENT_DEBUG_TRACE
509 * @brief The tevent debug callbac.
511 * @param[in] context The memory context to use.
513 * @param[in] level The debug level.
515 * @param[in] fmt The format string.
517 * @param[in] ap The arguments for the format string.
519 typedef void (*tevent_debug_fn)(void *context,
520 enum tevent_debug_level level,
521 const char *fmt,
522 va_list ap) PRINTF_ATTRIBUTE(3,0);
525 * Set destination for tevent debug messages
527 * @param[in] ev Event context to debug
528 * @param[in] debug Function to handle output printing
529 * @param[in] context The context to pass to the debug function.
531 * @return Always returns 0 as of version 0.9.8
533 * @note Default is to emit no debug messages
535 int tevent_set_debug(struct tevent_context *ev,
536 tevent_debug_fn debug,
537 void *context);
540 * Designate stderr for debug message output
542 * @param[in] ev Event context to debug
544 * @note This function will only output TEVENT_DEBUG_FATAL, TEVENT_DEBUG_ERROR
545 * and TEVENT_DEBUG_WARNING messages. For TEVENT_DEBUG_TRACE, please define a
546 * function for tevent_set_debug()
548 int tevent_set_debug_stderr(struct tevent_context *ev);
550 enum tevent_trace_point {
552 * Corresponds to a trace point just before waiting
554 TEVENT_TRACE_BEFORE_WAIT,
556 * Corresponds to a trace point just after waiting
558 TEVENT_TRACE_AFTER_WAIT,
559 #define TEVENT_HAS_LOOP_ONCE_TRACE_POINTS 1
561 * Corresponds to a trace point just before calling
562 * the loop_once() backend function.
564 TEVENT_TRACE_BEFORE_LOOP_ONCE,
566 * Corresponds to a trace point right after the
567 * loop_once() backend function has returned.
569 TEVENT_TRACE_AFTER_LOOP_ONCE,
572 typedef void (*tevent_trace_callback_t)(enum tevent_trace_point,
573 void *private_data);
576 * Register a callback to be called at certain trace points
578 * @param[in] ev Event context
579 * @param[in] cb Trace callback
580 * @param[in] private_data Data to be passed to callback
582 * @note The callback will be called at trace points defined by
583 * tevent_trace_point. Call with NULL to reset.
585 void tevent_set_trace_callback(struct tevent_context *ev,
586 tevent_trace_callback_t cb,
587 void *private_data);
590 * Retrieve the current trace callback
592 * @param[in] ev Event context
593 * @param[out] cb Registered trace callback
594 * @param[out] private_data Registered data to be passed to callback
596 * @note This can be used to allow one component that wants to
597 * register a callback to respect the callback that another component
598 * has already registered.
600 void tevent_get_trace_callback(struct tevent_context *ev,
601 tevent_trace_callback_t *cb,
602 void *private_data);
605 * @}
609 * @defgroup tevent_request The tevent request functions.
610 * @ingroup tevent
612 * A tevent_req represents an asynchronous computation.
614 * The tevent_req group of API calls is the recommended way of
615 * programming async computations within tevent. In particular the
616 * file descriptor (tevent_add_fd) and timer (tevent_add_timed) events
617 * are considered too low-level to be used in larger computations. To
618 * read and write from and to sockets, Samba provides two calls on top
619 * of tevent_add_fd: tstream_read_packet_send/recv and tstream_writev_send/recv.
620 * These requests are much easier to compose than the low-level event
621 * handlers called from tevent_add_fd.
623 * A lot of the simplicity tevent_req has brought to the notoriously
624 * hairy async programming came via a set of conventions that every
625 * async computation programmed should follow. One central piece of
626 * these conventions is the naming of routines and variables.
628 * Every async computation needs a name (sensibly called "computation"
629 * down from here). From this name quite a few naming conventions are
630 * derived.
632 * Every computation that requires local state needs a
633 * @code
634 * struct computation_state {
635 * int local_var;
636 * };
637 * @endcode
638 * Even if no local variables are required, such a state struct should
639 * be created containing a dummy variable. Quite a few helper
640 * functions and macros (for example tevent_req_create()) assume such
641 * a state struct.
643 * An async computation is started by a computation_send
644 * function. When it is finished, its result can be received by a
645 * computation_recv function. For an example how to set up an async
646 * computation, see the code example in the documentation for
647 * tevent_req_create() and tevent_req_post(). The prototypes for _send
648 * and _recv functions should follow some conventions:
650 * @code
651 * struct tevent_req *computation_send(TALLOC_CTX *mem_ctx,
652 * struct tevent_req *ev,
653 * ... further args);
654 * int computation_recv(struct tevent_req *req, ... further output args);
655 * @endcode
657 * The "int" result of computation_recv() depends on the result the
658 * sync version of the function would have, "int" is just an example
659 * here.
661 * Another important piece of the conventions is that the program flow
662 * is interrupted as little as possible. Because a blocking
663 * sub-computation requires that the flow needs to continue in a
664 * separate function that is the logical sequel of some computation,
665 * it should lexically follow sending off the blocking
666 * sub-computation. Setting the callback function via
667 * tevent_req_set_callback() requires referencing a function lexically
668 * below the call to tevent_req_set_callback(), forward declarations
669 * are required. A lot of the async computations thus begin with a
670 * sequence of declarations such as
672 * @code
673 * static void computation_step1_done(struct tevent_req *subreq);
674 * static void computation_step2_done(struct tevent_req *subreq);
675 * static void computation_step3_done(struct tevent_req *subreq);
676 * @endcode
678 * It really helps readability a lot to do these forward declarations,
679 * because the lexically sequential program flow makes the async
680 * computations almost as clear to read as a normal, sync program
681 * flow.
683 * It is up to the user of the async computation to talloc_free it
684 * after it has finished. If an async computation should be aborted,
685 * the tevent_req structure can be talloc_free'ed. After it has
686 * finished, it should talloc_free'ed by the API user.
688 * @{
692 * An async request moves from TEVENT_REQ_INIT to
693 * TEVENT_REQ_IN_PROGRESS. All other states are valid after a request
694 * has finished.
696 enum tevent_req_state {
698 * We are creating the request
700 TEVENT_REQ_INIT,
702 * We are waiting the request to complete
704 TEVENT_REQ_IN_PROGRESS,
706 * The request is finished successfully
708 TEVENT_REQ_DONE,
710 * A user error has occurred. The user error has been
711 * indicated by tevent_req_error(), it can be retrieved via
712 * tevent_req_is_error().
714 TEVENT_REQ_USER_ERROR,
716 * Request timed out after the timeout set by tevent_req_set_endtime.
718 TEVENT_REQ_TIMED_OUT,
720 * An internal allocation has failed, or tevent_req_nomem has
721 * been given a NULL pointer as the first argument.
723 TEVENT_REQ_NO_MEMORY,
725 * The request has been received by the caller. No further
726 * action is valid.
728 TEVENT_REQ_RECEIVED
732 * @brief An async request
734 struct tevent_req;
737 * @brief A tevent request callback function.
739 * @param[in] req The tevent async request which executed this callback.
741 typedef void (*tevent_req_fn)(struct tevent_req *req);
744 * @brief Set an async request callback.
746 * See the documentation of tevent_req_post() for an example how this
747 * is supposed to be used.
749 * @param[in] req The async request to set the callback.
751 * @param[in] fn The callback function to set.
753 * @param[in] pvt A pointer to private data to pass to the async request
754 * callback.
756 void tevent_req_set_callback(struct tevent_req *req, tevent_req_fn fn, void *pvt);
758 #ifdef DOXYGEN
760 * @brief Get the private data cast to the given type for a callback from
761 * a tevent request structure.
763 * @code
764 * static void computation_done(struct tevent_req *subreq) {
765 * struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
766 * struct computation_state *state = tevent_req_data(req, struct computation_state);
767 * .... more things, eventually maybe call tevent_req_done(req);
769 * @endcode
771 * @param[in] req The structure to get the callback data from.
773 * @param[in] type The type of the private callback data to get.
775 * @return The type casted private data set NULL if not set.
777 void *tevent_req_callback_data(struct tevent_req *req, #type);
778 #else
779 void *_tevent_req_callback_data(struct tevent_req *req);
780 #define tevent_req_callback_data(_req, _type) \
781 talloc_get_type_abort(_tevent_req_callback_data(_req), _type)
782 #endif
784 #ifdef DOXYGEN
786 * @brief Get the private data for a callback from a tevent request structure.
788 * @param[in] req The structure to get the callback data from.
790 * @param[in] req The structure to get the data from.
792 * @return The private data or NULL if not set.
794 void *tevent_req_callback_data_void(struct tevent_req *req);
795 #else
796 #define tevent_req_callback_data_void(_req) \
797 _tevent_req_callback_data(_req)
798 #endif
800 #ifdef DOXYGEN
802 * @brief Get the private data from a tevent request structure.
804 * When the tevent_req has been created by tevent_req_create, the
805 * result of tevent_req_data() is the state variable created by
806 * tevent_req_create() as a child of the req.
808 * @param[in] req The structure to get the private data from.
810 * @param[in] type The type of the private data
812 * @return The private data or NULL if not set.
814 void *tevent_req_data(struct tevent_req *req, #type);
815 #else
816 void *_tevent_req_data(struct tevent_req *req);
817 #define tevent_req_data(_req, _type) \
818 talloc_get_type_abort(_tevent_req_data(_req), _type)
819 #endif
822 * @brief The print function which can be set for a tevent async request.
824 * @param[in] req The tevent async request.
826 * @param[in] ctx A talloc memory context which can be uses to allocate
827 * memory.
829 * @return An allocated string buffer to print.
831 * Example:
832 * @code
833 * static char *my_print(struct tevent_req *req, TALLOC_CTX *mem_ctx)
835 * struct my_data *data = tevent_req_data(req, struct my_data);
836 * char *result;
838 * result = tevent_req_default_print(mem_ctx, req);
839 * if (result == NULL) {
840 * return NULL;
843 * return talloc_asprintf_append_buffer(result, "foo=%d, bar=%d",
844 * data->foo, data->bar);
846 * @endcode
848 typedef char *(*tevent_req_print_fn)(struct tevent_req *req, TALLOC_CTX *ctx);
851 * @brief This function sets a print function for the given request.
853 * This function can be used to setup a print function for the given request.
854 * This will be triggered if the tevent_req_print() function was
855 * called on the given request.
857 * @param[in] req The request to use.
859 * @param[in] fn A pointer to the print function
861 * @note This function should only be used for debugging.
863 void tevent_req_set_print_fn(struct tevent_req *req, tevent_req_print_fn fn);
866 * @brief The default print function for creating debug messages.
868 * The function should not be used by users of the async API,
869 * but custom print function can use it and append custom text
870 * to the string.
872 * @param[in] req The request to be printed.
874 * @param[in] mem_ctx The memory context for the result.
876 * @return Text representation of request.
879 char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx);
882 * @brief Print an tevent_req structure in debug messages.
884 * This function should be used by callers of the async API.
886 * @param[in] mem_ctx The memory context for the result.
888 * @param[in] req The request to be printed.
890 * @return Text representation of request.
892 char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req);
895 * @brief A typedef for a cancel function for a tevent request.
897 * @param[in] req The tevent request calling this function.
899 * @return True if the request could be canceled, false if not.
901 typedef bool (*tevent_req_cancel_fn)(struct tevent_req *req);
904 * @brief This function sets a cancel function for the given tevent request.
906 * This function can be used to setup a cancel function for the given request.
907 * This will be triggered if the tevent_req_cancel() function was
908 * called on the given request.
910 * @param[in] req The request to use.
912 * @param[in] fn A pointer to the cancel function.
914 void tevent_req_set_cancel_fn(struct tevent_req *req, tevent_req_cancel_fn fn);
916 #ifdef DOXYGEN
918 * @brief Try to cancel the given tevent request.
920 * This function can be used to cancel the given request.
922 * It is only possible to cancel a request when the implementation
923 * has registered a cancel function via the tevent_req_set_cancel_fn().
925 * @param[in] req The request to use.
927 * @return This function returns true is the request is cancelable,
928 * othererwise false is returned.
930 * @note Even if the function returns true, the caller need to wait
931 * for the function to complete normally.
932 * Only the _recv() function of the given request indicates
933 * if the request was really canceled.
935 bool tevent_req_cancel(struct tevent_req *req);
936 #else
937 bool _tevent_req_cancel(struct tevent_req *req, const char *location);
938 #define tevent_req_cancel(req) \
939 _tevent_req_cancel(req, __location__)
940 #endif
943 * @brief A typedef for a cleanup function for a tevent request.
945 * @param[in] req The tevent request calling this function.
947 * @param[in] req_state The current tevent_req_state.
950 typedef void (*tevent_req_cleanup_fn)(struct tevent_req *req,
951 enum tevent_req_state req_state);
954 * @brief This function sets a cleanup function for the given tevent request.
956 * This function can be used to setup a cleanup function for the given request.
957 * This will be triggered when the tevent_req_done() or tevent_req_error()
958 * function was called, before notifying the callers callback function,
959 * and also before scheduling the deferred trigger.
961 * This might be useful if more than one tevent_req belong together
962 * and need to finish both requests at the same time.
964 * The cleanup function is able to call tevent_req_done() or tevent_req_error()
965 * recursively, the cleanup function is only triggered the first time.
967 * The cleanup function is also called by tevent_req_received()
968 * (possibly triggered from tevent_req_destructor()) before destroying
969 * the private data of the tevent_req.
971 * @param[in] req The request to use.
973 * @param[in] fn A pointer to the cancel function.
975 void tevent_req_set_cleanup_fn(struct tevent_req *req, tevent_req_cleanup_fn fn);
977 #ifdef DOXYGEN
979 * @brief Create an async tevent request.
981 * The new async request will be initialized in state TEVENT_REQ_IN_PROGRESS.
983 * @code
984 * struct tevent_req *req;
985 * struct computation_state *state;
986 * req = tevent_req_create(mem_ctx, &state, struct computation_state);
987 * @endcode
989 * Tevent_req_create() allocates and zeros the state variable as a talloc
990 * child of its result. The state variable should be used as the talloc
991 * parent for all temporary variables that are allocated during the async
992 * computation. This way, when the user of the async computation frees
993 * the request, the state as a talloc child will be free'd along with
994 * all the temporary variables hanging off the state.
996 * @param[in] mem_ctx The memory context for the result.
997 * @param[in] pstate Pointer to the private request state.
998 * @param[in] type The name of the request.
1000 * @return A new async request. NULL on error.
1002 struct tevent_req *tevent_req_create(TALLOC_CTX *mem_ctx,
1003 void **pstate, #type);
1004 #else
1005 struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx,
1006 void *pstate,
1007 size_t state_size,
1008 const char *type,
1009 const char *location);
1011 #define tevent_req_create(_mem_ctx, _pstate, _type) \
1012 _tevent_req_create((_mem_ctx), (_pstate), sizeof(_type), \
1013 #_type, __location__)
1014 #endif
1017 * @brief Set a timeout for an async request.
1019 * @param[in] req The request to set the timeout for.
1021 * @param[in] ev The event context to use for the timer.
1023 * @param[in] endtime The endtime of the request.
1025 * @return True if succeeded, false if not.
1027 bool tevent_req_set_endtime(struct tevent_req *req,
1028 struct tevent_context *ev,
1029 struct timeval endtime);
1031 #ifdef DOXYGEN
1033 * @brief Call the notify callback of the given tevent request manually.
1035 * @param[in] req The tevent request to call the notify function from.
1037 * @see tevent_req_set_callback()
1039 void tevent_req_notify_callback(struct tevent_req *req);
1040 #else
1041 void _tevent_req_notify_callback(struct tevent_req *req, const char *location);
1042 #define tevent_req_notify_callback(req) \
1043 _tevent_req_notify_callback(req, __location__)
1044 #endif
1046 #ifdef DOXYGEN
1048 * @brief An async request has successfully finished.
1050 * This function is to be used by implementors of async requests. When a
1051 * request is successfully finished, this function calls the user's completion
1052 * function.
1054 * @param[in] req The finished request.
1056 void tevent_req_done(struct tevent_req *req);
1057 #else
1058 void _tevent_req_done(struct tevent_req *req,
1059 const char *location);
1060 #define tevent_req_done(req) \
1061 _tevent_req_done(req, __location__)
1062 #endif
1064 #ifdef DOXYGEN
1066 * @brief An async request has seen an error.
1068 * This function is to be used by implementors of async requests. When a
1069 * request can not successfully completed, the implementation should call this
1070 * function with the appropriate status code.
1072 * If error is 0 the function returns false and does nothing more.
1074 * @param[in] req The request with an error.
1076 * @param[in] error The error code.
1078 * @return On success true is returned, false if error is 0.
1080 * @code
1081 * int error = first_function();
1082 * if (tevent_req_error(req, error)) {
1083 * return;
1086 * error = second_function();
1087 * if (tevent_req_error(req, error)) {
1088 * return;
1091 * tevent_req_done(req);
1092 * return;
1093 * @endcode
1095 bool tevent_req_error(struct tevent_req *req,
1096 uint64_t error);
1097 #else
1098 bool _tevent_req_error(struct tevent_req *req,
1099 uint64_t error,
1100 const char *location);
1101 #define tevent_req_error(req, error) \
1102 _tevent_req_error(req, error, __location__)
1103 #endif
1105 #ifdef DOXYGEN
1107 * @brief Helper function for nomem check.
1109 * Convenience helper to easily check alloc failure within a callback
1110 * implementing the next step of an async request.
1112 * @param[in] p The pointer to be checked.
1114 * @param[in] req The request being processed.
1116 * @code
1117 * p = talloc(mem_ctx, bla);
1118 * if (tevent_req_nomem(p, req)) {
1119 * return;
1121 * @endcode
1123 bool tevent_req_nomem(const void *p,
1124 struct tevent_req *req);
1125 #else
1126 bool _tevent_req_nomem(const void *p,
1127 struct tevent_req *req,
1128 const char *location);
1129 #define tevent_req_nomem(p, req) \
1130 _tevent_req_nomem(p, req, __location__)
1131 #endif
1133 #ifdef DOXYGEN
1135 * @brief Indicate out of memory to a request
1137 * @param[in] req The request being processed.
1139 void tevent_req_oom(struct tevent_req *req);
1140 #else
1141 void _tevent_req_oom(struct tevent_req *req,
1142 const char *location);
1143 #define tevent_req_oom(req) \
1144 _tevent_req_oom(req, __location__)
1145 #endif
1148 * @brief Finish a request before the caller had the change to set the callback.
1150 * An implementation of an async request might find that it can either finish
1151 * the request without waiting for an external event, or it can not even start
1152 * the engine. To present the illusion of a callback to the user of the API,
1153 * the implementation can call this helper function which triggers an
1154 * immediate event. This way the caller can use the same calling
1155 * conventions, independent of whether the request was actually deferred.
1157 * @code
1158 * struct tevent_req *computation_send(TALLOC_CTX *mem_ctx,
1159 * struct tevent_context *ev)
1161 * struct tevent_req *req, *subreq;
1162 * struct computation_state *state;
1163 * req = tevent_req_create(mem_ctx, &state, struct computation_state);
1164 * if (req == NULL) {
1165 * return NULL;
1167 * subreq = subcomputation_send(state, ev);
1168 * if (tevent_req_nomem(subreq, req)) {
1169 * return tevent_req_post(req, ev);
1171 * tevent_req_set_callback(subreq, computation_done, req);
1172 * return req;
1174 * @endcode
1176 * @param[in] req The finished request.
1178 * @param[in] ev The tevent_context for the immediate event.
1180 * @return The given request will be returned.
1182 struct tevent_req *tevent_req_post(struct tevent_req *req,
1183 struct tevent_context *ev);
1186 * @brief Finish multiple requests within one function
1188 * Normally tevent_req_notify_callback() and all wrappers
1189 * (e.g. tevent_req_done() and tevent_req_error())
1190 * need to be the last thing an event handler should call.
1191 * This is because the callback is likely to destroy the
1192 * context of the current function.
1194 * If a function wants to notify more than one caller,
1195 * it is dangerous if it just triggers multiple callbacks
1196 * in a row. With tevent_req_defer_callback() it is possible
1197 * to set an event context that will be used to defer the callback
1198 * via an immediate event (similar to tevent_req_post()).
1200 * @code
1201 * struct complete_state {
1202 * struct tevent_context *ev;
1204 * struct tevent_req **reqs;
1205 * };
1207 * void complete(struct complete_state *state)
1209 * size_t i, c = talloc_array_length(state->reqs);
1211 * for (i=0; i < c; i++) {
1212 * tevent_req_defer_callback(state->reqs[i], state->ev);
1213 * tevent_req_done(state->reqs[i]);
1216 * @endcode
1218 * @param[in] req The finished request.
1220 * @param[in] ev The tevent_context for the immediate event.
1222 * @return The given request will be returned.
1224 void tevent_req_defer_callback(struct tevent_req *req,
1225 struct tevent_context *ev);
1228 * @brief Check if the given request is still in progress.
1230 * It is typically used by sync wrapper functions.
1232 * @param[in] req The request to poll.
1234 * @return The boolean form of "is in progress".
1236 bool tevent_req_is_in_progress(struct tevent_req *req);
1239 * @brief Actively poll for the given request to finish.
1241 * This function is typically used by sync wrapper functions.
1243 * @param[in] req The request to poll.
1245 * @param[in] ev The tevent_context to be used.
1247 * @return On success true is returned. If a critical error has
1248 * happened in the tevent loop layer false is returned.
1249 * This is not the return value of the given request!
1251 * @note This should only be used if the given tevent context was created by the
1252 * caller, to avoid event loop nesting.
1254 * @code
1255 * req = tstream_writev_queue_send(mem_ctx,
1256 * ev_ctx,
1257 * tstream,
1258 * send_queue,
1259 * iov, 2);
1260 * ok = tevent_req_poll(req, tctx->ev);
1261 * rc = tstream_writev_queue_recv(req, &sys_errno);
1262 * TALLOC_FREE(req);
1263 * @endcode
1265 bool tevent_req_poll(struct tevent_req *req,
1266 struct tevent_context *ev);
1269 * @brief Get the tevent request state and the actual error set by
1270 * tevent_req_error.
1272 * @code
1273 * int computation_recv(struct tevent_req *req, uint64_t *perr)
1275 * enum tevent_req_state state;
1276 * uint64_t err;
1277 * if (tevent_req_is_error(req, &state, &err)) {
1278 * *perr = err;
1279 * return -1;
1281 * return 0;
1283 * @endcode
1285 * @param[in] req The tevent request to get the error from.
1287 * @param[out] state A pointer to store the tevent request error state.
1289 * @param[out] error A pointer to store the error set by tevent_req_error().
1291 * @return True if the function could set error and state, false
1292 * otherwise.
1294 * @see tevent_req_error()
1296 bool tevent_req_is_error(struct tevent_req *req,
1297 enum tevent_req_state *state,
1298 uint64_t *error);
1301 * @brief Use as the last action of a _recv() function.
1303 * This function destroys the attached private data.
1305 * @param[in] req The finished request.
1307 void tevent_req_received(struct tevent_req *req);
1310 * @brief Create a tevent subrequest at a given time.
1312 * The idea is that always the same syntax for tevent requests.
1314 * @param[in] mem_ctx The talloc memory context to use.
1316 * @param[in] ev The event handle to setup the request.
1318 * @param[in] wakeup_time The time to wakeup and execute the request.
1320 * @return The new subrequest, NULL on error.
1322 * Example:
1323 * @code
1324 * static void my_callback_wakeup_done(tevent_req *subreq)
1326 * struct tevent_req *req = tevent_req_callback_data(subreq,
1327 * struct tevent_req);
1328 * bool ok;
1330 * ok = tevent_wakeup_recv(subreq);
1331 * TALLOC_FREE(subreq);
1332 * if (!ok) {
1333 * tevent_req_error(req, -1);
1334 * return;
1336 * ...
1338 * @endcode
1340 * @code
1341 * subreq = tevent_wakeup_send(mem_ctx, ev, wakeup_time);
1342 * if (tevent_req_nomem(subreq, req)) {
1343 * return false;
1345 * tevent_set_callback(subreq, my_callback_wakeup_done, req);
1346 * @endcode
1348 * @see tevent_wakeup_recv()
1350 struct tevent_req *tevent_wakeup_send(TALLOC_CTX *mem_ctx,
1351 struct tevent_context *ev,
1352 struct timeval wakeup_time);
1355 * @brief Check if the wakeup has been correctly executed.
1357 * This function needs to be called in the callback function set after calling
1358 * tevent_wakeup_send().
1360 * @param[in] req The tevent request to check.
1362 * @return True on success, false otherwise.
1364 * @see tevent_wakeup_recv()
1366 bool tevent_wakeup_recv(struct tevent_req *req);
1368 /* @} */
1371 * @defgroup tevent_helpers The tevent helper functiions
1372 * @ingroup tevent
1374 * @todo description
1376 * @{
1380 * @brief Compare two timeval values.
1382 * @param[in] tv1 The first timeval value to compare.
1384 * @param[in] tv2 The second timeval value to compare.
1386 * @return 0 if they are equal.
1387 * 1 if the first time is greater than the second.
1388 * -1 if the first time is smaller than the second.
1390 int tevent_timeval_compare(const struct timeval *tv1,
1391 const struct timeval *tv2);
1394 * @brief Get a zero timval value.
1396 * @return A zero timval value.
1398 struct timeval tevent_timeval_zero(void);
1401 * @brief Get a timeval value for the current time.
1403 * @return A timval value with the current time.
1405 struct timeval tevent_timeval_current(void);
1408 * @brief Get a timeval structure with the given values.
1410 * @param[in] secs The seconds to set.
1412 * @param[in] usecs The microseconds to set.
1414 * @return A timeval structure with the given values.
1416 struct timeval tevent_timeval_set(uint32_t secs, uint32_t usecs);
1419 * @brief Get the difference between two timeval values.
1421 * @param[in] tv1 The first timeval.
1423 * @param[in] tv2 The second timeval.
1425 * @return A timeval structure with the difference between the
1426 * first and the second value.
1428 struct timeval tevent_timeval_until(const struct timeval *tv1,
1429 const struct timeval *tv2);
1432 * @brief Check if a given timeval structure is zero.
1434 * @param[in] tv The timeval to check if it is zero.
1436 * @return True if it is zero, false otherwise.
1438 bool tevent_timeval_is_zero(const struct timeval *tv);
1441 * @brief Add the given amount of time to a timeval structure.
1443 * @param[in] tv The timeval structure to add the time.
1445 * @param[in] secs The seconds to add to the timeval.
1447 * @param[in] usecs The microseconds to add to the timeval.
1449 * @return The timeval structure with the new time.
1451 struct timeval tevent_timeval_add(const struct timeval *tv, uint32_t secs,
1452 uint32_t usecs);
1455 * @brief Get a timeval in the future with a specified offset from now.
1457 * @param[in] secs The seconds of the offset from now.
1459 * @param[in] usecs The microseconds of the offset from now.
1461 * @return A timval with the given offset in the future.
1463 struct timeval tevent_timeval_current_ofs(uint32_t secs, uint32_t usecs);
1465 /* @} */
1469 * @defgroup tevent_queue The tevent queue functions
1470 * @ingroup tevent
1472 * A tevent_queue is used to queue up async requests that must be
1473 * serialized. For example writing buffers into a socket must be
1474 * serialized. Writing a large lump of data into a socket can require
1475 * multiple write(2) or send(2) system calls. If more than one async
1476 * request is outstanding to write large buffers into a socket, every
1477 * request must individually be completed before the next one begins,
1478 * even if multiple syscalls are required.
1480 * Take a look at @ref tevent_queue_tutorial for more details.
1481 * @{
1484 struct tevent_queue;
1485 struct tevent_queue_entry;
1487 #ifdef DOXYGEN
1489 * @brief Create and start a tevent queue.
1491 * @param[in] mem_ctx The talloc memory context to allocate the queue.
1493 * @param[in] name The name to use to identify the queue.
1495 * @return An allocated tevent queue on success, NULL on error.
1497 * @see tevent_queue_start()
1498 * @see tevent_queue_stop()
1500 struct tevent_queue *tevent_queue_create(TALLOC_CTX *mem_ctx,
1501 const char *name);
1502 #else
1503 struct tevent_queue *_tevent_queue_create(TALLOC_CTX *mem_ctx,
1504 const char *name,
1505 const char *location);
1507 #define tevent_queue_create(_mem_ctx, _name) \
1508 _tevent_queue_create((_mem_ctx), (_name), __location__)
1509 #endif
1512 * @brief A callback trigger function run by the queue.
1514 * @param[in] req The tevent request the trigger function is executed on.
1516 * @param[in] private_data The private data pointer specified by
1517 * tevent_queue_add().
1519 * @see tevent_queue_add()
1520 * @see tevent_queue_add_entry()
1521 * @see tevent_queue_add_optimize_empty()
1523 typedef void (*tevent_queue_trigger_fn_t)(struct tevent_req *req,
1524 void *private_data);
1527 * @brief Add a tevent request to the queue.
1529 * @param[in] queue The queue to add the request.
1531 * @param[in] ev The event handle to use for the request.
1533 * @param[in] req The tevent request to add to the queue.
1535 * @param[in] trigger The function triggered by the queue when the request
1536 * is called. Since tevent 0.9.14 it's possible to
1537 * pass NULL, in order to just add a "blocker" to the
1538 * queue.
1540 * @param[in] private_data The private data passed to the trigger function.
1542 * @return True if the request has been successfully added, false
1543 * otherwise.
1545 bool tevent_queue_add(struct tevent_queue *queue,
1546 struct tevent_context *ev,
1547 struct tevent_req *req,
1548 tevent_queue_trigger_fn_t trigger,
1549 void *private_data);
1552 * @brief Add a tevent request to the queue.
1554 * The request can be removed from the queue by calling talloc_free()
1555 * (or a similar function) on the returned queue entry. This
1556 * is the only difference to tevent_queue_add().
1558 * @param[in] queue The queue to add the request.
1560 * @param[in] ev The event handle to use for the request.
1562 * @param[in] req The tevent request to add to the queue.
1564 * @param[in] trigger The function triggered by the queue when the request
1565 * is called. Since tevent 0.9.14 it's possible to
1566 * pass NULL, in order to just add a "blocker" to the
1567 * queue.
1569 * @param[in] private_data The private data passed to the trigger function.
1571 * @return a pointer to the tevent_queue_entry if the request
1572 * has been successfully added, NULL otherwise.
1574 * @see tevent_queue_add()
1575 * @see tevent_queue_add_optimize_empty()
1577 struct tevent_queue_entry *tevent_queue_add_entry(
1578 struct tevent_queue *queue,
1579 struct tevent_context *ev,
1580 struct tevent_req *req,
1581 tevent_queue_trigger_fn_t trigger,
1582 void *private_data);
1585 * @brief Add a tevent request to the queue using a possible optimization.
1587 * This tries to optimize for the empty queue case and may calls
1588 * the trigger function directly. This is the only difference compared
1589 * to tevent_queue_add_entry().
1591 * The caller needs to be prepared that the trigger function has
1592 * already called tevent_req_notify_callback(), tevent_req_error(),
1593 * tevent_req_done() or a similar function.
1595 * The request can be removed from the queue by calling talloc_free()
1596 * (or a similar function) on the returned queue entry.
1598 * @param[in] queue The queue to add the request.
1600 * @param[in] ev The event handle to use for the request.
1602 * @param[in] req The tevent request to add to the queue.
1604 * @param[in] trigger The function triggered by the queue when the request
1605 * is called. Since tevent 0.9.14 it's possible to
1606 * pass NULL, in order to just add a "blocker" to the
1607 * queue.
1609 * @param[in] private_data The private data passed to the trigger function.
1611 * @return a pointer to the tevent_queue_entry if the request
1612 * has been successfully added, NULL otherwise.
1614 * @see tevent_queue_add()
1615 * @see tevent_queue_add_entry()
1617 struct tevent_queue_entry *tevent_queue_add_optimize_empty(
1618 struct tevent_queue *queue,
1619 struct tevent_context *ev,
1620 struct tevent_req *req,
1621 tevent_queue_trigger_fn_t trigger,
1622 void *private_data);
1625 * @brief Start a tevent queue.
1627 * The queue is started by default.
1629 * @param[in] queue The queue to start.
1631 void tevent_queue_start(struct tevent_queue *queue);
1634 * @brief Stop a tevent queue.
1636 * The queue is started by default.
1638 * @param[in] queue The queue to stop.
1640 void tevent_queue_stop(struct tevent_queue *queue);
1643 * @brief Get the length of the queue.
1645 * @param[in] queue The queue to get the length from.
1647 * @return The number of elements.
1649 size_t tevent_queue_length(struct tevent_queue *queue);
1652 * @brief Is the tevent queue running.
1654 * The queue is started by default.
1656 * @param[in] queue The queue.
1658 * @return Wether the queue is running or not..
1660 bool tevent_queue_running(struct tevent_queue *queue);
1663 * @brief Create a tevent subrequest that waits in a tevent_queue
1665 * The idea is that always the same syntax for tevent requests.
1667 * @param[in] mem_ctx The talloc memory context to use.
1669 * @param[in] ev The event handle to setup the request.
1671 * @param[in] queue The queue to wait in.
1673 * @return The new subrequest, NULL on error.
1675 * @see tevent_queue_wait_recv()
1677 struct tevent_req *tevent_queue_wait_send(TALLOC_CTX *mem_ctx,
1678 struct tevent_context *ev,
1679 struct tevent_queue *queue);
1682 * @brief Check if we no longer need to wait in the queue.
1684 * This function needs to be called in the callback function set after calling
1685 * tevent_queue_wait_send().
1687 * @param[in] req The tevent request to check.
1689 * @return True on success, false otherwise.
1691 * @see tevent_queue_wait_send()
1693 bool tevent_queue_wait_recv(struct tevent_req *req);
1695 typedef int (*tevent_nesting_hook)(struct tevent_context *ev,
1696 void *private_data,
1697 uint32_t level,
1698 bool begin,
1699 void *stack_ptr,
1700 const char *location);
1701 #ifdef TEVENT_DEPRECATED
1702 #ifndef _DEPRECATED_
1703 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
1704 #define _DEPRECATED_ __attribute__ ((deprecated))
1705 #else
1706 #define _DEPRECATED_
1707 #endif
1708 #endif
1709 void tevent_loop_allow_nesting(struct tevent_context *ev) _DEPRECATED_;
1710 void tevent_loop_set_nesting_hook(struct tevent_context *ev,
1711 tevent_nesting_hook hook,
1712 void *private_data) _DEPRECATED_;
1713 int _tevent_loop_until(struct tevent_context *ev,
1714 bool (*finished)(void *private_data),
1715 void *private_data,
1716 const char *location) _DEPRECATED_;
1717 #define tevent_loop_until(ev, finished, private_data) \
1718 _tevent_loop_until(ev, finished, private_data, __location__)
1719 #endif
1721 int tevent_re_initialise(struct tevent_context *ev);
1723 /* @} */
1726 * @defgroup tevent_ops The tevent operation functions
1727 * @ingroup tevent
1729 * The following structure and registration functions are exclusively
1730 * needed for people writing and pluggin a different event engine.
1731 * There is nothing useful for normal tevent user in here.
1732 * @{
1735 struct tevent_ops {
1736 /* context init */
1737 int (*context_init)(struct tevent_context *ev);
1739 /* fd_event functions */
1740 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
1741 TALLOC_CTX *mem_ctx,
1742 int fd, uint16_t flags,
1743 tevent_fd_handler_t handler,
1744 void *private_data,
1745 const char *handler_name,
1746 const char *location);
1747 void (*set_fd_close_fn)(struct tevent_fd *fde,
1748 tevent_fd_close_fn_t close_fn);
1749 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
1750 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
1752 /* timed_event functions */
1753 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
1754 TALLOC_CTX *mem_ctx,
1755 struct timeval next_event,
1756 tevent_timer_handler_t handler,
1757 void *private_data,
1758 const char *handler_name,
1759 const char *location);
1761 /* immediate event functions */
1762 void (*schedule_immediate)(struct tevent_immediate *im,
1763 struct tevent_context *ev,
1764 tevent_immediate_handler_t handler,
1765 void *private_data,
1766 const char *handler_name,
1767 const char *location);
1769 /* signal functions */
1770 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
1771 TALLOC_CTX *mem_ctx,
1772 int signum, int sa_flags,
1773 tevent_signal_handler_t handler,
1774 void *private_data,
1775 const char *handler_name,
1776 const char *location);
1778 /* loop functions */
1779 int (*loop_once)(struct tevent_context *ev, const char *location);
1780 int (*loop_wait)(struct tevent_context *ev, const char *location);
1783 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
1785 /* @} */
1788 * @defgroup tevent_compat The tevent compatibility functions
1789 * @ingroup tevent
1791 * The following definitions are usueful only for compatibility with the
1792 * implementation originally developed within the samba4 code and will be
1793 * soon removed. Please NEVER use in new code.
1795 * @todo Ignore it?
1797 * @{
1800 #ifdef TEVENT_COMPAT_DEFINES
1802 #define event_context tevent_context
1803 #define event_ops tevent_ops
1804 #define fd_event tevent_fd
1805 #define timed_event tevent_timer
1806 #define signal_event tevent_signal
1808 #define event_fd_handler_t tevent_fd_handler_t
1809 #define event_timed_handler_t tevent_timer_handler_t
1810 #define event_signal_handler_t tevent_signal_handler_t
1812 #define event_context_init(mem_ctx) \
1813 tevent_context_init(mem_ctx)
1815 #define event_context_init_byname(mem_ctx, name) \
1816 tevent_context_init_byname(mem_ctx, name)
1818 #define event_backend_list(mem_ctx) \
1819 tevent_backend_list(mem_ctx)
1821 #define event_set_default_backend(backend) \
1822 tevent_set_default_backend(backend)
1824 #define event_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \
1825 tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data)
1827 #define event_add_timed(ev, mem_ctx, next_event, handler, private_data) \
1828 tevent_add_timer(ev, mem_ctx, next_event, handler, private_data)
1830 #define event_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \
1831 tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data)
1833 #define event_loop_once(ev) \
1834 tevent_loop_once(ev)
1836 #define event_loop_wait(ev) \
1837 tevent_loop_wait(ev)
1839 #define event_get_fd_flags(fde) \
1840 tevent_fd_get_flags(fde)
1842 #define event_set_fd_flags(fde, flags) \
1843 tevent_fd_set_flags(fde, flags)
1845 #define EVENT_FD_READ TEVENT_FD_READ
1846 #define EVENT_FD_WRITE TEVENT_FD_WRITE
1848 #define EVENT_FD_WRITEABLE(fde) \
1849 TEVENT_FD_WRITEABLE(fde)
1851 #define EVENT_FD_READABLE(fde) \
1852 TEVENT_FD_READABLE(fde)
1854 #define EVENT_FD_NOT_WRITEABLE(fde) \
1855 TEVENT_FD_NOT_WRITEABLE(fde)
1857 #define EVENT_FD_NOT_READABLE(fde) \
1858 TEVENT_FD_NOT_READABLE(fde)
1860 #define ev_debug_level tevent_debug_level
1862 #define EV_DEBUG_FATAL TEVENT_DEBUG_FATAL
1863 #define EV_DEBUG_ERROR TEVENT_DEBUG_ERROR
1864 #define EV_DEBUG_WARNING TEVENT_DEBUG_WARNING
1865 #define EV_DEBUG_TRACE TEVENT_DEBUG_TRACE
1867 #define ev_set_debug(ev, debug, context) \
1868 tevent_set_debug(ev, debug, context)
1870 #define ev_set_debug_stderr(_ev) tevent_set_debug_stderr(ev)
1872 #endif /* TEVENT_COMPAT_DEFINES */
1874 /* @} */
1876 #endif /* __TEVENT_H__ */