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 fd events - used by common code */
134 struct tevent_fd
*fd_events
;
136 /* list of timed events - used by common code */
137 struct tevent_timer
*timer_events
;
139 /* list of signal events - used by common code */
140 struct tevent_signal
*signal_events
;
142 /* this is private for the events_ops implementation */
143 void *additional_data
;
145 /* pipe hack used with signal handlers */
146 struct tevent_fd
*pipe_fde
;
148 /* debugging operations */
149 struct tevent_debug_ops debug_ops
;
153 bool tevent_register_backend(const char *name
, const struct tevent_ops
*ops
);
155 int tevent_common_context_destructor(struct tevent_context
*ev
);
157 int tevent_common_fd_destructor(struct tevent_fd
*fde
);
158 struct tevent_fd
*tevent_common_add_fd(struct tevent_context
*ev
,
162 tevent_fd_handler_t handler
,
164 const char *handler_name
,
165 const char *location
);
166 void tevent_common_fd_set_close_fn(struct tevent_fd
*fde
,
167 tevent_fd_close_fn_t close_fn
);
168 uint16_t tevent_common_fd_get_flags(struct tevent_fd
*fde
);
169 void tevent_common_fd_set_flags(struct tevent_fd
*fde
, uint16_t flags
);
171 bool ev_timeval_is_zero(const struct timeval
*tv
);
172 struct tevent_timer
*tevent_common_add_timer(struct tevent_context
*ev
,
174 struct timeval next_event
,
175 tevent_timer_handler_t handler
,
177 const char *handler_name
,
178 const char *location
);
179 struct timeval
tevent_common_loop_timer_delay(struct tevent_context
*);
181 struct tevent_signal
*tevent_common_add_signal(struct tevent_context
*ev
,
185 tevent_signal_handler_t handler
,
187 const char *handler_name
,
188 const char *location
);
189 int tevent_common_check_signal(struct tevent_context
*ev
);
191 bool tevent_standard_init(void);
192 bool tevent_select_init(void);
194 bool tevent_epoll_init(void);
196 #ifdef HAVE_LINUX_AIO
197 bool tevent_aio_init(void);