2016-06-30 21:18:56 +08:00
|
|
|
.. -*- coding: utf-8; mode: rst -*-
|
|
|
|
|
|
|
|
.. _func-select:
|
|
|
|
|
|
|
|
*************
|
|
|
|
V4L2 select()
|
|
|
|
*************
|
|
|
|
|
2016-07-06 02:14:35 +08:00
|
|
|
Name
|
2016-07-05 18:58:48 +08:00
|
|
|
====
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-05 18:58:48 +08:00
|
|
|
v4l2-select - Synchronous I/O multiplexing
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-06 02:14:35 +08:00
|
|
|
|
|
|
|
Synopsis
|
2016-06-30 21:18:56 +08:00
|
|
|
========
|
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
2016-08-19 23:00:43 +08:00
|
|
|
.. c:function:: int select( int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout )
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-05 18:58:48 +08:00
|
|
|
|
2016-07-06 02:14:35 +08:00
|
|
|
Arguments
|
2016-07-05 18:58:48 +08:00
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-06 02:14:35 +08:00
|
|
|
Description
|
2016-06-30 21:18:56 +08:00
|
|
|
===========
|
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
With the :ref:`select() <func-select>` function applications can suspend
|
2016-06-30 21:18:56 +08:00
|
|
|
execution until the driver has captured data or is ready to accept data
|
|
|
|
for output.
|
|
|
|
|
|
|
|
When streaming I/O has been negotiated this function waits until a
|
|
|
|
buffer has been filled or displayed and can be dequeued with the
|
2016-07-02 00:42:29 +08:00
|
|
|
:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. When buffers are already in
|
2016-06-30 21:18:56 +08:00
|
|
|
the outgoing queue of the driver the function returns immediately.
|
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
On success :ref:`select() <func-select>` returns the total number of bits set in
|
2016-07-04 00:28:28 +08:00
|
|
|
:c:func:`struct fd_set`. When the function timed out it returns
|
2016-06-30 21:18:56 +08:00
|
|
|
a value of zero. On failure it returns -1 and the ``errno`` variable is
|
|
|
|
set appropriately. When the application did not call
|
2016-07-02 00:58:44 +08:00
|
|
|
:ref:`VIDIOC_QBUF` or
|
2016-07-04 23:56:17 +08:00
|
|
|
:ref:`VIDIOC_STREAMON` yet the :ref:`select() <func-select>`
|
2016-06-30 21:18:56 +08:00
|
|
|
function succeeds, setting the bit of the file descriptor in ``readfds``
|
2016-07-02 00:42:29 +08:00
|
|
|
or ``writefds``, but subsequent :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`
|
2016-07-13 02:15:23 +08:00
|
|
|
calls will fail. [#f1]_
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
When use of the :ref:`read() <func-read>` function has been negotiated and the
|
|
|
|
driver does not capture yet, the :ref:`select() <func-select>` function starts
|
|
|
|
capturing. When that fails, :ref:`select() <func-select>` returns successful and
|
|
|
|
a subsequent :ref:`read() <func-read>` call, which also attempts to start
|
2016-06-30 21:18:56 +08:00
|
|
|
capturing, will return an appropriate error code. When the driver
|
|
|
|
captures continuously (as opposed to, for example, still images) and
|
2016-07-04 23:56:17 +08:00
|
|
|
data is already available the :ref:`select() <func-select>` function returns
|
2016-06-30 21:18:56 +08:00
|
|
|
immediately.
|
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
When use of the :ref:`write() <func-write>` function has been negotiated the
|
|
|
|
:ref:`select() <func-select>` function just waits until the driver is ready for a
|
|
|
|
non-blocking :ref:`write() <func-write>` call.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
All drivers implementing the :ref:`read() <func-read>` or :ref:`write() <func-write>`
|
|
|
|
function or streaming I/O must also support the :ref:`select() <func-select>`
|
2016-06-30 21:18:56 +08:00
|
|
|
function.
|
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
For more details see the :ref:`select() <func-select>` manual page.
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
|
2016-07-06 02:14:35 +08:00
|
|
|
Return Value
|
2016-06-30 21:18:56 +08:00
|
|
|
============
|
|
|
|
|
2016-07-04 23:56:17 +08:00
|
|
|
On success, :ref:`select() <func-select>` returns the number of descriptors
|
2016-06-30 21:18:56 +08:00
|
|
|
contained in the three returned descriptor sets, which will be zero if
|
|
|
|
the timeout expired. On error -1 is returned, and the ``errno`` variable
|
|
|
|
is set appropriately; the sets and ``timeout`` are undefined. Possible
|
|
|
|
error codes are:
|
|
|
|
|
|
|
|
EBADF
|
|
|
|
One or more of the file descriptor sets specified a file descriptor
|
|
|
|
that is not open.
|
|
|
|
|
|
|
|
EBUSY
|
|
|
|
The driver does not support multiple read or write streams and the
|
|
|
|
device is already in use.
|
|
|
|
|
|
|
|
EFAULT
|
|
|
|
The ``readfds``, ``writefds``, ``exceptfds`` or ``timeout`` pointer
|
|
|
|
references an inaccessible memory area.
|
|
|
|
|
|
|
|
EINTR
|
|
|
|
The call was interrupted by a signal.
|
|
|
|
|
|
|
|
EINVAL
|
|
|
|
The ``nfds`` argument is less than zero or greater than
|
|
|
|
``FD_SETSIZE``.
|
|
|
|
|
2016-07-13 02:15:23 +08:00
|
|
|
.. [#f1]
|
2016-07-04 23:56:17 +08:00
|
|
|
The Linux kernel implements :ref:`select() <func-select>` like the
|
|
|
|
:ref:`poll() <func-poll>` function, but :ref:`select() <func-select>` cannot
|
2016-06-30 21:18:56 +08:00
|
|
|
return a ``POLLERR``.
|