xref: /netbsd/sys/sys/epoll.h (revision 47cc1f20)
1 /*	$NetBSD: epoll.h,v 1.1 2023/07/28 18:19:01 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2007 Roman Divacky
5  * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _SYS_EPOLL_H_
32 #define	_SYS_EPOLL_H_
33 
34 #include <sys/types.h>			/* for uint32_t, uint64_t */
35 #include <sys/sigtypes.h>		/* for sigset_t */
36 struct timespec;
37 
38 #define	EPOLLIN		0x00000001
39 #define	EPOLLPRI	0x00000002
40 #define	EPOLLOUT	0x00000004
41 #define	EPOLLERR	0x00000008
42 #define	EPOLLHUP	0x00000010
43 #define	EPOLLRDNORM	0x00000040
44 #define	EPOLLRDBAND	0x00000080
45 #define	EPOLLWRNORM	0x00000100
46 #define	EPOLLWRBAND	0x00000200
47 #define	EPOLLMSG	0x00000400
48 #define	EPOLLRDHUP	0x00002000
49 #define	EPOLLWAKEUP	0x20000000
50 #define	EPOLLONESHOT	0x40000000
51 #define	EPOLLET		0x80000000
52 
53 #define	EPOLL_CTL_ADD	1
54 #define	EPOLL_CTL_DEL	2
55 #define	EPOLL_CTL_MOD	3
56 
57 #ifdef _KERNEL
58 #define	EPOLL_MAX_EVENTS	(4 * 1024 * 1024)
59 typedef uint64_t		epoll_data_t;
60 #else
61 union epoll_data {
62 	void		*ptr;
63 	int		fd;
64 	uint32_t	u32;
65 	uint64_t	u64;
66 };
67 
68 typedef union epoll_data	epoll_data_t;
69 #endif
70 
71 struct epoll_event {
72 	uint32_t	events;
73 	epoll_data_t	data;
74 };
75 
76 #ifdef _KERNEL
77 int	epoll_ctl_common(struct lwp *l, register_t *retval, int epfd, int op,
78 	    int fd, struct epoll_event *event);
79 int	epoll_wait_common(struct lwp *l, register_t *retval, int epfd,
80 	    struct epoll_event *events, int maxevents, struct timespec *tsp,
81 	    const sigset_t *nss);
82 #else	/* !_KERNEL */
83 __BEGIN_DECLS
84 #ifdef _NETBSD_SOURCE
85 int	epoll_create(int size);
86 int	epoll_create1(int flags);
87 int	epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
88 int	epoll_wait(int epfd, struct epoll_event *events, int maxevents,
89 	    int timeout);
90 int	epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
91 	    int timeout, const sigset_t *sigmask);
92 int	epoll_pwait2(int epfd, struct epoll_event *events, int maxevents,
93 	    const struct timespec *timeout, const sigset_t *sigmask);
94 #endif	/* _NETBSD_SOURCE */
95 __END_DECLS
96 #endif	/* !_KERNEL */
97 
98 #endif	/* !_SYS_EPOLL_H_ */
99