Check for I/O events on file descriptors for a set of open streams.
CS_INT srv_poll(fdsp, nfds, waitflag)
SRV_POLLFD *fdsp; CS_INT nfds; CS_INT waitflag;
A pointer to an array of SRV_POLLFD structures with one element for each open file descriptor of interest. The SRV_POLLFD structure has the following members:
CS_INT srv_fd; /* File descriptor. */
CS_INT srv_events; /* Relevant events. */
CS_INT srv_revents; /* Returned events. */
The number of elements in the *fdsp array.
A CS_INT value that indicates whether the thread should be suspended until a file descriptor is available for the desired operation. If set to SRV_M_WAIT, the thread is suspended and will wake when any file descriptor represented in the *fdsp array is available for the specified operation. If the flag is set to SRV_M_NOWAIT, srv_poll will perform a single check and return to the caller. A return status greater than zero indicates that a file descriptor was available for the desired operation.
Returns |
To indicate |
---|---|
An integer |
The number of &ready file descriptors. |
-1 |
The routine failed. |
0 |
No file descriptors are &ready. |
#include <ospublic.h>
/*
** Local Prototype
*/
CS_RETCODE ex_srv_pollPROTOTYPE((
struct pollfd *fdp,
CS_INT nfds
));
/*
** EX_SRV_POLL
**
** This routine demonstrates how to use srv_poll to poll
** application-specific file descriptors.
**
** Arguments:
** fdp - The address of the file descriptor array.
** nfds - The number of file descriptors to poll.
**
** Returns
**
** CS_SUCCEED If the data address is returned.
** CS_FAIL If the call to srv_poll failed.
**
*/
CS_RETCODE ex_srv_poll(fdp, nfds)
struct pollfd *fdp;
CS_INT nfds;
{
/*
** Initialization.
*/
lp = (CS_VOID *)NULL;
/*
** Calls srv_poll to check if any of these file
** descriptors are active; ask to sleep until at
** least one of them is.
*/
if( srv_poll(fdp, nfds, SRV_M_WAIT) == (CS_INT)-1 )
{
return CS_FAIL;
}
/*
** All done.
*/
return CS_SUCCEED;
}
An application can use srv_poll to poll the file descriptor or to suspend a thread until there is I/O to be performed.
The following table summarizes legal values for srv_events and srv_revents:
Value |
Description |
---|---|
SRV_POLLIN |
Normal read event. |
SRV_POLLPRI |
Priority event received. |
SRV_POLLOUT |
File descriptor is writable. |
SRV_POLLERR |
Error occurred on file descriptor. |
SRV_POLLHUP |
A hang up occurred on the file descriptor. This value is valid in returned events only. |
SRV_POLLNVAL |
Invalid file descriptor specified in SRV_POLLFD. |
srv_poll is available on all UNIX platforms.
If an application uses srv_poll on
a UNIX platform that supports the native poll(2) system
call, the application must include <sys/poll.h>
before ospublic.h.