1a9643ea8Slogwang /*- 2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-3-Clause 3*22ce4affSfengbojiang * 4a9643ea8Slogwang * Copyright (c) 1997 Peter Wemm <[email protected]> 5a9643ea8Slogwang * All rights reserved. 6a9643ea8Slogwang * 7a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without 8a9643ea8Slogwang * modification, are permitted provided that the following conditions 9a9643ea8Slogwang * are met: 10a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright 11a9643ea8Slogwang * notice, this list of conditions and the following disclaimer. 12a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright 13a9643ea8Slogwang * notice, this list of conditions and the following disclaimer in the 14a9643ea8Slogwang * documentation and/or other materials provided with the distribution. 15a9643ea8Slogwang * 3. The name of the author may not be used to endorse or promote products 16a9643ea8Slogwang * derived from this software without specific prior written permission. 17a9643ea8Slogwang * 18a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21a9643ea8Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28a9643ea8Slogwang * SUCH DAMAGE. 29a9643ea8Slogwang * 30a9643ea8Slogwang * $FreeBSD$ 31a9643ea8Slogwang */ 32a9643ea8Slogwang 33a9643ea8Slogwang #ifndef _SYS_POLL_H_ 34a9643ea8Slogwang #define _SYS_POLL_H_ 35a9643ea8Slogwang 36a9643ea8Slogwang #include <sys/cdefs.h> 37a9643ea8Slogwang 38a9643ea8Slogwang /* 39a9643ea8Slogwang * This file is intended to be compatible with the traditional poll.h. 40a9643ea8Slogwang */ 41a9643ea8Slogwang 42a9643ea8Slogwang typedef unsigned int nfds_t; 43a9643ea8Slogwang 44a9643ea8Slogwang /* 45a9643ea8Slogwang * This structure is passed as an array to poll(2). 46a9643ea8Slogwang */ 47a9643ea8Slogwang struct pollfd { 48a9643ea8Slogwang int fd; /* which file descriptor to poll */ 49a9643ea8Slogwang short events; /* events we are interested in */ 50a9643ea8Slogwang short revents; /* events found on return */ 51a9643ea8Slogwang }; 52a9643ea8Slogwang 53a9643ea8Slogwang /* 54a9643ea8Slogwang * Requestable events. If poll(2) finds any of these set, they are 55a9643ea8Slogwang * copied to revents on return. 56a9643ea8Slogwang * XXX Note that FreeBSD doesn't make much distinction between POLLPRI 57a9643ea8Slogwang * and POLLRDBAND since none of the file types have distinct priority 58a9643ea8Slogwang * bands - and only some have an urgent "mode". 59a9643ea8Slogwang * XXX Note POLLIN isn't really supported in true SVSV terms. Under SYSV 60a9643ea8Slogwang * POLLIN includes all of normal, band and urgent data. Most poll handlers 61a9643ea8Slogwang * on FreeBSD only treat it as "normal" data. 62a9643ea8Slogwang */ 63a9643ea8Slogwang #define POLLIN 0x0001 /* any readable data available */ 64a9643ea8Slogwang #define POLLPRI 0x0002 /* OOB/Urgent readable data */ 65a9643ea8Slogwang #define POLLOUT 0x0004 /* file descriptor is writeable */ 66a9643ea8Slogwang #define POLLRDNORM 0x0040 /* non-OOB/URG data available */ 67a9643ea8Slogwang #define POLLWRNORM POLLOUT /* no write type differentiation */ 68a9643ea8Slogwang #define POLLRDBAND 0x0080 /* OOB/Urgent readable data */ 69a9643ea8Slogwang #define POLLWRBAND 0x0100 /* OOB/Urgent data can be written */ 70a9643ea8Slogwang 71a9643ea8Slogwang #if __BSD_VISIBLE 72a9643ea8Slogwang /* General FreeBSD extension (currently only supported for sockets): */ 73a9643ea8Slogwang #define POLLINIGNEOF 0x2000 /* like POLLIN, except ignore EOF */ 74a9643ea8Slogwang #endif 75a9643ea8Slogwang 76a9643ea8Slogwang /* 77a9643ea8Slogwang * These events are set if they occur regardless of whether they were 78a9643ea8Slogwang * requested. 79a9643ea8Slogwang */ 80a9643ea8Slogwang #define POLLERR 0x0008 /* some poll error occurred */ 81a9643ea8Slogwang #define POLLHUP 0x0010 /* file descriptor was "hung up" */ 82a9643ea8Slogwang #define POLLNVAL 0x0020 /* requested events "invalid" */ 83a9643ea8Slogwang 84a9643ea8Slogwang #if __BSD_VISIBLE 85a9643ea8Slogwang 86a9643ea8Slogwang #define POLLSTANDARD (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|\ 87a9643ea8Slogwang POLLWRBAND|POLLERR|POLLHUP|POLLNVAL) 88a9643ea8Slogwang 89a9643ea8Slogwang /* 90a9643ea8Slogwang * Request that poll() wait forever. 91a9643ea8Slogwang * XXX in SYSV, this is defined in stropts.h, which is not included 92a9643ea8Slogwang * by poll.h. 93a9643ea8Slogwang */ 94a9643ea8Slogwang #define INFTIM (-1) 95a9643ea8Slogwang 96a9643ea8Slogwang #endif 97a9643ea8Slogwang 98a9643ea8Slogwang #ifndef _KERNEL 99a9643ea8Slogwang 100a9643ea8Slogwang #if __BSD_VISIBLE 101a9643ea8Slogwang #include <sys/_types.h> 102a9643ea8Slogwang 103a9643ea8Slogwang #include <sys/_sigset.h> 104a9643ea8Slogwang #include <sys/timespec.h> 105a9643ea8Slogwang 106a9643ea8Slogwang #ifndef _SIGSET_T_DECLARED 107a9643ea8Slogwang #define _SIGSET_T_DECLARED 108a9643ea8Slogwang typedef __sigset_t sigset_t; 109a9643ea8Slogwang #endif 110a9643ea8Slogwang 111a9643ea8Slogwang #endif 112a9643ea8Slogwang 113a9643ea8Slogwang __BEGIN_DECLS 114a9643ea8Slogwang int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout); 115a9643ea8Slogwang #if __BSD_VISIBLE 116a9643ea8Slogwang int ppoll(struct pollfd _pfd[], nfds_t _nfds, 117a9643ea8Slogwang const struct timespec *__restrict _timeout, 118a9643ea8Slogwang const sigset_t *__restrict _newsigmask); 119a9643ea8Slogwang #endif 120a9643ea8Slogwang __END_DECLS 121a9643ea8Slogwang 122a9643ea8Slogwang #endif /* !_KERNEL */ 123a9643ea8Slogwang 124a9643ea8Slogwang #endif /* !_SYS_POLL_H_ */ 125