2 Unix SMB/CIFS implementation.
4 generalised event loop handling
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "talloc/talloc.h"
35 /* event handler types */
36 typedef void (*event_fd_handler_t)(struct event_context *, struct fd_event *,
38 typedef void (*event_timed_handler_t)(struct event_context *, struct timed_event *,
39 struct timeval , void *);
40 typedef void (*event_signal_handler_t)(struct event_context *, struct signal_event *,
41 int , int, void *, void *);
42 typedef void (*event_aio_handler_t)(struct event_context *, struct aio_event *,
45 struct event_context *event_context_init(TALLOC_CTX *mem_ctx);
46 struct event_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char *name);
47 const char **event_backend_list(TALLOC_CTX *mem_ctx);
48 void event_set_default_backend(const char *backend);
50 struct fd_event *event_add_fd(struct event_context *ev, TALLOC_CTX *mem_ctx,
51 int fd, uint16_t flags, event_fd_handler_t handler,
54 struct timed_event *event_add_timed(struct event_context *ev, TALLOC_CTX *mem_ctx,
55 struct timeval next_event,
56 event_timed_handler_t handler,
59 struct signal_event *event_add_signal(struct event_context *ev, TALLOC_CTX *mem_ctx,
60 int signum, int sa_flags,
61 event_signal_handler_t handler,
65 struct aio_event *event_add_aio(struct event_context *ev,
68 event_aio_handler_t handler,
71 int event_loop_once(struct event_context *ev);
72 int event_loop_wait(struct event_context *ev);
74 uint16_t event_get_fd_flags(struct fd_event *fde);
75 void event_set_fd_flags(struct fd_event *fde, uint16_t flags);
77 struct event_context *event_context_find(TALLOC_CTX *mem_ctx);
79 /* bits for file descriptor event flags */
80 #define EVENT_FD_READ 1
81 #define EVENT_FD_WRITE 2
82 #define EVENT_FD_AUTOCLOSE 4
84 #define EVENT_FD_WRITEABLE(fde) \
85 event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_WRITE)
86 #define EVENT_FD_READABLE(fde) \
87 event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_READ)
89 #define EVENT_FD_NOT_WRITEABLE(fde) \
90 event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_WRITE)
91 #define EVENT_FD_NOT_READABLE(fde) \
92 event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_READ)
94 #endif /* __EVENTS_H__ */