s3:smbd react on message that client should be disconnected
[Samba.git] / ctdb / lib / tevent / tevent.h
blob6b4d371e4c5dae31307eaa2b6ea973cd7c148036
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 struct tevent_fd *tevent_add_fd(struct tevent_context *ev,
181 TALLOC_CTX *mem_ctx,
182 int fd,
183 uint16_t flags,
184 tevent_fd_handler_t handler,
185 void *private_data);
186 #else
187 struct tevent_fd *_tevent_add_fd(struct tevent_context *ev,
188 TALLOC_CTX *mem_ctx,
189 int fd,
190 uint16_t flags,
191 tevent_fd_handler_t handler,
192 void *private_data,
193 const char *handler_name,
194 const char *location);
195 #define tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \
196 _tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data, \
197 #handler, __location__)
198 #endif
200 #ifdef DOXYGEN
202 * @brief Add a timed event
204 * @param[in] ev The event context to work on.
206 * @param[in] mem_ctx The talloc memory context to use.
208 * @param[in] next_event Timeval specifying the absolute time to fire this
209 * event. This is not an offset.
211 * @param[in] handler The callback handler for the event.
213 * @param[in] private_data The private data passed to the callback handler.
215 * @return The newly-created timer event, or NULL on error.
217 * @note To cancel a timer event before it fires, call talloc_free() on the
218 * event returned from this function. This event is automatically
219 * talloc_free()-ed after its event handler files, if it hasn't been freed yet.
221 * @note Unlike some mainloops, tevent timers are one-time events. To set up
222 * a recurring event, it is necessary to call tevent_add_timer() again during
223 * the handler processing.
225 * @note Due to the internal mainloop processing, a timer set to run
226 * immediately will do so after any other pending timers fire, but before
227 * any further file descriptor or signal handling events fire. Callers should
228 * not rely on this behavior!
230 struct tevent_timer *tevent_add_timer(struct tevent_context *ev,
231 TALLOC_CTX *mem_ctx,
232 struct timeval next_event,
233 tevent_timer_handler_t handler,
234 void *private_data);
235 #else
236 struct tevent_timer *_tevent_add_timer(struct tevent_context *ev,
237 TALLOC_CTX *mem_ctx,
238 struct timeval next_event,
239 tevent_timer_handler_t handler,
240 void *private_data,
241 const char *handler_name,
242 const char *location);
243 #define tevent_add_timer(ev, mem_ctx, next_event, handler, private_data) \
244 _tevent_add_timer(ev, mem_ctx, next_event, handler, private_data, \
245 #handler, __location__)
246 #endif
248 #ifdef DOXYGEN
250 * Initialize an immediate event object
252 * This object can be used to trigger an event to occur immediately after
253 * returning from the current event (before any other event occurs)
255 * @param[in] mem_ctx The talloc memory context to use as the parent
257 * @return An empty tevent_immediate object. Use tevent_schedule_immediate
258 * to populate and use it.
260 * @note Available as of tevent 0.9.8
262 struct tevent_immediate *tevent_create_immediate(TALLOC_CTX *mem_ctx);
263 #else
264 struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx,
265 const char *location);
266 #define tevent_create_immediate(mem_ctx) \
267 _tevent_create_immediate(mem_ctx, __location__)
268 #endif
270 #ifdef DOXYGEN
273 * Schedule an event for immediate execution. This event will occur
274 * immediately after returning from the current event (before any other
275 * event occurs)
277 * @param[in] im The tevent_immediate object to populate and use
278 * @param[in] ctx The tevent_context to run this event
279 * @param[in] handler The event handler to run when this event fires
280 * @param[in] private_data Data to pass to the event handler
282 void tevent_schedule_immediate(struct tevent_immediate *im,
283 struct tevent_context *ctx,
284 tevent_immediate_handler_t handler,
285 void *private_data);
286 #else
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 const char *handler_name,
292 const char *location);
293 #define tevent_schedule_immediate(im, ctx, handler, private_data) \
294 _tevent_schedule_immediate(im, ctx, handler, private_data, \
295 #handler, __location__);
296 #endif
298 #ifdef DOXYGEN
300 * @brief Add a tevent signal handler
302 * tevent_add_signal() creates a new event for handling a signal the next
303 * time through the mainloop. It implements a very simple traditional signal
304 * handler whose only purpose is to add the handler event into the mainloop.
306 * @param[in] ev The event context to work on.
308 * @param[in] mem_ctx The talloc memory context to use.
310 * @param[in] signum The signal to trap
312 * @param[in] handler The callback handler for the signal.
314 * @param[in] sa_flags sigaction flags for this signal handler.
316 * @param[in] private_data The private data passed to the callback handler.
318 * @return The newly-created signal handler event, or NULL on error.
320 * @note To cancel a signal handler, call talloc_free() on the event returned
321 * from this function.
323 struct tevent_signal *tevent_add_signal(struct tevent_context *ev,
324 TALLOC_CTX *mem_ctx,
325 int signum,
326 int sa_flags,
327 tevent_signal_handler_t handler,
328 void *private_data);
329 #else
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 const char *handler_name,
337 const char *location);
338 #define tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \
339 _tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data, \
340 #handler, __location__)
341 #endif
343 #ifdef DOXYGEN
345 * @brief Pass a single time through the mainloop
347 * This will process any appropriate signal, immediate, fd and timer events
349 * @param[in] ev The event context to process
351 * @return Zero on success, nonzero if an internal error occurred
353 int tevent_loop_once(struct tevent_context *ev);
354 #else
355 int _tevent_loop_once(struct tevent_context *ev, const char *location);
356 #define tevent_loop_once(ev) \
357 _tevent_loop_once(ev, __location__)
358 #endif
360 #ifdef DOXYGEN
362 * @brief Run the mainloop
364 * The mainloop will run until there are no events remaining to be processed
366 * @param[in] ev The event context to process
368 * @return Zero if all events have been processed. Nonzero if an internal
369 * error occurred.
371 int tevent_loop_wait(struct tevent_context *ev);
372 #else
373 int _tevent_loop_wait(struct tevent_context *ev, const char *location);
374 #define tevent_loop_wait(ev) \
375 _tevent_loop_wait(ev, __location__)
376 #endif
380 * Assign a function to run when a tevent_fd is freed
382 * This function is a destructor for the tevent_fd. It does not automatically
383 * close the file descriptor. If this is the desired behavior, then it must be
384 * performed by the close_fn.
386 * @param[in] fde File descriptor event on which to set the destructor
387 * @param[in] close_fn Destructor to execute when fde is freed
389 void tevent_fd_set_close_fn(struct tevent_fd *fde,
390 tevent_fd_close_fn_t close_fn);
393 * Automatically close the file descriptor when the tevent_fd is freed
395 * This function calls close(fd) internally.
397 * @param[in] fde File descriptor event to auto-close
399 void tevent_fd_set_auto_close(struct tevent_fd *fde);
402 * Return the flags set on this file descriptor event
404 * @param[in] fde File descriptor event to query
406 * @return The flags set on the event. See #TEVENT_FD_READ and
407 * #TEVENT_FD_WRITE
409 uint16_t tevent_fd_get_flags(struct tevent_fd *fde);
412 * Set flags on a file descriptor event
414 * @param[in] fde File descriptor event to set
415 * @param[in] flags Flags to set on the event. See #TEVENT_FD_READ and
416 * #TEVENT_FD_WRITE
418 void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
421 * Query whether tevent supports signal handling
423 * @param[in] ev An initialized tevent context
425 * @return True if this platform and tevent context support signal handling
427 bool tevent_signal_support(struct tevent_context *ev);
429 void tevent_set_abort_fn(void (*abort_fn)(const char *reason));
431 /* bits for file descriptor event flags */
434 * Monitor a file descriptor for write availability
436 #define TEVENT_FD_READ 1
438 * Monitor a file descriptor for data to be read
440 #define TEVENT_FD_WRITE 2
443 * Convenience function for declaring a tevent_fd writable
445 #define TEVENT_FD_WRITEABLE(fde) \
446 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) | TEVENT_FD_WRITE)
449 * Convenience function for declaring a tevent_fd readable
451 #define TEVENT_FD_READABLE(fde) \
452 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) | TEVENT_FD_READ)
455 * Convenience function for declaring a tevent_fd non-writable
457 #define TEVENT_FD_NOT_WRITEABLE(fde) \
458 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_WRITE)
461 * Convenience function for declaring a tevent_fd non-readable
463 #define TEVENT_FD_NOT_READABLE(fde) \
464 tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_READ)
467 * Debug level of tevent
469 enum tevent_debug_level {
470 TEVENT_DEBUG_FATAL,
471 TEVENT_DEBUG_ERROR,
472 TEVENT_DEBUG_WARNING,
473 TEVENT_DEBUG_TRACE
477 * @brief The tevent debug callbac.
479 * @param[in] context The memory context to use.
481 * @param[in] level The debug level.
483 * @param[in] fmt The format string.
485 * @param[in] ap The arguments for the format string.
487 typedef void (*tevent_debug_fn)(void *context,
488 enum tevent_debug_level level,
489 const char *fmt,
490 va_list ap) PRINTF_ATTRIBUTE(3,0);
493 * Set destination for tevent debug messages
495 * @param[in] ev Event context to debug
496 * @param[in] debug Function to handle output printing
497 * @param[in] context The context to pass to the debug function.
499 * @return Always returns 0 as of version 0.9.8
501 * @note Default is to emit no debug messages
503 int tevent_set_debug(struct tevent_context *ev,
504 tevent_debug_fn debug,
505 void *context);
508 * Designate stderr for debug message output
510 * @param[in] ev Event context to debug
512 * @note This function will only output TEVENT_DEBUG_FATAL, TEVENT_DEBUG_ERROR
513 * and TEVENT_DEBUG_WARNING messages. For TEVENT_DEBUG_TRACE, please define a
514 * function for tevent_set_debug()
516 int tevent_set_debug_stderr(struct tevent_context *ev);
518 enum tevent_trace_point {
520 * Corresponds to a trace point just before waiting
522 TEVENT_TRACE_BEFORE_WAIT,
524 * Corresponds to a trace point just after waiting
526 TEVENT_TRACE_AFTER_WAIT,
527 #define TEVENT_HAS_LOOP_ONCE_TRACE_POINTS 1
529 * Corresponds to a trace point just before calling
530 * the loop_once() backend function.
532 TEVENT_TRACE_BEFORE_LOOP_ONCE,
534 * Corresponds to a trace point right after the
535 * loop_once() backend function has returned.
537 TEVENT_TRACE_AFTER_LOOP_ONCE,
540 typedef void (*tevent_trace_callback_t)(enum tevent_trace_point,
541 void *private_data);
544 * Register a callback to be called at certain trace points
546 * @param[in] ev Event context
547 * @param[in] cb Trace callback
548 * @param[in] private_data Data to be passed to callback
550 * @note The callback will be called at trace points defined by
551 * tevent_trace_point. Call with NULL to reset.
553 void tevent_set_trace_callback(struct tevent_context *ev,
554 tevent_trace_callback_t cb,
555 void *private_data);
558 * Retrieve the current trace callback
560 * @param[in] ev Event context
561 * @param[out] cb Registered trace callback
562 * @param[out] private_data Registered data to be passed to callback
564 * @note This can be used to allow one component that wants to
565 * register a callback to respect the callback that another component
566 * has already registered.
568 void tevent_get_trace_callback(struct tevent_context *ev,
569 tevent_trace_callback_t *cb,
570 void *private_data);
573 * @}
577 * @defgroup tevent_request The tevent request functions.
578 * @ingroup tevent
580 * A tevent_req represents an asynchronous computation.
582 * The tevent_req group of API calls is the recommended way of
583 * programming async computations within tevent. In particular the
584 * file descriptor (tevent_add_fd) and timer (tevent_add_timed) events
585 * are considered too low-level to be used in larger computations. To
586 * read and write from and to sockets, Samba provides two calls on top
587 * of tevent_add_fd: read_packet_send/recv and writev_send/recv. These
588 * requests are much easier to compose than the low-level event
589 * handlers called from tevent_add_fd.
591 * A lot of the simplicity tevent_req has brought to the notoriously
592 * hairy async programming came via a set of conventions that every
593 * async computation programmed should follow. One central piece of
594 * these conventions is the naming of routines and variables.
596 * Every async computation needs a name (sensibly called "computation"
597 * down from here). From this name quite a few naming conventions are
598 * derived.
600 * Every computation that requires local state needs a
601 * @code
602 * struct computation_state {
603 * int local_var;
604 * };
605 * @endcode
606 * Even if no local variables are required, such a state struct should
607 * be created containing a dummy variable. Quite a few helper
608 * functions and macros (for example tevent_req_create()) assume such
609 * a state struct.
611 * An async computation is started by a computation_send
612 * function. When it is finished, its result can be received by a
613 * computation_recv function. For an example how to set up an async
614 * computation, see the code example in the documentation for
615 * tevent_req_create() and tevent_req_post(). The prototypes for _send
616 * and _recv functions should follow some conventions:
618 * @code
619 * struct tevent_req *computation_send(TALLOC_CTX *mem_ctx,
620 * struct tevent_req *ev,
621 * ... further args);
622 * int computation_recv(struct tevent_req *req, ... further output args);
623 * @endcode
625 * The "int" result of computation_recv() depends on the result the
626 * sync version of the function would have, "int" is just an example
627 * here.
629 * Another important piece of the conventions is that the program flow
630 * is interrupted as little as possible. Because a blocking
631 * sub-computation requires that the flow needs to continue in a
632 * separate function that is the logical sequel of some computation,
633 * it should lexically follow sending off the blocking
634 * sub-computation. Setting the callback function via
635 * tevent_req_set_callback() requires referencing a function lexically
636 * below the call to tevent_req_set_callback(), forward declarations
637 * are required. A lot of the async computations thus begin with a
638 * sequence of declarations such as
640 * @code
641 * static void computation_step1_done(struct tevent_req *subreq);
642 * static void computation_step2_done(struct tevent_req *subreq);
643 * static void computation_step3_done(struct tevent_req *subreq);
644 * @endcode
646 * It really helps readability a lot to do these forward declarations,
647 * because the lexically sequential program flow makes the async
648 * computations almost as clear to read as a normal, sync program
649 * flow.
651 * It is up to the user of the async computation to talloc_free it
652 * after it has finished. If an async computation should be aborted,
653 * the tevent_req structure can be talloc_free'ed. After it has
654 * finished, it should talloc_free'ed by the API user.
656 * @{
660 * An async request moves from TEVENT_REQ_INIT to
661 * TEVENT_REQ_IN_PROGRESS. All other states are valid after a request
662 * has finished.
664 enum tevent_req_state {
666 * We are creating the request
668 TEVENT_REQ_INIT,
670 * We are waiting the request to complete
672 TEVENT_REQ_IN_PROGRESS,
674 * The request is finished successfully
676 TEVENT_REQ_DONE,
678 * A user error has occurred. The user error has been
679 * indicated by tevent_req_error(), it can be retrieved via
680 * tevent_req_is_error().
682 TEVENT_REQ_USER_ERROR,
684 * Request timed out after the timeout set by tevent_req_set_endtime.
686 TEVENT_REQ_TIMED_OUT,
688 * An internal allocation has failed, or tevent_req_nomem has
689 * been given a NULL pointer as the first argument.
691 TEVENT_REQ_NO_MEMORY,
693 * The request has been received by the caller. No further
694 * action is valid.
696 TEVENT_REQ_RECEIVED
700 * @brief An async request
702 struct tevent_req;
705 * @brief A tevent request callback function.
707 * @param[in] req The tevent async request which executed this callback.
709 typedef void (*tevent_req_fn)(struct tevent_req *req);
712 * @brief Set an async request callback.
714 * See the documentation of tevent_req_post() for an example how this
715 * is supposed to be used.
717 * @param[in] req The async request to set the callback.
719 * @param[in] fn The callback function to set.
721 * @param[in] pvt A pointer to private data to pass to the async request
722 * callback.
724 void tevent_req_set_callback(struct tevent_req *req, tevent_req_fn fn, void *pvt);
726 #ifdef DOXYGEN
728 * @brief Get the private data cast to the given type for a callback from
729 * a tevent request structure.
731 * @code
732 * static void computation_done(struct tevent_req *subreq) {
733 * struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
734 * struct computation_state *state = tevent_req_data(req, struct computation_state);
735 * .... more things, eventually maybe call tevent_req_done(req);
737 * @endcode
739 * @param[in] req The structure to get the callback data from.
741 * @param[in] type The type of the private callback data to get.
743 * @return The type casted private data set NULL if not set.
745 void *tevent_req_callback_data(struct tevent_req *req, #type);
746 #else
747 void *_tevent_req_callback_data(struct tevent_req *req);
748 #define tevent_req_callback_data(_req, _type) \
749 talloc_get_type_abort(_tevent_req_callback_data(_req), _type)
750 #endif
752 #ifdef DOXYGEN
754 * @brief Get the private data for a callback from a tevent request structure.
756 * @param[in] req The structure to get the callback data from.
758 * @param[in] req The structure to get the data from.
760 * @return The private data or NULL if not set.
762 void *tevent_req_callback_data_void(struct tevent_req *req);
763 #else
764 #define tevent_req_callback_data_void(_req) \
765 _tevent_req_callback_data(_req)
766 #endif
768 #ifdef DOXYGEN
770 * @brief Get the private data from a tevent request structure.
772 * When the tevent_req has been created by tevent_req_create, the
773 * result of tevent_req_data() is the state variable created by
774 * tevent_req_create() as a child of the req.
776 * @param[in] req The structure to get the private data from.
778 * @param[in] type The type of the private data
780 * @return The private data or NULL if not set.
782 void *tevent_req_data(struct tevent_req *req, #type);
783 #else
784 void *_tevent_req_data(struct tevent_req *req);
785 #define tevent_req_data(_req, _type) \
786 talloc_get_type_abort(_tevent_req_data(_req), _type)
787 #endif
790 * @brief The print function which can be set for a tevent async request.
792 * @param[in] req The tevent async request.
794 * @param[in] ctx A talloc memory context which can be uses to allocate
795 * memory.
797 * @return An allocated string buffer to print.
799 * Example:
800 * @code
801 * static char *my_print(struct tevent_req *req, TALLOC_CTX *mem_ctx)
803 * struct my_data *data = tevent_req_data(req, struct my_data);
804 * char *result;
806 * result = tevent_req_default_print(mem_ctx, req);
807 * if (result == NULL) {
808 * return NULL;
811 * return talloc_asprintf_append_buffer(result, "foo=%d, bar=%d",
812 * data->foo, data->bar);
814 * @endcode
816 typedef char *(*tevent_req_print_fn)(struct tevent_req *req, TALLOC_CTX *ctx);
819 * @brief This function sets a print function for the given request.
821 * This function can be used to setup a print function for the given request.
822 * This will be triggered if the tevent_req_print() function was
823 * called on the given request.
825 * @param[in] req The request to use.
827 * @param[in] fn A pointer to the print function
829 * @note This function should only be used for debugging.
831 void tevent_req_set_print_fn(struct tevent_req *req, tevent_req_print_fn fn);
834 * @brief The default print function for creating debug messages.
836 * The function should not be used by users of the async API,
837 * but custom print function can use it and append custom text
838 * to the string.
840 * @param[in] req The request to be printed.
842 * @param[in] mem_ctx The memory context for the result.
844 * @return Text representation of request.
847 char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx);
850 * @brief Print an tevent_req structure in debug messages.
852 * This function should be used by callers of the async API.
854 * @param[in] mem_ctx The memory context for the result.
856 * @param[in] req The request to be printed.
858 * @return Text representation of request.
860 char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req);
863 * @brief A typedef for a cancel function for a tevent request.
865 * @param[in] req The tevent request calling this function.
867 * @return True if the request could be canceled, false if not.
869 typedef bool (*tevent_req_cancel_fn)(struct tevent_req *req);
872 * @brief This function sets a cancel function for the given tevent request.
874 * This function can be used to setup a cancel function for the given request.
875 * This will be triggered if the tevent_req_cancel() function was
876 * called on the given request.
878 * @param[in] req The request to use.
880 * @param[in] fn A pointer to the cancel function.
882 void tevent_req_set_cancel_fn(struct tevent_req *req, tevent_req_cancel_fn fn);
884 #ifdef DOXYGEN
886 * @brief Try to cancel the given tevent request.
888 * This function can be used to cancel the given request.
890 * It is only possible to cancel a request when the implementation
891 * has registered a cancel function via the tevent_req_set_cancel_fn().
893 * @param[in] req The request to use.
895 * @return This function returns true is the request is cancelable,
896 * othererwise false is returned.
898 * @note Even if the function returns true, the caller need to wait
899 * for the function to complete normally.
900 * Only the _recv() function of the given request indicates
901 * if the request was really canceled.
903 bool tevent_req_cancel(struct tevent_req *req);
904 #else
905 bool _tevent_req_cancel(struct tevent_req *req, const char *location);
906 #define tevent_req_cancel(req) \
907 _tevent_req_cancel(req, __location__)
908 #endif
910 #ifdef DOXYGEN
912 * @brief Create an async tevent request.
914 * The new async request will be initialized in state TEVENT_REQ_IN_PROGRESS.
916 * @code
917 * struct tevent_req *req;
918 * struct computation_state *state;
919 * req = tevent_req_create(mem_ctx, &state, struct computation_state);
920 * @endcode
922 * Tevent_req_create() creates the state variable as a talloc child of
923 * its result. The state variable should be used as the talloc parent
924 * for all temporary variables that are allocated during the async
925 * computation. This way, when the user of the async computation frees
926 * the request, the state as a talloc child will be free'd along with
927 * all the temporary variables hanging off the state.
929 * @param[in] mem_ctx The memory context for the result.
930 * @param[in] pstate Pointer to the private request state.
931 * @param[in] type The name of the request.
933 * @return A new async request. NULL on error.
935 struct tevent_req *tevent_req_create(TALLOC_CTX *mem_ctx,
936 void **pstate, #type);
937 #else
938 struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx,
939 void *pstate,
940 size_t state_size,
941 const char *type,
942 const char *location);
944 #define tevent_req_create(_mem_ctx, _pstate, _type) \
945 _tevent_req_create((_mem_ctx), (_pstate), sizeof(_type), \
946 #_type, __location__)
947 #endif
950 * @brief Set a timeout for an async request.
952 * @param[in] req The request to set the timeout for.
954 * @param[in] ev The event context to use for the timer.
956 * @param[in] endtime The endtime of the request.
958 * @return True if succeeded, false if not.
960 bool tevent_req_set_endtime(struct tevent_req *req,
961 struct tevent_context *ev,
962 struct timeval endtime);
964 #ifdef DOXYGEN
966 * @brief Call the notify callback of the given tevent request manually.
968 * @param[in] req The tevent request to call the notify function from.
970 * @see tevent_req_set_callback()
972 void tevent_req_notify_callback(struct tevent_req *req);
973 #else
974 void _tevent_req_notify_callback(struct tevent_req *req, const char *location);
975 #define tevent_req_notify_callback(req) \
976 _tevent_req_notify_callback(req, __location__)
977 #endif
979 #ifdef DOXYGEN
981 * @brief An async request has successfully finished.
983 * This function is to be used by implementors of async requests. When a
984 * request is successfully finished, this function calls the user's completion
985 * function.
987 * @param[in] req The finished request.
989 void tevent_req_done(struct tevent_req *req);
990 #else
991 void _tevent_req_done(struct tevent_req *req,
992 const char *location);
993 #define tevent_req_done(req) \
994 _tevent_req_done(req, __location__)
995 #endif
997 #ifdef DOXYGEN
999 * @brief An async request has seen an error.
1001 * This function is to be used by implementors of async requests. When a
1002 * request can not successfully completed, the implementation should call this
1003 * function with the appropriate status code.
1005 * If error is 0 the function returns false and does nothing more.
1007 * @param[in] req The request with an error.
1009 * @param[in] error The error code.
1011 * @return On success true is returned, false if error is 0.
1013 * @code
1014 * int error = first_function();
1015 * if (tevent_req_error(req, error)) {
1016 * return;
1019 * error = second_function();
1020 * if (tevent_req_error(req, error)) {
1021 * return;
1024 * tevent_req_done(req);
1025 * return;
1026 * @endcode
1028 bool tevent_req_error(struct tevent_req *req,
1029 uint64_t error);
1030 #else
1031 bool _tevent_req_error(struct tevent_req *req,
1032 uint64_t error,
1033 const char *location);
1034 #define tevent_req_error(req, error) \
1035 _tevent_req_error(req, error, __location__)
1036 #endif
1038 #ifdef DOXYGEN
1040 * @brief Helper function for nomem check.
1042 * Convenience helper to easily check alloc failure within a callback
1043 * implementing the next step of an async request.
1045 * @param[in] p The pointer to be checked.
1047 * @param[in] req The request being processed.
1049 * @code
1050 * p = talloc(mem_ctx, bla);
1051 * if (tevent_req_nomem(p, req)) {
1052 * return;
1054 * @endcode
1056 bool tevent_req_nomem(const void *p,
1057 struct tevent_req *req);
1058 #else
1059 bool _tevent_req_nomem(const void *p,
1060 struct tevent_req *req,
1061 const char *location);
1062 #define tevent_req_nomem(p, req) \
1063 _tevent_req_nomem(p, req, __location__)
1064 #endif
1066 #ifdef DOXYGEN
1068 * @brief Indicate out of memory to a request
1070 * @param[in] req The request being processed.
1072 void tevent_req_oom(struct tevent_req *req);
1073 #else
1074 void _tevent_req_oom(struct tevent_req *req,
1075 const char *location);
1076 #define tevent_req_oom(req) \
1077 _tevent_req_oom(req, __location__)
1078 #endif
1081 * @brief Finish a request before the caller had the change to set the callback.
1083 * An implementation of an async request might find that it can either finish
1084 * the request without waiting for an external event, or it can not even start
1085 * the engine. To present the illusion of a callback to the user of the API,
1086 * the implementation can call this helper function which triggers an
1087 * immediate event. This way the caller can use the same calling
1088 * conventions, independent of whether the request was actually deferred.
1090 * @code
1091 * struct tevent_req *computation_send(TALLOC_CTX *mem_ctx,
1092 * struct tevent_context *ev)
1094 * struct tevent_req *req, *subreq;
1095 * struct computation_state *state;
1096 * req = tevent_req_create(mem_ctx, &state, struct computation_state);
1097 * if (req == NULL) {
1098 * return NULL;
1100 * subreq = subcomputation_send(state, ev);
1101 * if (tevent_req_nomem(subreq, req)) {
1102 * return tevent_req_post(req, ev);
1104 * tevent_req_set_callback(subreq, computation_done, req);
1105 * return req;
1107 * @endcode
1109 * @param[in] req The finished request.
1111 * @param[in] ev The tevent_context for the immediate event.
1113 * @return The given request will be returned.
1115 struct tevent_req *tevent_req_post(struct tevent_req *req,
1116 struct tevent_context *ev);
1119 * @brief Finish multiple requests within one function
1121 * Normally tevent_req_notify_callback() and all wrappers
1122 * (e.g. tevent_req_done() and tevent_req_error())
1123 * need to be the last thing an event handler should call.
1124 * This is because the callback is likely to destroy the
1125 * context of the current function.
1127 * If a function wants to notify more than one caller,
1128 * it is dangerous if it just triggers multiple callbacks
1129 * in a row. With tevent_req_defer_callback() it is possible
1130 * to set an event context that will be used to defer the callback
1131 * via an immediate event (similar to tevent_req_post()).
1133 * @code
1134 * struct complete_state {
1135 * struct tevent_context *ev;
1137 * struct tevent_req **reqs;
1138 * };
1140 * void complete(struct complete_state *state)
1142 * size_t i, c = talloc_array_length(state->reqs);
1144 * for (i=0; i < c; i++) {
1145 * tevent_req_defer_callback(state->reqs[i], state->ev);
1146 * tevent_req_done(state->reqs[i]);
1149 * @endcode
1151 * @param[in] req The finished request.
1153 * @param[in] ev The tevent_context for the immediate event.
1155 * @return The given request will be returned.
1157 void tevent_req_defer_callback(struct tevent_req *req,
1158 struct tevent_context *ev);
1161 * @brief Check if the given request is still in progress.
1163 * It is typically used by sync wrapper functions.
1165 * @param[in] req The request to poll.
1167 * @return The boolean form of "is in progress".
1169 bool tevent_req_is_in_progress(struct tevent_req *req);
1172 * @brief Actively poll for the given request to finish.
1174 * This function is typically used by sync wrapper functions.
1176 * @param[in] req The request to poll.
1178 * @param[in] ev The tevent_context to be used.
1180 * @return On success true is returned. If a critical error has
1181 * happened in the tevent loop layer false is returned.
1182 * This is not the return value of the given request!
1184 * @note This should only be used if the given tevent context was created by the
1185 * caller, to avoid event loop nesting.
1187 * @code
1188 * req = tstream_writev_queue_send(mem_ctx,
1189 * ev_ctx,
1190 * tstream,
1191 * send_queue,
1192 * iov, 2);
1193 * ok = tevent_req_poll(req, tctx->ev);
1194 * rc = tstream_writev_queue_recv(req, &sys_errno);
1195 * TALLOC_FREE(req);
1196 * @endcode
1198 bool tevent_req_poll(struct tevent_req *req,
1199 struct tevent_context *ev);
1202 * @brief Get the tevent request state and the actual error set by
1203 * tevent_req_error.
1205 * @code
1206 * int computation_recv(struct tevent_req *req, uint64_t *perr)
1208 * enum tevent_req_state state;
1209 * uint64_t err;
1210 * if (tevent_req_is_error(req, &state, &err)) {
1211 * *perr = err;
1212 * return -1;
1214 * return 0;
1216 * @endcode
1218 * @param[in] req The tevent request to get the error from.
1220 * @param[out] state A pointer to store the tevent request error state.
1222 * @param[out] error A pointer to store the error set by tevent_req_error().
1224 * @return True if the function could set error and state, false
1225 * otherwise.
1227 * @see tevent_req_error()
1229 bool tevent_req_is_error(struct tevent_req *req,
1230 enum tevent_req_state *state,
1231 uint64_t *error);
1234 * @brief Use as the last action of a _recv() function.
1236 * This function destroys the attached private data.
1238 * @param[in] req The finished request.
1240 void tevent_req_received(struct tevent_req *req);
1243 * @brief Create a tevent subrequest at a given time.
1245 * The idea is that always the same syntax for tevent requests.
1247 * @param[in] mem_ctx The talloc memory context to use.
1249 * @param[in] ev The event handle to setup the request.
1251 * @param[in] wakeup_time The time to wakeup and execute the request.
1253 * @return The new subrequest, NULL on error.
1255 * Example:
1256 * @code
1257 * static void my_callback_wakeup_done(tevent_req *subreq)
1259 * struct tevent_req *req = tevent_req_callback_data(subreq,
1260 * struct tevent_req);
1261 * bool ok;
1263 * ok = tevent_wakeup_recv(subreq);
1264 * TALLOC_FREE(subreq);
1265 * if (!ok) {
1266 * tevent_req_error(req, -1);
1267 * return;
1269 * ...
1271 * @endcode
1273 * @code
1274 * subreq = tevent_wakeup_send(mem_ctx, ev, wakeup_time);
1275 * if (tevent_req_nomem(subreq, req)) {
1276 * return false;
1278 * tevent_set_callback(subreq, my_callback_wakeup_done, req);
1279 * @endcode
1281 * @see tevent_wakeup_recv()
1283 struct tevent_req *tevent_wakeup_send(TALLOC_CTX *mem_ctx,
1284 struct tevent_context *ev,
1285 struct timeval wakeup_time);
1288 * @brief Check if the wakeup has been correctly executed.
1290 * This function needs to be called in the callback function set after calling
1291 * tevent_wakeup_send().
1293 * @param[in] req The tevent request to check.
1295 * @return True on success, false otherwise.
1297 * @see tevent_wakeup_recv()
1299 bool tevent_wakeup_recv(struct tevent_req *req);
1301 /* @} */
1304 * @defgroup tevent_helpers The tevent helper functiions
1305 * @ingroup tevent
1307 * @todo description
1309 * @{
1313 * @brief Compare two timeval values.
1315 * @param[in] tv1 The first timeval value to compare.
1317 * @param[in] tv2 The second timeval value to compare.
1319 * @return 0 if they are equal.
1320 * 1 if the first time is greater than the second.
1321 * -1 if the first time is smaller than the second.
1323 int tevent_timeval_compare(const struct timeval *tv1,
1324 const struct timeval *tv2);
1327 * @brief Get a zero timval value.
1329 * @return A zero timval value.
1331 struct timeval tevent_timeval_zero(void);
1334 * @brief Get a timeval value for the current time.
1336 * @return A timval value with the current time.
1338 struct timeval tevent_timeval_current(void);
1341 * @brief Get a timeval structure with the given values.
1343 * @param[in] secs The seconds to set.
1345 * @param[in] usecs The microseconds to set.
1347 * @return A timeval structure with the given values.
1349 struct timeval tevent_timeval_set(uint32_t secs, uint32_t usecs);
1352 * @brief Get the difference between two timeval values.
1354 * @param[in] tv1 The first timeval.
1356 * @param[in] tv2 The second timeval.
1358 * @return A timeval structure with the difference between the
1359 * first and the second value.
1361 struct timeval tevent_timeval_until(const struct timeval *tv1,
1362 const struct timeval *tv2);
1365 * @brief Check if a given timeval structure is zero.
1367 * @param[in] tv The timeval to check if it is zero.
1369 * @return True if it is zero, false otherwise.
1371 bool tevent_timeval_is_zero(const struct timeval *tv);
1374 * @brief Add the given amount of time to a timeval structure.
1376 * @param[in] tv The timeval structure to add the time.
1378 * @param[in] secs The seconds to add to the timeval.
1380 * @param[in] usecs The microseconds to add to the timeval.
1382 * @return The timeval structure with the new time.
1384 struct timeval tevent_timeval_add(const struct timeval *tv, uint32_t secs,
1385 uint32_t usecs);
1388 * @brief Get a timeval in the future with a specified offset from now.
1390 * @param[in] secs The seconds of the offset from now.
1392 * @param[in] usecs The microseconds of the offset from now.
1394 * @return A timval with the given offset in the future.
1396 struct timeval tevent_timeval_current_ofs(uint32_t secs, uint32_t usecs);
1398 /* @} */
1402 * @defgroup tevent_queue The tevent queue functions
1403 * @ingroup tevent
1405 * A tevent_queue is used to queue up async requests that must be
1406 * serialized. For example writing buffers into a socket must be
1407 * serialized. Writing a large lump of data into a socket can require
1408 * multiple write(2) or send(2) system calls. If more than one async
1409 * request is outstanding to write large buffers into a socket, every
1410 * request must individually be completed before the next one begins,
1411 * even if multiple syscalls are required.
1413 * Take a look at @ref tevent_queue_tutorial for more details.
1414 * @{
1417 struct tevent_queue;
1418 struct tevent_queue_entry;
1420 #ifdef DOXYGEN
1422 * @brief Create and start a tevent queue.
1424 * @param[in] mem_ctx The talloc memory context to allocate the queue.
1426 * @param[in] name The name to use to identify the queue.
1428 * @return An allocated tevent queue on success, NULL on error.
1430 * @see tevent_queue_start()
1431 * @see tevent_queue_stop()
1433 struct tevent_queue *tevent_queue_create(TALLOC_CTX *mem_ctx,
1434 const char *name);
1435 #else
1436 struct tevent_queue *_tevent_queue_create(TALLOC_CTX *mem_ctx,
1437 const char *name,
1438 const char *location);
1440 #define tevent_queue_create(_mem_ctx, _name) \
1441 _tevent_queue_create((_mem_ctx), (_name), __location__)
1442 #endif
1445 * @brief A callback trigger function run by the queue.
1447 * @param[in] req The tevent request the trigger function is executed on.
1449 * @param[in] private_data The private data pointer specified by
1450 * tevent_queue_add().
1452 * @see tevent_queue_add()
1453 * @see tevent_queue_add_entry()
1454 * @see tevent_queue_add_optimize_empty()
1456 typedef void (*tevent_queue_trigger_fn_t)(struct tevent_req *req,
1457 void *private_data);
1460 * @brief Add a tevent request to the queue.
1462 * @param[in] queue The queue to add the request.
1464 * @param[in] ev The event handle to use for the request.
1466 * @param[in] req The tevent request to add to the queue.
1468 * @param[in] trigger The function triggered by the queue when the request
1469 * is called. Since tevent 0.9.14 it's possible to
1470 * pass NULL, in order to just add a "blocker" to the
1471 * queue.
1473 * @param[in] private_data The private data passed to the trigger function.
1475 * @return True if the request has been successfully added, false
1476 * otherwise.
1478 bool tevent_queue_add(struct tevent_queue *queue,
1479 struct tevent_context *ev,
1480 struct tevent_req *req,
1481 tevent_queue_trigger_fn_t trigger,
1482 void *private_data);
1485 * @brief Add a tevent request to the queue.
1487 * The request can be removed from the queue by calling talloc_free()
1488 * (or a similar function) on the returned queue entry. This
1489 * is the only difference to tevent_queue_add().
1491 * @param[in] queue The queue to add the request.
1493 * @param[in] ev The event handle to use for the request.
1495 * @param[in] req The tevent request to add to the queue.
1497 * @param[in] trigger The function triggered by the queue when the request
1498 * is called. Since tevent 0.9.14 it's possible to
1499 * pass NULL, in order to just add a "blocker" to the
1500 * queue.
1502 * @param[in] private_data The private data passed to the trigger function.
1504 * @return a pointer to the tevent_queue_entry if the request
1505 * has been successfully added, NULL otherwise.
1507 * @see tevent_queue_add()
1508 * @see tevent_queue_add_optimize_empty()
1510 struct tevent_queue_entry *tevent_queue_add_entry(
1511 struct tevent_queue *queue,
1512 struct tevent_context *ev,
1513 struct tevent_req *req,
1514 tevent_queue_trigger_fn_t trigger,
1515 void *private_data);
1518 * @brief Add a tevent request to the queue using a possible optimization.
1520 * This tries to optimize for the empty queue case and may calls
1521 * the trigger function directly. This is the only difference compared
1522 * to tevent_queue_add_entry().
1524 * The caller needs to be prepared that the trigger function has
1525 * already called tevent_req_notify_callback(), tevent_req_error(),
1526 * tevent_req_done() or a similar function.
1528 * The request can be removed from the queue by calling talloc_free()
1529 * (or a similar function) on the returned queue entry.
1531 * @param[in] queue The queue to add the request.
1533 * @param[in] ev The event handle to use for the request.
1535 * @param[in] req The tevent request to add to the queue.
1537 * @param[in] trigger The function triggered by the queue when the request
1538 * is called. Since tevent 0.9.14 it's possible to
1539 * pass NULL, in order to just add a "blocker" to the
1540 * queue.
1542 * @param[in] private_data The private data passed to the trigger function.
1544 * @return a pointer to the tevent_queue_entry if the request
1545 * has been successfully added, NULL otherwise.
1547 * @see tevent_queue_add()
1548 * @see tevent_queue_add_entry()
1550 struct tevent_queue_entry *tevent_queue_add_optimize_empty(
1551 struct tevent_queue *queue,
1552 struct tevent_context *ev,
1553 struct tevent_req *req,
1554 tevent_queue_trigger_fn_t trigger,
1555 void *private_data);
1558 * @brief Start a tevent queue.
1560 * The queue is started by default.
1562 * @param[in] queue The queue to start.
1564 void tevent_queue_start(struct tevent_queue *queue);
1567 * @brief Stop a tevent queue.
1569 * The queue is started by default.
1571 * @param[in] queue The queue to stop.
1573 void tevent_queue_stop(struct tevent_queue *queue);
1576 * @brief Get the length of the queue.
1578 * @param[in] queue The queue to get the length from.
1580 * @return The number of elements.
1582 size_t tevent_queue_length(struct tevent_queue *queue);
1585 * @brief Is the tevent queue running.
1587 * The queue is started by default.
1589 * @param[in] queue The queue.
1591 * @return Wether the queue is running or not..
1593 bool tevent_queue_running(struct tevent_queue *queue);
1595 typedef int (*tevent_nesting_hook)(struct tevent_context *ev,
1596 void *private_data,
1597 uint32_t level,
1598 bool begin,
1599 void *stack_ptr,
1600 const char *location);
1601 #ifdef TEVENT_DEPRECATED
1602 #ifndef _DEPRECATED_
1603 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
1604 #define _DEPRECATED_ __attribute__ ((deprecated))
1605 #else
1606 #define _DEPRECATED_
1607 #endif
1608 #endif
1609 void tevent_loop_allow_nesting(struct tevent_context *ev) _DEPRECATED_;
1610 void tevent_loop_set_nesting_hook(struct tevent_context *ev,
1611 tevent_nesting_hook hook,
1612 void *private_data) _DEPRECATED_;
1613 int _tevent_loop_until(struct tevent_context *ev,
1614 bool (*finished)(void *private_data),
1615 void *private_data,
1616 const char *location) _DEPRECATED_;
1617 #define tevent_loop_until(ev, finished, private_data) \
1618 _tevent_loop_until(ev, finished, private_data, __location__)
1619 #endif
1621 int tevent_re_initialise(struct tevent_context *ev);
1623 /* @} */
1626 * @defgroup tevent_ops The tevent operation functions
1627 * @ingroup tevent
1629 * The following structure and registration functions are exclusively
1630 * needed for people writing and pluggin a different event engine.
1631 * There is nothing useful for normal tevent user in here.
1632 * @{
1635 struct tevent_ops {
1636 /* context init */
1637 int (*context_init)(struct tevent_context *ev);
1639 /* fd_event functions */
1640 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
1641 TALLOC_CTX *mem_ctx,
1642 int fd, uint16_t flags,
1643 tevent_fd_handler_t handler,
1644 void *private_data,
1645 const char *handler_name,
1646 const char *location);
1647 void (*set_fd_close_fn)(struct tevent_fd *fde,
1648 tevent_fd_close_fn_t close_fn);
1649 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
1650 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
1652 /* timed_event functions */
1653 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
1654 TALLOC_CTX *mem_ctx,
1655 struct timeval next_event,
1656 tevent_timer_handler_t handler,
1657 void *private_data,
1658 const char *handler_name,
1659 const char *location);
1661 /* immediate event functions */
1662 void (*schedule_immediate)(struct tevent_immediate *im,
1663 struct tevent_context *ev,
1664 tevent_immediate_handler_t handler,
1665 void *private_data,
1666 const char *handler_name,
1667 const char *location);
1669 /* signal functions */
1670 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
1671 TALLOC_CTX *mem_ctx,
1672 int signum, int sa_flags,
1673 tevent_signal_handler_t handler,
1674 void *private_data,
1675 const char *handler_name,
1676 const char *location);
1678 /* loop functions */
1679 int (*loop_once)(struct tevent_context *ev, const char *location);
1680 int (*loop_wait)(struct tevent_context *ev, const char *location);
1683 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
1685 /* @} */
1688 * @defgroup tevent_compat The tevent compatibility functions
1689 * @ingroup tevent
1691 * The following definitions are usueful only for compatibility with the
1692 * implementation originally developed within the samba4 code and will be
1693 * soon removed. Please NEVER use in new code.
1695 * @todo Ignore it?
1697 * @{
1700 #ifdef TEVENT_COMPAT_DEFINES
1702 #define event_context tevent_context
1703 #define event_ops tevent_ops
1704 #define fd_event tevent_fd
1705 #define timed_event tevent_timer
1706 #define signal_event tevent_signal
1708 #define event_fd_handler_t tevent_fd_handler_t
1709 #define event_timed_handler_t tevent_timer_handler_t
1710 #define event_signal_handler_t tevent_signal_handler_t
1712 #define event_context_init(mem_ctx) \
1713 tevent_context_init(mem_ctx)
1715 #define event_context_init_byname(mem_ctx, name) \
1716 tevent_context_init_byname(mem_ctx, name)
1718 #define event_backend_list(mem_ctx) \
1719 tevent_backend_list(mem_ctx)
1721 #define event_set_default_backend(backend) \
1722 tevent_set_default_backend(backend)
1724 #define event_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \
1725 tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data)
1727 #define event_add_timed(ev, mem_ctx, next_event, handler, private_data) \
1728 tevent_add_timer(ev, mem_ctx, next_event, handler, private_data)
1730 #define event_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \
1731 tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data)
1733 #define event_loop_once(ev) \
1734 tevent_loop_once(ev)
1736 #define event_loop_wait(ev) \
1737 tevent_loop_wait(ev)
1739 #define event_get_fd_flags(fde) \
1740 tevent_fd_get_flags(fde)
1742 #define event_set_fd_flags(fde, flags) \
1743 tevent_fd_set_flags(fde, flags)
1745 #define EVENT_FD_READ TEVENT_FD_READ
1746 #define EVENT_FD_WRITE TEVENT_FD_WRITE
1748 #define EVENT_FD_WRITEABLE(fde) \
1749 TEVENT_FD_WRITEABLE(fde)
1751 #define EVENT_FD_READABLE(fde) \
1752 TEVENT_FD_READABLE(fde)
1754 #define EVENT_FD_NOT_WRITEABLE(fde) \
1755 TEVENT_FD_NOT_WRITEABLE(fde)
1757 #define EVENT_FD_NOT_READABLE(fde) \
1758 TEVENT_FD_NOT_READABLE(fde)
1760 #define ev_debug_level tevent_debug_level
1762 #define EV_DEBUG_FATAL TEVENT_DEBUG_FATAL
1763 #define EV_DEBUG_ERROR TEVENT_DEBUG_ERROR
1764 #define EV_DEBUG_WARNING TEVENT_DEBUG_WARNING
1765 #define EV_DEBUG_TRACE TEVENT_DEBUG_TRACE
1767 #define ev_set_debug(ev, debug, context) \
1768 tevent_set_debug(ev, debug, context)
1770 #define ev_set_debug_stderr(_ev) tevent_set_debug_stderr(ev)
1772 #endif /* TEVENT_COMPAT_DEFINES */
1774 /* @} */
1776 #endif /* __TEVENT_H__ */