s3:rpc_server: use get_client_fd() instead of smbd_server_fd()
[Samba/gbeck.git] / lib / tevent / tevent_internal.h
blob32be12c8d882307e1a04c9d0e6ecca7476945635
1 /*
2 Unix SMB/CIFS implementation.
4 generalised event loop handling
6 Internal structs
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/>.
24 struct tevent_ops {
25 /* conntext init */
26 int (*context_init)(struct tevent_context *ev);
28 /* fd_event functions */
29 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
30 TALLOC_CTX *mem_ctx,
31 int fd, uint16_t flags,
32 tevent_fd_handler_t handler,
33 void *private_data,
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,
43 TALLOC_CTX *mem_ctx,
44 struct timeval next_event,
45 tevent_timer_handler_t handler,
46 void *private_data,
47 const char *handler_name,
48 const char *location);
49 /* disk aio event functions */
50 struct tevent_aio *(*add_aio)(struct tevent_context *ev,
51 TALLOC_CTX *mem_ctx,
52 struct iocb *iocb,
53 tevent_aio_handler_t handler,
54 void *private_data,
55 const char *handler_name,
56 const char *location);
57 /* signal functions */
58 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
59 TALLOC_CTX *mem_ctx,
60 int signum, int sa_flags,
61 tevent_signal_handler_t handler,
62 void *private_data,
63 const char *handler_name,
64 const char *location);
66 /* loop functions */
67 int (*loop_once)(struct tevent_context *ev);
68 int (*loop_wait)(struct tevent_context *ev);
71 struct tevent_fd {
72 struct tevent_fd *prev, *next;
73 struct tevent_context *event_ctx;
74 int fd;
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 */
79 void *private_data;
80 /* this is for debugging only! */
81 const char *handler_name;
82 const char *location;
83 /* this is private for the events_ops implementation */
84 uint16_t additional_flags;
85 void *additional_data;
88 struct tevent_timer {
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 */
94 void *private_data;
95 /* this is for debugging only! */
96 const char *handler_name;
97 const char *location;
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;
105 int signum;
106 int sa_flags;
107 tevent_signal_handler_t handler;
108 /* this is private for the specific handler */
109 void *private_data;
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);
120 void *context;
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 */
127 struct tevent_aio;
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,
159 TALLOC_CTX *mem_ctx,
160 int fd,
161 uint16_t flags,
162 tevent_fd_handler_t handler,
163 void *private_data,
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,
173 TALLOC_CTX *mem_ctx,
174 struct timeval next_event,
175 tevent_timer_handler_t handler,
176 void *private_data,
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,
182 TALLOC_CTX *mem_ctx,
183 int signum,
184 int sa_flags,
185 tevent_signal_handler_t handler,
186 void *private_data,
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);
193 #ifdef HAVE_EPOLL
194 bool tevent_epoll_init(void);
195 #endif
196 #ifdef HAVE_LINUX_AIO
197 bool tevent_aio_init(void);
198 #endif