func-select.rst 3.6 KB

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