424 lines
12 KiB
HTML
424 lines
12 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
||
|
<title>poll()--Wait for Events on Multiple Descriptors</title>
|
||
|
<!-- Begin Header Records ========================================== -->
|
||
|
<!-- Unix8 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
||
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
||
|
<!-- Change History: -->
|
||
|
<!-- 020319 JTROUS Changes for Virus scanner, 98860, V5R3 -->
|
||
|
<!-- 020618 EMIG: updated for NFS threadsafety, V5R3 -->
|
||
|
<!-- 020718 MFENLON: updated for QFileSvr.400 threadsafety, V5R3 -->
|
||
|
<!-- 030812 JTROUS Fix discussion on what will happen for scan, V5R3 -->
|
||
|
<!-- 040720 TIMCLARK Remove non-threadsafe file system usage note; -->
|
||
|
<!-- see PTR9A74361, v5r4 -->
|
||
|
<!-- (C) Copyright IBM Corporation, 2005 -->
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<!--End Header Records --><!-- Edited by Kersten Feb 02 -->
|
||
|
<!-- Java sync-link -->
|
||
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
||
|
</script>
|
||
|
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
|
||
|
<h2><img src="delta.gif" alt="Start of change">
|
||
|
poll()--Wait for Events on Multiple Descriptors</h2>
|
||
|
|
||
|
<div class="box" style="width: 60%;">
|
||
|
<br>
|
||
|
Syntax<br>
|
||
|
<pre>
|
||
|
#include <sys/poll.h>
|
||
|
|
||
|
int poll(struct pollfd <em>fds[]</em>,
|
||
|
nfds_t <em>nfds</em>,
|
||
|
int <em>timeout</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV1<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Conditional; see <a href="#USAGE_NOTES">Usage Notes</a>.<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<p>The <em>poll()</em> function is used to enable an application to multiplex
|
||
|
I/O over a set of descriptors. For each member of the array pointed to
|
||
|
by <em>fds,
|
||
|
</em> <em>poll()</em> will examine the given descriptor for
|
||
|
the event(s) specified. <em>nfds</em> is
|
||
|
the number of <strong>pollfd</strong> structures in the <em>fds</em> array.
|
||
|
The <em>poll()</em> function will determine which descriptors can
|
||
|
read or write data, or whether certain events have occured on the
|
||
|
descriptors within the <em>timeout</em> period.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Parameters</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong>fds</strong></dt>
|
||
|
<dd>
|
||
|
<br>
|
||
|
|
||
|
(Input) Specifies an array of descriptors to be examined and the events of
|
||
|
interest for each descriptor.
|
||
|
|
||
|
<pre>
|
||
|
struct pollfd {
|
||
|
int fd; /* Descriptor */
|
||
|
short events; /* Requested events */
|
||
|
short revents; /* Returned events */
|
||
|
};
|
||
|
</pre>
|
||
|
|
||
|
The array's members are <strong>pollfd</strong> structures within which
|
||
|
<em>fd</em> specifies an open descriptor. The <em>events</em> and
|
||
|
<em>revents</em> are bitmasks constructed by OR'ing a combination of the
|
||
|
following event flags.<br>
|
||
|
|
||
|
<br>
|
||
|
The following events can be specified in the <em>events</em> field:
|
||
|
<table cellpadding="5">
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLIN</samp></em></td>
|
||
|
<td align="left" valign="top">Data may be read without blocking.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLPRI</samp></em></td>
|
||
|
<td align="left" valign="top">High-priority(OOB) data may be read without blocking.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLOUT</samp></em></td>
|
||
|
<td align="left" valign="top">Data may be written without blocking.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLWRNORM</samp></em></td>
|
||
|
<td align="left" valign="top">Equivalent to POLLOUT.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLRDNORM</samp></em></td>
|
||
|
<td align="left" valign="top">Equivalent to POLLIN.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLNORM</samp></em></td>
|
||
|
<td align="left" valign="top">Equivalent to POLLIN.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
<br>
|
||
|
|
||
|
Each of the <em>events</em> listed above may be returned in the <em>revents</em> field
|
||
|
when the <em>poll()</em> API completes if that requested condition is valid for the
|
||
|
specified descriptor. In addition to these events, the following event may also be
|
||
|
returned in the <em>revents</em> field:
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLNVAL</samp></em></td>
|
||
|
<td align="left" valign="top">The specified <em>fd</em> value is invalid. This
|
||
|
flag is ignored if it is specified in the <em>events</em> field.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
The following events will never be returned in the <em>revents</em> field on the iSeries:
|
||
|
<table cellpadding="5">
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLRDBAND</samp></em></td>
|
||
|
<td align="left" valign="top">Priority message ready to read.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLWRBAND</samp></em></td>
|
||
|
<td align="left" valign="top">Writable priority band exists.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLERR</samp></em></td>
|
||
|
<td align="left" valign="top">An error occurred.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em><samp>POLLHUP</samp></em></td>
|
||
|
<td align="left" valign="top">Connection disconnected.</td>
|
||
|
</tr>
|
||
|
|
||
|
</table>
|
||
|
<br>
|
||
|
In each <strong>pollfd</strong> structure,
|
||
|
<em>poll()</em> will clear the <em>revents</em> member, except that where
|
||
|
the application requested a report on a condition by setting one of the
|
||
|
bits of <em>events</em>, <em>poll()</em> will set the corresponding
|
||
|
bit in <em>revents</em> if the requested condition is true. In addition,
|
||
|
<em>poll()</em> shall set the POLLNVAL flag in <em>revents</em> if the
|
||
|
condition is true, even if the application did not set the corresponding
|
||
|
bit in events.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>nfds</strong></dt>
|
||
|
|
||
|
<dd>(Input) <em>nfds</em> is the number of <strong>pollfd</strong> structures
|
||
|
in the <em>fds</em> array.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>timeout</strong></dt>
|
||
|
|
||
|
<dd>(Input) The <em>timeout</em> argument specifies how long <em>poll()</em>
|
||
|
is to wait before returning. If none of the requested events have occurred on
|
||
|
any of the descriptors, <em>poll()</em> will wait at least
|
||
|
<em>timeout</em> milliseconds for an event to occur on any of the
|
||
|
descriptors. If the value of <em>timeout</em> is 0, <em>poll()</em> will return
|
||
|
immediately. If the value of <em>timeout</em> is -1, <em>poll()</em> will block
|
||
|
until a requested event occurs or until the call is interrupted.
|
||
|
<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Authorities</h3>
|
||
|
|
||
|
<p>No authorization is required.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Return Value</h3>
|
||
|
|
||
|
<p><em>poll()</em> returns an integer. Possible values are:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>-1 (unsuccessful)<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>0 (the <em>timeout</em> expired before any of the requested <em>events</em> were
|
||
|
satisfied)<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>n (total number of descriptors that met poll criteria)</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<h3>Error Conditions</h3>
|
||
|
|
||
|
<p>When <em>poll()</em> fails, <em>errno</em> can be set to one of the
|
||
|
following:</p>
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EINVAL]</em></td>
|
||
|
<td align="left" valign="top">The <em>timeout</em> argument was less than -1.
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ENOTSAFE]</em></td>
|
||
|
<td align="left" valign="top">Function not allowed.
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EINTR]</em></td>
|
||
|
<td align="left" valign="top">A signal was caught during the <em>poll()</em>.
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EFAULT]</em></td>
|
||
|
<td align="left" valign="top">The address used for an argument was not valid.
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EUNKNOWN]</em></td>
|
||
|
<td align="left" valign="top">Unknown system state.
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[ENOTSUP]</em></td>
|
||
|
<td align="left" valign="top">Operation not supported.
|
||
|
<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
<h3>Error Messages</h3>
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPE3418 E</td>
|
||
|
<td align="left" valign="top">Possible APAR condition or hardware failure.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPF9872 E</td>
|
||
|
<td align="left" valign="top">Program or service program &1 in library
|
||
|
&2 ended. Reason code &3.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPFA081 E</td>
|
||
|
<td align="left" valign="top">Unable to set return value or error code.</td>
|
||
|
</tr>
|
||
|
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
|
||
|
|
||
|
<ol>
|
||
|
<li>When specifying the POLLIN flag for <em>events</em>,
|
||
|
the following can be indicated:
|
||
|
|
||
|
<ul>
|
||
|
<li>Data is available to be read<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>An error event exists on the descriptor.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>
|
||
|
A socket descriptor that is listening for connections will indicate that
|
||
|
it is ready for reading, once connections are available.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>No data can be read from the underlying instance represented by the
|
||
|
descriptor. For example, a socket descriptor for which a <em>shutdown()</em>
|
||
|
call has been done to disable the reception of data.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>When specifying the POLLOUT flag for <em>events</em>,
|
||
|
the following can be indicated:
|
||
|
|
||
|
<ul>
|
||
|
|
||
|
<li>When a <em>write()</em> can be successfully issued without blocking (or,
|
||
|
for nonblocking, so it does not return <samp>[EWOULDBLOCK]</samp>).<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>Completion of a non-blocking <em>connect()</em> call on a socket
|
||
|
descriptor. This allows an application to set a socket descriptor to
|
||
|
nonblocking (with <em>fcntl()</em> or <em>ioctl()</em>), issue a
|
||
|
<em>connect()</em> and receive <samp>[EINPROGRESS]</samp>, and then use
|
||
|
<em>poll()</em> to verify that the connection has completed.<br>
|
||
|
<br>
|
||
|
|
||
|
</li>
|
||
|
<li>No data can be written to the underlying instance represented by the
|
||
|
descriptor (for example, a socket descriptor for which a <em>shutdown()</em>
|
||
|
has been done to disable the sending of data).<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>If the <em>revents</em> field is set to POLLPRI
|
||
|
when the <em>poll()</em> API completes, this indicates that out-of-band data
|
||
|
has arrived on the descriptor specified by the <em>fd</em> field.
|
||
|
This is only supported for connection-oriented sockets with an address
|
||
|
family of <samp>AF_INET</samp> or <samp>AF_INET6</samp>.
|
||
|
<br>
|
||
|
<br></li>
|
||
|
|
||
|
<li>The <em>poll()</em> API will not be affected by the O_NONBLOCK flag.
|
||
|
|
||
|
<br>
|
||
|
<br></li>
|
||
|
|
||
|
<li>The <em>poll()</em> API is more efficient than the <em>select()</em> API and
|
||
|
therefore <em>poll()</em> is always recommended over <em>select()</em>.
|
||
|
<br>
|
||
|
<br></li>
|
||
|
|
||
|
<li>The timeout mechanism is different between <em>poll()</em> and <em>select()</em>.
|
||
|
The <em>poll()</em> API uses an integer with the unit of measure as milliseconds.
|
||
|
The <em>select()</em> API uses a timeval structure.
|
||
|
<br>
|
||
|
<br></li>
|
||
|
|
||
|
<li>
|
||
|
Unpredictable results will appear if
|
||
|
this function or any of its associated type and macro definitions are used
|
||
|
in a thread executing one of the scan-related exit programs
|
||
|
(or any of its' created threads). See
|
||
|
<a href="ifsopenexit.htm">Integrated File System Scan on Open Exit Programs</a> and
|
||
|
<a href="ifscloseexit.htm">Integrated File System Scan on Close Exit Programs</a>
|
||
|
for more information.
|
||
|
<br>
|
||
|
<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
</ol>
|
||
|
|
||
|
<h3>Related Information</h3>
|
||
|
|
||
|
<ul>
|
||
|
<li><a href="sselect.htm">select()</a>--Wait for events on Multiple
|
||
|
Sockets</li>
|
||
|
</ul>
|
||
|
|
||
|
<img src="deltaend.gif" alt="End of change">
|
||
|
<br>
|
||
|
<hr>
|
||
|
<br>
|
||
|
API introduced: V5R4
|
||
|
|
||
|
<hr>
|
||
|
<center>
|
||
|
<table cellpadding="2" cellspacing="2">
|
||
|
<tr align="center">
|
||
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> |
|
||
|
<a href="unix.htm">UNIX-Type APIs</a> |
|
||
|
<a href="aplist.htm">APIs by category</a> </td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</center>
|
||
|
</body>
|
||
|
</html>
|
||
|
|