2 Unix SMB/CIFS implementation.
4 generalised event loop handling
8 Copyright (C) Stefan Metzmacher 2005
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 int (*context_init)(struct tevent_context *ev);
28 /* fd_event functions */
29 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
31 int fd, uint16_t flags,
32 tevent_fd_handler_t handler,
34 const char *handler_name,
35 const char *location);
36 void (*set_fd_close_fn)(struct tevent_fd *fde,
37 tevent_fd_close_fn_t close_fn);
38 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
39 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
41 /* timed_event functions */
42 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
44 struct timeval next_event,
45 tevent_timer_handler_t handler,
47 const char *handler_name,
48 const char *location);
49 /* disk aio event functions */
50 struct tevent_aio *(*add_aio)(struct tevent_context *ev,
53 tevent_aio_handler_t handler,
55 const char *handler_name,
56 const char *location);
57 /* signal functions */
58 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
60 int signum, int sa_flags,
61 tevent_signal_handler_t handler,
63 const char *handler_name,
64 const char *location);
67 int (*loop_once)(struct tevent_context *ev);
68 int (*loop_wait)(struct tevent_context *ev);
72 struct tevent_fd *prev, *next;
73 struct tevent_context *event_ctx;
75 uint16_t flags; /* see TEVENT_FD_* flags */
76 tevent_fd_handler_t handler;
77 tevent_fd_close_fn_t close_fn;
78 /* this is private for the specific handler */
80 /* this is for debugging only! */
81 const char *handler_name;
83 /* this is private for the events_ops implementation */
84 uint16_t additional_flags;
85 void *additional_data;
89 struct tevent_timer *prev, *next;
90 struct tevent_context *event_ctx;
91 struct timeval next_event;
92 tevent_timer_handler_t handler;
93 /* this is private for the specific handler */
95 /* this is for debugging only! */
96 const char *handler_name;
98 /* this is private for the events_ops implementation */
99 void *additional_data;
102 struct tevent_signal {
103 struct tevent_signal *prev, *next;
104 struct tevent_context *event_ctx;
107 tevent_signal_handler_t handler;
108 /* this is private for the specific handler */
110 /* this is for debugging only! */
111 const char *handler_name;
112 const char *location;
113 /* this is private for the events_ops implementation */
114 void *additional_data;
117 struct tevent_debug_ops {
118 void (*debug)(void *context, enum tevent_debug_level level,
119 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
123 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
124 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
126 /* aio event is private to the aio backend */
129 struct tevent_context {
130 /* the specific events implementation */
131 const struct tevent_ops *ops;
133 /* list of timed events - used by common code */
134 struct tevent_timer *timer_events;
136 /* list of signal events - used by common code */
137 struct tevent_signal *signal_events;
139 /* this is private for the events_ops implementation */
140 void *additional_data;
142 /* pipe hack used with signal handlers */
143 struct tevent_fd *pipe_fde;
145 /* debugging operations */
146 struct tevent_debug_ops debug_ops;
150 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
152 void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
153 tevent_fd_close_fn_t close_fn);
154 uint16_t tevent_common_fd_get_flags(struct tevent_fd *fde);
155 void tevent_common_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
157 bool ev_timeval_is_zero(const struct timeval *tv);
158 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
160 struct timeval next_event,
161 tevent_timer_handler_t handler,
163 const char *handler_name,
164 const char *location);
165 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
167 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
171 tevent_signal_handler_t handler,
173 const char *handler_name,
174 const char *location);
175 int tevent_common_check_signal(struct tevent_context *ev);
177 bool tevent_standard_init(void);
178 bool tevent_select_init(void);
180 bool tevent_epoll_init(void);
182 #ifdef HAVE_LINUX_AIO
183 bool tevent_aio_init(void);