Detects when I/O is ready for a set of socket file descriptors.
Syntax
#include <prio.h> PRInt32 PR_Poll( PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout);
Parameters
The function has the following parameters:
- pds
- A pointer to the first element of an array of PRPollDescstructures.
- npds
- The number of elements in the pdsarray. If this parameter is zero,PR_Pollis equivalent toPR_Sleepwith a timeout.
- timeout
- Amount of time the call will block waiting for I/O to become ready. If this time expires without any I/O becoming ready, PR_Pollreturns zero.
Returns
The function returns one of these values:
- If successful, the function returns a positive number indicating the number of PRPollDescstructures inpdsthat have events.
- The value 0 indicates the function timed out.
- The value -1 indicates the function failed. The reason for the failure can be obtained by calling PR_GetError.
Description
This function returns as soon as I/O is ready on one or more of the underlying socket objects. A count of the number of ready descriptors is returned unless a timeout occurs, in which case zero is returned.
The in_flags field of the PRPollDesc data structure should be set to the I/O events (readable, writable, exception, or some combination) that the caller is interested in. On successful return, the out_flags field of the PRPollDesc data structure is set to indicate what kind of I/O is ready on the respective descriptor. PR_Poll uses the out_flags fields as scratch variables during the call. If PR_Poll returns 0 or -1, the out_flags fields do not contain meaningful values and must not be used.
The PRPollDesc structure is defined as follows:
struct PRPollDesc {
  PRFileDesc* fd;
  PRInt16 in_flags;
  PRInt16 out_flags;
};
typedef struct PRPollDesc PRPollDesc;
The structure has the following fields:
- fd
- A pointer to a PRFileDescobject representing a socket or a pollable event. This field can be set toNULLto indicate toPR_Pollthat thisPRFileDesc objectshould be ignored.On Unix, thefdfield can be set to a pointer to anyPRFileDescobject, including one representing a file or a pipe. Cross-platform applications should only set thefdfield to a pointer to aPRFileDescobject representing a socket or a pollable event because on Windows theselectfunction can only be used with sockets.
- in_flags
- A bitwise ORof the following bit flags:
- PR_POLL_READ:- fdis readable.
- PR_POLL_WRITE:- fdis writable.
- PR_POLL_EXCEPT:- fdhas an exception condition.
- out_flags
- A bitwise ORof the following bit flags:
- PR_POLL_READ
- PR_POLL_WRITE
- PR_POLL_EXCEPT
- PR_POLL_ERR:- fdhas an error.
- PR_POLL_NVAL:- fdis bad.
- Note that the PR_POLL_ERRandPR_POLL_NVALflags are used only inout_flags. ThePR_POLL_ERRandPR_POLL_NVALevents are always reported byPR_Poll.