#include <sys.socket.h>
#include <sys.poll.h>
Kernighan-Ritchie-C:int soc_poll(fds, nfds, timeout);
struct pollfd fds[];
unsigned long nfds;
int timeout;
ANSI-C:
int soc_poll(struct pollfd fds[], unsigned long nfds, int timeout);
Description
The soc_poll() function tests a set of socket descriptors, which are transmitted with an array of structure elements of type pollfd. Depending on the desired test, each descriptor-specific structure element states whether messages can be received or sent on this socket descriptor or whether specific events have occured.
The soc_poll() function is supported in the AF_INET, AF_INET6 and AF_ISO address families.
The fds parameter is a pointer to the array to be sent by the caller with an element of type struct pollfd for each socket descriptor to be tested.
The nfds parameter specifies the set of descriptors to be tested.
The timeout parameter specifies the maximum waiting time in seconds that the soc_poll() function is available for testing the descriptors, if no event occurs:
If timeout = 0: No waiting time, only all marked file descriptors are tested.
If timeout = -1: soc_poll() is blocked, until an event occurs in at least one of the selected file descriptors.
The maximum time value that will be accepted is ~ 24.85 days. Values bigger than that will lead to waiting until an event occurs.
pollfd structure
The pollfd structure is declared in <sys.poll.h> as follows:
struct pollfd { int fd; /* socket file descriptor to poll*/ short events; /* events on interest on fd*/ short revents; /* events that occured on fd */ };
The fd socket descriptor designates the socket to be tested.
events designates the events to be tested on this socket.
revents returns the test result. The POLLNVAL, POLLERR, POLLHUP bits are always set in revents, if the conditions for this are met, regardless of the bits set in events.
Events can be requested in the events element field using the following bit masks:
POLLIN
POLLOUT
The following bit masks are not supported in the events element field and are not set in the revents element field:
POLLPRI
POLLRDNORM
POLLWRNORM
POLLRDBAND
POLLWRBAND
The following events can be displayed in the bit mask of the revents element field:
POLLIN
With an existing connection data can be read non-blocking.
POLLOUT
With an existing connection data can be written non-blocking.
POLLNVAL
The socket selected with the socket descriptor is not available or it does not have the status that displays an active connection. This flag is only written as a result in the revents field.
POLLERR
An error has been reported to the socket selected and the connection is inactive. This flag is only written as a result in the revents field.
POLLHUP
The application or the transport system have closed the connection.
This flag is only written as a result in the revents field.
If a negative value is specified for an fd socket descriptor, this value will be ignored and the revents field will be set to 0.
Return value
0:
The time specified in the timeout parameter has elapsed without an event display being set.
>0
The positive value indicates the number of socket descriptors when at least one event display has been set in the revents field.
-1
If errors occur. errno is set to indicate the error.
Errors
EACCES
The socket function is not supported by the called subsystem.
EINTR
The soc_poll() call was interrupted by soc_wake().
EINVAL
The value of nfds is greater than the maximum number permitted of socket descriptors. The maximum value is determined by calling getdtablesize().
See also
select()