Commit | Line | Data |
---|---|---|
5377d91f MH |
1 | .. -*- coding: utf-8; mode: rst -*- |
2 | ||
3 | .. _func-select: | |
4 | ||
5 | ************* | |
6 | V4L2 select() | |
7 | ************* | |
8 | ||
15e7d615 | 9 | Name |
586027ce | 10 | ==== |
5377d91f | 11 | |
586027ce | 12 | v4l2-select - Synchronous I/O multiplexing |
5377d91f | 13 | |
15e7d615 MCC |
14 | |
15 | Synopsis | |
5377d91f MH |
16 | ======== |
17 | ||
18 | .. code-block:: c | |
19 | ||
20 | #include <sys/time.h> | |
21 | #include <sys/types.h> | |
22 | #include <unistd.h> | |
23 | ||
24 | ||
1b81f010 | 25 | .. c:function:: int select( int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout ) |
41d80465 | 26 | :name: v4l2-select |
586027ce | 27 | |
15e7d615 | 28 | Arguments |
586027ce MCC |
29 | ========= |
30 | ||
41d80465 MCC |
31 | ``nfds`` |
32 | The highest-numbered file descriptor in any of the three sets, plus 1. | |
33 | ||
34 | ``readfds`` | |
35 | File descriptions to be watched if a read() call won't block. | |
36 | ||
37 | ``writefds`` | |
38 | File descriptions to be watched if a write() won't block. | |
39 | ||
40 | ``exceptfds`` | |
41 | File descriptions to be watched for V4L2 events. | |
42 | ||
43 | ``timeout`` | |
44 | Maximum time to wait. | |
586027ce MCC |
45 | |
46 | ||
15e7d615 | 47 | Description |
5377d91f MH |
48 | =========== |
49 | ||
760c7010 | 50 | With the :ref:`select() <func-select>` function applications can suspend |
5377d91f MH |
51 | execution until the driver has captured data or is ready to accept data |
52 | for output. | |
53 | ||
54 | When streaming I/O has been negotiated this function waits until a | |
55 | buffer has been filled or displayed and can be dequeued with the | |
af4a4d0d | 56 | :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. When buffers are already in |
5377d91f MH |
57 | the outgoing queue of the driver the function returns immediately. |
58 | ||
760c7010 | 59 | On success :ref:`select() <func-select>` returns the total number of bits set in |
acf309a2 | 60 | :c:func:`struct fd_set`. When the function timed out it returns |
5377d91f MH |
61 | a value of zero. On failure it returns -1 and the ``errno`` variable is |
62 | set appropriately. When the application did not call | |
7347081e | 63 | :ref:`VIDIOC_QBUF` or |
760c7010 | 64 | :ref:`VIDIOC_STREAMON` yet the :ref:`select() <func-select>` |
5377d91f | 65 | function succeeds, setting the bit of the file descriptor in ``readfds`` |
af4a4d0d | 66 | or ``writefds``, but subsequent :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` |
4855307b | 67 | calls will fail. [#f1]_ |
5377d91f | 68 | |
760c7010 MCC |
69 | When use of the :ref:`read() <func-read>` function has been negotiated and the |
70 | driver does not capture yet, the :ref:`select() <func-select>` function starts | |
71 | capturing. When that fails, :ref:`select() <func-select>` returns successful and | |
72 | a subsequent :ref:`read() <func-read>` call, which also attempts to start | |
5377d91f MH |
73 | capturing, will return an appropriate error code. When the driver |
74 | captures continuously (as opposed to, for example, still images) and | |
760c7010 | 75 | data is already available the :ref:`select() <func-select>` function returns |
5377d91f MH |
76 | immediately. |
77 | ||
760c7010 MCC |
78 | When use of the :ref:`write() <func-write>` function has been negotiated the |
79 | :ref:`select() <func-select>` function just waits until the driver is ready for a | |
80 | non-blocking :ref:`write() <func-write>` call. | |
5377d91f | 81 | |
760c7010 MCC |
82 | All drivers implementing the :ref:`read() <func-read>` or :ref:`write() <func-write>` |
83 | function or streaming I/O must also support the :ref:`select() <func-select>` | |
5377d91f MH |
84 | function. |
85 | ||
760c7010 | 86 | For more details see the :ref:`select() <func-select>` manual page. |
5377d91f MH |
87 | |
88 | ||
15e7d615 | 89 | Return Value |
5377d91f MH |
90 | ============ |
91 | ||
760c7010 | 92 | On success, :ref:`select() <func-select>` returns the number of descriptors |
5377d91f MH |
93 | contained in the three returned descriptor sets, which will be zero if |
94 | the timeout expired. On error -1 is returned, and the ``errno`` variable | |
95 | is set appropriately; the sets and ``timeout`` are undefined. Possible | |
96 | error codes are: | |
97 | ||
98 | EBADF | |
99 | One or more of the file descriptor sets specified a file descriptor | |
100 | that is not open. | |
101 | ||
102 | EBUSY | |
103 | The driver does not support multiple read or write streams and the | |
104 | device is already in use. | |
105 | ||
106 | EFAULT | |
107 | The ``readfds``, ``writefds``, ``exceptfds`` or ``timeout`` pointer | |
108 | references an inaccessible memory area. | |
109 | ||
110 | EINTR | |
111 | The call was interrupted by a signal. | |
112 | ||
113 | EINVAL | |
114 | The ``nfds`` argument is less than zero or greater than | |
115 | ``FD_SETSIZE``. | |
116 | ||
4855307b | 117 | .. [#f1] |
760c7010 MCC |
118 | The Linux kernel implements :ref:`select() <func-select>` like the |
119 | :ref:`poll() <func-poll>` function, but :ref:`select() <func-select>` cannot | |
5377d91f | 120 | return a ``POLLERR``. |