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