blob: 04a96817766cfff31fa2ee7d28fed7f616e1a699 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>V4L2 select()</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Video for Linux Two API Specification"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Function Reference"
HREF="r7624.htm"><LINK
REL="PREVIOUS"
TITLE="V4L2 read()"
HREF="r14264.htm"><LINK
REL="NEXT"
TITLE="V4L2 write()"
HREF="r14496.htm"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Video for Linux Two API Specification: Revision 0.24</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="r14264.htm"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="r14496.htm"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="FUNC-SELECT"
></A
>V4L2 select()</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN14394"
></A
><H2
>Name</H2
>v4l2-select&nbsp;--&nbsp;Synchronous I/O multiplexing</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN14397"
></A
><H2
>Synopsis</H2
><DIV
CLASS="FUNCSYNOPSIS"
><P
></P
><A
NAME="AEN14398"
></A
><PRE
CLASS="FUNCSYNOPSISINFO"
>#include &lt;sys/time.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;</PRE
><P
><CODE
><CODE
CLASS="FUNCDEF"
>int select</CODE
>(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);</CODE
></P
><P
></P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN14413"
></A
><H2
>Description</H2
><P
>With the <CODE
CLASS="FUNCTION"
>select()</CODE
> function applications
can suspend execution until the driver has captured data or is ready
to accept data for output.</P
><P
>When streaming I/O has been negotiated this function waits
until a buffer has been filled or displayed and can be dequeued with
the <A
HREF="r12878.htm"
><CODE
CLASS="CONSTANT"
>VIDIOC_DQBUF</CODE
></A
> ioctl. When buffers are already in the outgoing
queue of the driver the function returns immediately.</P
><P
>On success <CODE
CLASS="FUNCTION"
>select()</CODE
> returns the total
number of bits set in the <CODE
CLASS="STRUCTNAME"
>fd_set</CODE
>s. When the
function timed out it returns a value of zero. On failure it returns
<SPAN
CLASS="RETURNVALUE"
>-1</SPAN
> and the <CODE
CLASS="VARNAME"
>errno</CODE
>
variable is set appropriately. When the application did not call
<A
HREF="r12878.htm"
><CODE
CLASS="CONSTANT"
>VIDIOC_QBUF</CODE
></A
> or <A
HREF="r13817.htm"
><CODE
CLASS="CONSTANT"
>VIDIOC_STREAMON</CODE
></A
> yet the
<CODE
CLASS="FUNCTION"
>select()</CODE
> function succeeds, setting the bit of
the file descriptor in <CODE
CLASS="PARAMETER"
>readfds</CODE
> or
<CODE
CLASS="PARAMETER"
>writefds</CODE
>, but subsequent <A
HREF="r12878.htm"
><CODE
CLASS="CONSTANT"
>VIDIOC_DQBUF</CODE
></A
> calls
will fail.<A
NAME="AEN14434"
HREF="r14390.htm#FTN.AEN14434"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
></P
><P
>When use of the <CODE
CLASS="FUNCTION"
>read()</CODE
> function has
been negotiated and the driver does not capture yet, the
<CODE
CLASS="FUNCTION"
>select()</CODE
> function starts capturing. When that
fails, <CODE
CLASS="FUNCTION"
>select()</CODE
> returns successful and a
subsequent <CODE
CLASS="FUNCTION"
>read()</CODE
> call, which also attempts to
start capturing, will return an appropriate error code. When the
driver captures continuously (as opposed to, for example, still
images) and data is already available the
<CODE
CLASS="FUNCTION"
>select()</CODE
> function returns immediately.</P
><P
>When use of the <CODE
CLASS="FUNCTION"
>write()</CODE
> function has
been negotiated the <CODE
CLASS="FUNCTION"
>select()</CODE
> function just waits
until the driver is ready for a non-blocking
<CODE
CLASS="FUNCTION"
>write()</CODE
> call.</P
><P
>All drivers implementing the <CODE
CLASS="FUNCTION"
>read()</CODE
> or
<CODE
CLASS="FUNCTION"
>write()</CODE
> function or streaming I/O must also
support the <CODE
CLASS="FUNCTION"
>select()</CODE
> function.</P
><P
>For more details see the <CODE
CLASS="FUNCTION"
>select()</CODE
>
manual page.</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN14457"
></A
><H2
>Return Value</H2
><P
>On success, <CODE
CLASS="FUNCTION"
>select()</CODE
> returns the number
of descriptors contained in the three returned descriptor sets, which
will be zero if the timeout expired. On error
<SPAN
CLASS="RETURNVALUE"
>-1</SPAN
> is returned, and the
<CODE
CLASS="VARNAME"
>errno</CODE
> variable is set appropriately; the sets and
<CODE
CLASS="PARAMETER"
>timeout</CODE
> are undefined. Possible error codes
are:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="ERRORCODE"
>EBADF</SPAN
></DT
><DD
><P
>One or more of the file descriptor sets specified a
file descriptor that is not open.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>EBUSY</SPAN
></DT
><DD
><P
>The driver does not support multiple read or write
streams and the device is already in use.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>EFAULT</SPAN
></DT
><DD
><P
>The <CODE
CLASS="PARAMETER"
>readfds</CODE
>,
<CODE
CLASS="PARAMETER"
>writefds</CODE
>, <CODE
CLASS="PARAMETER"
>exceptfds</CODE
> or
<CODE
CLASS="PARAMETER"
>timeout</CODE
> pointer references an inaccessible memory
area.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>EINTR</SPAN
></DT
><DD
><P
>The call was interrupted by a signal.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>EINVAL</SPAN
></DT
><DD
><P
>The <CODE
CLASS="PARAMETER"
>nfds</CODE
> argument is less than
zero or greater than <CODE
CLASS="CONSTANT"
>FD_SETSIZE</CODE
>.</P
></DD
></DL
></DIV
></DIV
><H2
CLASS="FOOTNOTES"
>Notes</H2
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN14434"
HREF="r14390.htm#AEN14434"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>The Linux kernel implements
<CODE
CLASS="FUNCTION"
>select()</CODE
> like the <A
HREF="r14169.htm"
><CODE
CLASS="FUNCTION"
>poll()</CODE
></A
> function, but
<CODE
CLASS="FUNCTION"
>select()</CODE
> cannot return a
<CODE
CLASS="CONSTANT"
>POLLERR</CODE
>.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="r14264.htm"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="r14496.htm"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>V4L2 read()</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="r7624.htm"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>V4L2 write()</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>