Path: blob/master/Documentation/DocBook/v4l/func-select.xml
10821 views
<refentry id="func-select">1<refmeta>2<refentrytitle>V4L2 select()</refentrytitle>3&manvol;4</refmeta>56<refnamediv>7<refname>v4l2-select</refname>8<refpurpose>Synchronous I/O multiplexing</refpurpose>9</refnamediv>1011<refsynopsisdiv>12<funcsynopsis>13<funcsynopsisinfo>14#include <sys/time.h>15#include <sys/types.h>16#include <unistd.h></funcsynopsisinfo>17<funcprototype>18<funcdef>int <function>select</function></funcdef>19<paramdef>int <parameter>nfds</parameter></paramdef>20<paramdef>fd_set *<parameter>readfds</parameter></paramdef>21<paramdef>fd_set *<parameter>writefds</parameter></paramdef>22<paramdef>fd_set *<parameter>exceptfds</parameter></paramdef>23<paramdef>struct timeval *<parameter>timeout</parameter></paramdef>24</funcprototype>25</funcsynopsis>26</refsynopsisdiv>2728<refsect1>29<title>Description</title>3031<para>With the <function>select()</function> function applications32can suspend execution until the driver has captured data or is ready33to accept data for output.</para>3435<para>When streaming I/O has been negotiated this function waits36until a buffer has been filled or displayed and can be dequeued with37the &VIDIOC-DQBUF; ioctl. When buffers are already in the outgoing38queue of the driver the function returns immediately.</para>3940<para>On success <function>select()</function> returns the total41number of bits set in the <structname>fd_set</structname>s. When the42function timed out it returns a value of zero. On failure it returns43<returnvalue>-1</returnvalue> and the <varname>errno</varname>44variable is set appropriately. When the application did not call45&VIDIOC-QBUF; or &VIDIOC-STREAMON; yet the46<function>select()</function> function succeeds, setting the bit of47the file descriptor in <parameter>readfds</parameter> or48<parameter>writefds</parameter>, but subsequent &VIDIOC-DQBUF; calls49will fail.<footnote><para>The Linux kernel implements50<function>select()</function> like the &func-poll; function, but51<function>select()</function> cannot return a52<constant>POLLERR</constant>.</para>53</footnote></para>5455<para>When use of the <function>read()</function> function has56been negotiated and the driver does not capture yet, the57<function>select()</function> function starts capturing. When that58fails, <function>select()</function> returns successful and a59subsequent <function>read()</function> call, which also attempts to60start capturing, will return an appropriate error code. When the61driver captures continuously (as opposed to, for example, still62images) and data is already available the63<function>select()</function> function returns immediately.</para>6465<para>When use of the <function>write()</function> function has66been negotiated the <function>select()</function> function just waits67until the driver is ready for a non-blocking68<function>write()</function> call.</para>6970<para>All drivers implementing the <function>read()</function> or71<function>write()</function> function or streaming I/O must also72support the <function>select()</function> function.</para>7374<para>For more details see the <function>select()</function>75manual page.</para>7677</refsect1>7879<refsect1>80<title>Return Value</title>8182<para>On success, <function>select()</function> returns the number83of descriptors contained in the three returned descriptor sets, which84will be zero if the timeout expired. On error85<returnvalue>-1</returnvalue> is returned, and the86<varname>errno</varname> variable is set appropriately; the sets and87<parameter>timeout</parameter> are undefined. Possible error codes88are:</para>8990<variablelist>91<varlistentry>92<term><errorcode>EBADF</errorcode></term>93<listitem>94<para>One or more of the file descriptor sets specified a95file descriptor that is not open.</para>96</listitem>97</varlistentry>98<varlistentry>99<term><errorcode>EBUSY</errorcode></term>100<listitem>101<para>The driver does not support multiple read or write102streams and the device is already in use.</para>103</listitem>104</varlistentry>105<varlistentry>106<term><errorcode>EFAULT</errorcode></term>107<listitem>108<para>The <parameter>readfds</parameter>,109<parameter>writefds</parameter>, <parameter>exceptfds</parameter> or110<parameter>timeout</parameter> pointer references an inaccessible memory111area.</para>112</listitem>113</varlistentry>114<varlistentry>115<term><errorcode>EINTR</errorcode></term>116<listitem>117<para>The call was interrupted by a signal.</para>118</listitem>119</varlistentry>120<varlistentry>121<term><errorcode>EINVAL</errorcode></term>122<listitem>123<para>The <parameter>nfds</parameter> argument is less than124zero or greater than <constant>FD_SETSIZE</constant>.</para>125</listitem>126</varlistentry>127</variablelist>128</refsect1>129</refentry>130131<!--132Local Variables:133mode: sgml134sgml-parent-document: "v4l2.sgml"135indent-tabs-mode: nil136End:137-->138139140