srv_poll (UNIX only)

Description

Check for I/O events on file descriptors for a set of open streams.

Syntax

CS_INT srv_poll(fdsp, nfds, waitflag)
SRV_POLLFD         *fdsp;
CS_INT                   nfds;
CS_INT                 waitflag;

Parameters

fdsp

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. */ 
nfds

The number of elements in the *fdsp array.

waitflag

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

Table 3-79: Return values (srv_poll)

Returns

To indicate

An integer

The number of &ready file descriptors.

-1

The routine failed.

0

No file descriptors are &ready.

Examples

Example 1

#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;
}

Usage

NoteIf 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.

See also

srv_capability, srv_select (UNIX only)