1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>V4L2 poll()</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="user-func.html" title="Appendix&#160;A.&#160;Function Reference"><link rel="prev" href="func-open.html" title="V4L2 open()"><link rel="next" href="func-read.html" title="V4L2 read()"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">V4L2 poll()</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="func-open.html">Prev</a>&#160;</td><th width="60%" align="center">Appendix&#160;A.&#160;Function Reference</th><td width="20%" align="right">&#160;<a accesskey="n" href="func-read.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="func-poll"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>v4l2-poll &#8212; Wait for some event on a file descriptor</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;sys/poll.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">poll</b>(</code></td><td>struct pollfd *<var class="pdparam">ufds</var>, </td></tr><tr><td>&#160;</td><td>unsigned int <var class="pdparam">nfds</var>, </td></tr><tr><td>&#160;</td><td>int <var class="pdparam">timeout</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1117090324"></a><h2>Description</h2><p>With the <code class="function">poll()</code> function applications
2can suspend execution until the driver has captured data or is ready
3to accept data for output.</p><p>When streaming I/O has been negotiated this function waits
4until a buffer has been filled by the capture device and can be dequeued
5with the <a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_DQBUF</code></a> ioctl. For output devices this function waits
6until the device is ready to accept a new buffer to be queued up with
7the <a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_QBUF</code></a> ioctl for display. When buffers are already in the outgoing
8queue of the driver (capture) or the incoming queue isn't full (display)
9the function returns immediately.</p><p>On success <code class="function">poll()</code> returns the number of
10file descriptors that have been selected (that is, file descriptors
11for which the <em class="structfield"><code>revents</code></em> field of the
12respective <span class="structname">pollfd</span> structure is non-zero).
13Capture devices set the <code class="constant">POLLIN</code> and
14<code class="constant">POLLRDNORM</code> flags in the
15<em class="structfield"><code>revents</code></em> field, output devices the
16<code class="constant">POLLOUT</code> and <code class="constant">POLLWRNORM</code>
17flags. When the function timed out it returns a value of zero, on
18failure it returns <span class="returnvalue">-1</span> and the
19<code class="varname">errno</code> variable is set appropriately. When the
20application did not call <a class="link" href="vidioc-streamon.html" title="ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF"><code class="constant">VIDIOC_STREAMON</code></a> the
21<code class="function">poll()</code> function succeeds, but sets the
22<code class="constant">POLLERR</code> flag in the
23<em class="structfield"><code>revents</code></em> field. When the
24application has called <a class="link" href="vidioc-streamon.html" title="ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF"><code class="constant">VIDIOC_STREAMON</code></a> for a capture device but hasn't
25yet called <a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_QBUF</code></a>, the <code class="function">poll()</code> function
26succeeds and sets the <code class="constant">POLLERR</code> flag in the
27<em class="structfield"><code>revents</code></em> field. For output devices this
28same situation will cause <code class="function">poll()</code> to succeed
29as well, but it sets the <code class="constant">POLLOUT</code> and
30<code class="constant">POLLWRNORM</code> flags in the <em class="structfield"><code>revents</code></em>
31field.</p><p>If an event occurred (see <a class="link" href="vidioc-dqevent.html" title="ioctl VIDIOC_DQEVENT"><code class="constant">VIDIOC_DQEVENT</code></a>) then
32<code class="constant">POLLPRI</code> will be set in the <em class="structfield"><code>revents</code></em>
33field and <code class="function">poll()</code> will return.</p><p>When use of the <code class="function">read()</code> function has
34been negotiated and the driver does not capture yet, the
35<code class="function">poll</code> function starts capturing. When that fails
36it returns a <code class="constant">POLLERR</code> as above. Otherwise it waits
37until data has been captured and can be read. When the driver captures
38continuously (as opposed to, for example, still images) the function
39may return immediately.</p><p>When use of the <code class="function">write()</code> function has
40been negotiated and the driver does not stream yet, the
41<code class="function">poll</code> function starts streaming. When that fails
42it returns a <code class="constant">POLLERR</code> as above. Otherwise it waits
43until the driver is ready for a non-blocking
44<code class="function">write()</code> call.</p><p>If the caller is only interested in events (just
45<code class="constant">POLLPRI</code> is set in the <em class="structfield"><code>events</code></em>
46field), then <code class="function">poll()</code> will <span class="emphasis"><em>not</em></span>
47start streaming if the driver does not stream yet. This makes it
48possible to just poll for events and not for buffers.</p><p>All drivers implementing the <code class="function">read()</code> or
49<code class="function">write()</code> function or streaming I/O must also
50support the <code class="function">poll()</code> function.</p><p>For more details see the
51<code class="function">poll()</code> manual page.</p></div><div class="refsect1"><a name="idp1117107876"></a><h2>Return Value</h2><p>On success, <code class="function">poll()</code> returns the number
52structures which have non-zero <em class="structfield"><code>revents</code></em>
53fields, or zero if the call timed out. On error
54<span class="returnvalue">-1</span> is returned, and the
55<code class="varname">errno</code> variable is set appropriately:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorcode">EBADF</span></span></dt><dd><p>One or more of the <em class="parameter"><code>ufds</code></em> members
56specify an invalid file descriptor.</p></dd><dt><span class="term"><span class="errorcode">EBUSY</span></span></dt><dd><p>The driver does not support multiple read or write
57streams and the device is already in use.</p></dd><dt><span class="term"><span class="errorcode">EFAULT</span></span></dt><dd><p><em class="parameter"><code>ufds</code></em> references an inaccessible
58memory area.</p></dd><dt><span class="term"><span class="errorcode">EINTR</span></span></dt><dd><p>The call was interrupted by a signal.</p></dd><dt><span class="term"><span class="errorcode">EINVAL</span></span></dt><dd><p>The <em class="parameter"><code>nfds</code></em> argument is greater
59than <code class="constant">OPEN_MAX</code>.</p></dd></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="func-open.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="func-read.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">V4L2 open()&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;V4L2 read()</td></tr></table></div></body></html>
60