1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>V4L2 select()</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 A. Function Reference"><link rel="prev" href="func-read.html" title="V4L2 read()"><link rel="next" href="func-write.html" title="V4L2 write()"></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 select()</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="func-read.html">Prev</a> </td><th width="60%" align="center">Appendix A. Function Reference</th><td width="20%" align="right"> <a accesskey="n" href="func-write.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="func-select"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>v4l2-select — Synchronous I/O multiplexing</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo"> 2#include <sys/time.h> 3#include <sys/types.h> 4#include <unistd.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">select</b>(</code></td><td>int <var class="pdparam">nfds</var>, </td></tr><tr><td> </td><td>fd_set *<var class="pdparam">readfds</var>, </td></tr><tr><td> </td><td>fd_set *<var class="pdparam">writefds</var>, </td></tr><tr><td> </td><td>fd_set *<var class="pdparam">exceptfds</var>, </td></tr><tr><td> </td><td>struct timeval *<var class="pdparam">timeout</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1117222076"></a><h2>Description</h2><p>With the <code class="function">select()</code> function applications 5can suspend execution until the driver has captured data or is ready 6to accept data for output.</p><p>When streaming I/O has been negotiated this function waits 7until a buffer has been filled or displayed and can be dequeued with 8the <a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_DQBUF</code></a> ioctl. When buffers are already in the outgoing 9queue of the driver the function returns immediately.</p><p>On success <code class="function">select()</code> returns the total 10number of bits set in the <span class="structname">fd_set</span>s. When the 11function timed out it returns a value of zero. On failure it returns 12<span class="returnvalue">-1</span> and the <code class="varname">errno</code> 13variable is set appropriately. When the application did not call 14<a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_QBUF</code></a> or <a class="link" href="vidioc-streamon.html" title="ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF"><code class="constant">VIDIOC_STREAMON</code></a> yet the 15<code class="function">select()</code> function succeeds, setting the bit of 16the file descriptor in <em class="parameter"><code>readfds</code></em> or 17<em class="parameter"><code>writefds</code></em>, but subsequent <a class="link" href="vidioc-qbuf.html" title="ioctl VIDIOC_QBUF, VIDIOC_DQBUF"><code class="constant">VIDIOC_DQBUF</code></a> calls 18will fail.<a href="#ftn.idp1117227732" class="footnote" name="idp1117227732"><sup class="footnote">[20]</sup></a></p><p>When use of the <code class="function">read()</code> function has 19been negotiated and the driver does not capture yet, the 20<code class="function">select()</code> function starts capturing. When that 21fails, <code class="function">select()</code> returns successful and a 22subsequent <code class="function">read()</code> call, which also attempts to 23start capturing, will return an appropriate error code. When the 24driver captures continuously (as opposed to, for example, still 25images) and data is already available the 26<code class="function">select()</code> function returns immediately.</p><p>When use of the <code class="function">write()</code> function has 27been negotiated the <code class="function">select()</code> function just waits 28until the driver is ready for a non-blocking 29<code class="function">write()</code> call.</p><p>All drivers implementing the <code class="function">read()</code> or 30<code class="function">write()</code> function or streaming I/O must also 31support the <code class="function">select()</code> function.</p><p>For more details see the <code class="function">select()</code> 32manual page.</p></div><div class="refsect1"><a name="idp1117235300"></a><h2>Return Value</h2><p>On success, <code class="function">select()</code> returns the number 33of descriptors contained in the three returned descriptor sets, which 34will be zero if the timeout expired. On error 35<span class="returnvalue">-1</span> is returned, and the 36<code class="varname">errno</code> variable is set appropriately; the sets and 37<em class="parameter"><code>timeout</code></em> are undefined. Possible error codes 38are:</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 file descriptor sets specified a 39file descriptor that is not open.</p></dd><dt><span class="term"><span class="errorcode">EBUSY</span></span></dt><dd><p>The driver does not support multiple read or write 40streams and the device is already in use.</p></dd><dt><span class="term"><span class="errorcode">EFAULT</span></span></dt><dd><p>The <em class="parameter"><code>readfds</code></em>, 41<em class="parameter"><code>writefds</code></em>, <em class="parameter"><code>exceptfds</code></em> or 42<em class="parameter"><code>timeout</code></em> pointer references an inaccessible memory 43area.</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 less than 44zero or greater than <code class="constant">FD_SETSIZE</code>.</p></dd></dl></div></div><div class="footnotes"><br><hr style="width:100; text-align:left;margin-left: 0"><div id="ftn.idp1117227732" class="footnote"><p><a href="#idp1117227732" class="para"><sup class="para">[20] </sup></a>The Linux kernel implements 45<code class="function">select()</code> like the <a class="link" href="func-poll.html" title="V4L2 poll()"><code class="function">poll()</code></a> function, but 46<code class="function">select()</code> cannot return a 47<code class="constant">POLLERR</code>.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="func-read.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="func-write.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">V4L2 read() </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> V4L2 write()</td></tr></table></div></body></html> 48