xref: /illumos-gate/usr/src/uts/common/sys/poll.h (revision b93865c3d90e9b0d73e338c9abb3293c35c571a8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved	*/
24 
25 
26 /*
27  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
28  *
29  * Copyright (c) 1995, 1998 by Sun Microsystems, Inc.
30  * All rights reserved.
31  */
32 
33 /*
34  * Copyright 2015, Joyent, Inc.
35  */
36 
37 #ifndef _SYS_POLL_H
38 #define	_SYS_POLL_H
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Structure of file descriptor/event pairs supplied in
46  * the poll arrays.
47  */
48 typedef struct pollfd {
49 	int fd;				/* file desc to poll */
50 	short events;			/* events of interest on fd */
51 	short revents;			/* events that occurred on fd */
52 } pollfd_t;
53 
54 typedef unsigned long	nfds_t;
55 
56 /*
57  * Testable select events
58  */
59 #define	POLLIN		0x0001		/* fd is readable */
60 #define	POLLPRI		0x0002		/* high priority info at fd */
61 #define	POLLOUT		0x0004		/* fd is writeable (won't block) */
62 #define	POLLRDNORM	0x0040		/* normal data is readable */
63 #define	POLLWRNORM	POLLOUT
64 #define	POLLRDBAND	0x0080		/* out-of-band data is readable */
65 #define	POLLWRBAND	0x0100		/* out-of-band data is writeable */
66 #define	POLLRDHUP	0x4000		/* read-side hangup */
67 
68 #define	POLLNORM	POLLRDNORM
69 
70 /*
71  * Non-testable poll events (may not be specified in events field,
72  * but may be returned in revents field).
73  */
74 #define	POLLERR		0x0008		/* fd has error condition */
75 #define	POLLHUP		0x0010		/* fd has been hung up on */
76 #define	POLLNVAL	0x0020		/* invalid pollfd entry */
77 
78 /*
79  * These events will never be specified in revents, but may be specified in
80  * events to control /dev/poll behavior.
81  */
82 #define	POLLREMOVE	0x0800		/* remove cached /dev/poll fd */
83 #define	POLLONESHOT	0x1000		/* /dev/poll should one-shot this fd */
84 #define	POLLET		0x2000		/* edge-triggered /dev/poll fd */
85 
86 #ifdef _KERNEL
87 
88 /*
89  * Additional private poll flags supported only by strpoll().
90  * Must be bit-wise distinct from the above POLL flags.
91  */
92 #define	POLLRDDATA	0x0200	/* Wait for M_DATA; ignore M_PROTO only msgs */
93 #define	POLLNOERR	0x0400	/* Ignore POLLERR conditions */
94 
95 #define	POLLCLOSED	0x8000	/* a (cached) poll fd has been closed */
96 
97 #endif /* _KERNEL */
98 
99 #if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER)
100 
101 #include <sys/thread.h>
102 
103 /*
104  * XXX We are forced to use a forward reference here because including
105  * file.h here will break i386 build. The real solution is to fix the
106  * broken parts in usr/src/stand/lib/fs.
107  */
108 struct fpollinfo;
109 
110 /*
111  * Poll list head structure.  A pointer to this is passed to
112  * pollwakeup() from the caller indicating an event has occurred.
113  * Only the ph_list field is used, but for DDI compliance, we can't
114  * change the size of the structure.
115  */
116 typedef struct pollhead {
117 	struct polldat		*ph_list;	/* list of pollers */
118 	void			*ph_pad1;	/* unused -- see above */
119 	short			ph_pad2;	/* unused -- see above */
120 } pollhead_t;
121 
122 #if defined(_KERNEL)
123 
124 /*
125  * Routine called to notify a process of the occurrence
126  * of an event.
127  */
128 extern void pollwakeup(pollhead_t *, short);
129 
130 /*
131  * Internal routines.
132  */
133 extern int polllock(pollhead_t *, kmutex_t *);
134 extern int pollunlock(int *);
135 extern void pollrelock(int);
136 extern void pollcleanup(void);
137 extern void pollblockexit(struct fpollinfo *);
138 extern void pollcacheclean(struct fpollinfo *, int);
139 
140 /*
141  * public poll head interface:
142  *
143  *  pollhead_clean      clean up all polldats on a pollhead list
144  */
145 extern void pollhead_clean(pollhead_t *);
146 
147 #endif /* defined(_KERNEL) */
148 
149 #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
150 
151 #if !defined(_KERNEL)
152 int poll(struct pollfd *, nfds_t, int);
153 #endif /* !_KERNEL */
154 
155 #ifdef	__cplusplus
156 }
157 #endif
158 
159 #endif	/* _SYS_POLL_H */
160