xref: /haiku/headers/compatibility/bsd/sys/event.h (revision 7eab6b486ebadb54ca3c306601f4b04dd92359fa)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
5  * All rights reserved.
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 #ifndef _BSD_SYS_EVENT_H_
31 #define _BSD_SYS_EVENT_H_
32 
33 #include <features.h>
34 
35 #ifdef _DEFAULT_SOURCE
36 
37 #include <stdint.h>
38 
39 
40 #define EVFILT_READ			(-1)
41 #define EVFILT_WRITE		(-2)
42 #define EVFILT_PROC			(-5)
43 
44 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
45 #define	EV_SET(kevp_, a, b, c, d, e, f) do {	\
46 	*(kevp_) = (struct kevent){		\
47 		.ident = (a),			\
48 		.filter = (b),			\
49 		.flags = (c),			\
50 		.fflags = (d),			\
51 		.data = (e),			\
52 		.udata = (f),			\
53 		.ext = {0},				\
54 	};					\
55 } while (0)
56 #else /* Pre-C99 or not STDC (e.g., C++) */
57 /*
58  * The definition of the local variable kevp could possibly conflict
59  * with a user-defined value passed in parameters a-f.
60  */
61 #define EV_SET(kevp_, a, b, c, d, e, f) do {	\
62 	struct kevent *kevp = (kevp_);		\
63 	(kevp)->ident = (a);			\
64 	(kevp)->filter = (b);			\
65 	(kevp)->flags = (c);			\
66 	(kevp)->fflags = (d);			\
67 	(kevp)->data = (e);			\
68 	(kevp)->udata = (f);			\
69 	(kevp)->ext[0] = 0;			\
70 	(kevp)->ext[1] = 0;			\
71 	(kevp)->ext[2] = 0;			\
72 	(kevp)->ext[3] = 0;			\
73 } while (0)
74 #endif
75 
76 struct kevent {
77 	uintptr_t	ident;		/* identifier for this event */
78 	short		filter;		/* filter for event */
79 	unsigned short	flags;		/* action flags for kqueue */
80 	unsigned int	fflags;		/* filter flag value */
81 	int64_t	data;		/* filter data value */
82 	void		*udata;		/* opaque user data identifier */
83 	uint64_t	ext[4];		/* extensions */
84 };
85 
86 /* actions */
87 #define EV_ADD		0x0001		/* add event to kq (implies enable) */
88 #define EV_DELETE	0x0002		/* delete event from kq */
89 
90 /* flags */
91 #define EV_ONESHOT	0x0010		/* only report one occurrence */
92 #define EV_CLEAR	0x0020		/* clear event state after reporting */
93 
94 /* returned values */
95 #define EV_EOF		0x8000		/* EOF detected */
96 #define EV_ERROR	0x4000		/* error, data contains errno */
97 
98 /* data/hint flags for EVFILT_PROC */
99 #define	NOTE_EXIT	0x80000000		/* process exited */
100 
101 
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
106 int     kqueue(void);
107 int     kevent(int kq, const struct kevent *changelist, int nchanges,
108 			struct kevent *eventlist, int nevents,
109 			const struct timespec *timeout);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 
116 #endif	/* _DEFAULT_SOURCE */
117 
118 #endif	/* _BSD_SYS_EVENT_H_ */
119