/** * @defgroup poll Poll * @ingroup libc */ #ifndef _POLL_H #define _POLL_H #ifdef __cplusplus extern "C" { #endif #include #include #define POLLIN 0x001 #define POLLPRI 0x002 #define POLLOUT 0x004 #define POLLERR 0x008 #define POLLHUP 0x010 #define POLLNVAL 0x020 #define POLLRDNORM 0x040 #define POLLRDBAND 0x080 #ifndef POLLWRNORM #define POLLWRNORM 0x100 #define POLLWRBAND 0x200 #endif #ifndef POLLMSG #define POLLMSG 0x400 #define POLLRDHUP 0x2000 #endif typedef unsigned long nfds_t; #include "poll_adapt.h" /** * @ingroup poll * @par Description: * * The poll function provides applications with a mechanism for multiplexing input/output over a set of file descriptors. For each member of the * array pointed to by fds, the poll examines the given file descriptor for the event(s) specified in events. The poll identifies those file descriptors * on which an application can read or write data, or on which certain events have occurred.\n\n * * The fds argument specifies the file descriptors to be examined and the events of interest for each file descriptor. It is a pointer to an array with * one member for each open file descriptor of interest. The array's members are pollfd structures within which fd specifies an open file descriptor * and events and revents are bitmasks constructed by OR'ing a combination of the following event flags:\n * POLLIN -- There is data to read.\n * POLLOUT -- Writing is now possible, though a write larger that the available space in a socket or pipe will still block (unless O_NONBLOCK is set).\n * POLLERR -- Error condition (only returned in revents; ignored in events).\n * POLLRDHUP -- Stream socket peer closed connection, or shut down writing half of connection.\n * POLLHUP -- Hang up (only returned in revents; ignored in events). Note that when reading from a channel such as a stream socket, this event * merely indicates that the peer closed its end of the channel. Subsequent reads from the channel will return 0 (end of file) only after all outstanding * data in the channel has been consumed.\n\n * * @param fds [IN/OUT] The field fd contains a file descriptor for an open file. The field events is an input parameter, a bit mask specifying * the events the application is interested in for the file descriptor fd. This field can be specified as zero, in which case the only events that can be * returned in revents are POLLHUP and POLLERR. The field revents is an output parameter, filled by LiteOS kernel with the events that actually occurred. * The bits returned in revents can include any of those specified in events, or one of the values POLLERR or POLLHUP. * @param nfds [IN] the number of items in the fds. * @param timeout [IN] the number of milliseconds that the poll should block waiting for a file descriptor to become ready. The call will block until * either a file descriptor becomes ready or the timeout expires. If the value of timeout is 0, poll just check the file descriptors and return immediately, * even if no file descriptors are ready. If the value of timeout is -1, poll blocks until a requested event occurs. * * @attention * * * @retval #>=0 On success, a positive number is returned; this is the number of structures which have nonzero revents fields (in other words, * those descriptors with events or errors reported). A value of 0 indicates that the call timed out and no file descriptors were ready. * @retval #-1 On failure, -1 is returned, and errno is set to indicate the error. * * @par Errors * * * @par Dependency: * * * @see accept | connect | select | read | recv | send | write * * @since Huawei LiteOS V100R001C00 */ int poll (struct pollfd *, nfds_t, int); #ifdef _GNU_SOURCE #define __NEED_time_t #define __NEED_struct_timespec #define __NEED_sigset_t #include int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); #endif #if _REDIR_TIME64 #ifdef _GNU_SOURCE __REDIR(ppoll, __ppoll_time64); #endif #endif #ifdef __cplusplus } #endif #endif