blob: 77fdf33648b35462fe55993c5edb53e4bc11b953 [file] [log] [blame]
Markus Heiser5377d912016-06-30 15:18:56 +02001.. -*- coding: utf-8; mode: rst -*-
2
3.. _func-select:
4
5*************
6V4L2 select()
7*************
8
9*man v4l2-select(2)*
10
11Synchronous I/O multiplexing
12
13
14Synopsis
15========
16
17.. code-block:: c
18
19 #include <sys/time.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22
23
24.. c:function:: int select( int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout )
25
26Description
27===========
28
29With the :c:func:`select()` function applications can suspend
30execution until the driver has captured data or is ready to accept data
31for output.
32
33When streaming I/O has been negotiated this function waits until a
34buffer has been filled or displayed and can be dequeued with the
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030035:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. When buffers are already in
Markus Heiser5377d912016-06-30 15:18:56 +020036the outgoing queue of the driver the function returns immediately.
37
38On success :c:func:`select()` returns the total number of bits set in
39the :c:type:`struct fd_set`s. When the function timed out it returns
40a value of zero. On failure it returns -1 and the ``errno`` variable is
41set appropriately. When the application did not call
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030042:ref:`VIDIOC_QBUF <VIDIOC_QBUF>` or
43:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` yet the :c:func:`select()`
Markus Heiser5377d912016-06-30 15:18:56 +020044function succeeds, setting the bit of the file descriptor in ``readfds``
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030045or ``writefds``, but subsequent :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`
Markus Heiser5377d912016-06-30 15:18:56 +020046calls will fail. [1]_
47
48When use of the :c:func:`read()` function has been negotiated and the
49driver does not capture yet, the :c:func:`select()` function starts
50capturing. When that fails, :c:func:`select()` returns successful and
51a subsequent :c:func:`read()` call, which also attempts to start
52capturing, will return an appropriate error code. When the driver
53captures continuously (as opposed to, for example, still images) and
54data is already available the :c:func:`select()` function returns
55immediately.
56
57When use of the :c:func:`write()` function has been negotiated the
58:c:func:`select()` function just waits until the driver is ready for a
59non-blocking :c:func:`write()` call.
60
61All drivers implementing the :c:func:`read()` or :c:func:`write()`
62function or streaming I/O must also support the :c:func:`select()`
63function.
64
65For more details see the :c:func:`select()` manual page.
66
67
68Return Value
69============
70
71On success, :c:func:`select()` returns the number of descriptors
72contained in the three returned descriptor sets, which will be zero if
73the timeout expired. On error -1 is returned, and the ``errno`` variable
74is set appropriately; the sets and ``timeout`` are undefined. Possible
75error codes are:
76
77EBADF
78 One or more of the file descriptor sets specified a file descriptor
79 that is not open.
80
81EBUSY
82 The driver does not support multiple read or write streams and the
83 device is already in use.
84
85EFAULT
86 The ``readfds``, ``writefds``, ``exceptfds`` or ``timeout`` pointer
87 references an inaccessible memory area.
88
89EINTR
90 The call was interrupted by a signal.
91
92EINVAL
93 The ``nfds`` argument is less than zero or greater than
94 ``FD_SETSIZE``.
95
96.. [1]
97 The Linux kernel implements :c:func:`select()` like the
98 :ref:`poll() <func-poll>` function, but :c:func:`select()` cannot
99 return a ``POLLERR``.
100
101
102.. ------------------------------------------------------------------------------
103.. This file was automatically converted from DocBook-XML with the dbxml
104.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
105.. from the linux kernel, refer to:
106..
107.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
108.. ------------------------------------------------------------------------------