func-poll.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _func-poll:
  4. ***********
  5. V4L2 poll()
  6. ***********
  7. Name
  8. ====
  9. v4l2-poll - Wait for some event on a file descriptor
  10. Synopsis
  11. ========
  12. .. code-block:: c
  13. #include <sys/poll.h>
  14. .. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
  15. Arguments
  16. =========
  17. Description
  18. ===========
  19. With the :c:func:`poll()` function applications can suspend execution
  20. until the driver has captured data or is ready to accept data for
  21. output.
  22. When streaming I/O has been negotiated this function waits until a
  23. buffer has been filled by the capture device and can be dequeued with
  24. the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this
  25. function waits until the device is ready to accept a new buffer to be
  26. queued up with the :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` ioctl for
  27. display. When buffers are already in the outgoing queue of the driver
  28. (capture) or the incoming queue isn't full (display) the function
  29. returns immediately.
  30. On success :c:func:`poll()` returns the number of file descriptors
  31. that have been selected (that is, file descriptors for which the
  32. ``revents`` field of the respective ``struct pollfd`` structure
  33. is non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM``
  34. flags in the ``revents`` field, output devices the ``POLLOUT`` and
  35. ``POLLWRNORM`` flags. When the function timed out it returns a value of
  36. zero, on failure it returns -1 and the ``errno`` variable is set
  37. appropriately. When the application did not call
  38. :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` the :c:func:`poll()`
  39. function succeeds, but sets the ``POLLERR`` flag in the ``revents``
  40. field. When the application has called
  41. :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` for a capture device but
  42. hasn't yet called :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`, the
  43. :c:func:`poll()` function succeeds and sets the ``POLLERR`` flag in
  44. the ``revents`` field. For output devices this same situation will cause
  45. :c:func:`poll()` to succeed as well, but it sets the ``POLLOUT`` and
  46. ``POLLWRNORM`` flags in the ``revents`` field.
  47. If an event occurred (see :ref:`VIDIOC_DQEVENT`)
  48. then ``POLLPRI`` will be set in the ``revents`` field and
  49. :c:func:`poll()` will return.
  50. When use of the :c:func:`read()` function has been negotiated and the
  51. driver does not capture yet, the :c:func:`poll()` function starts
  52. capturing. When that fails it returns a ``POLLERR`` as above. Otherwise
  53. it waits until data has been captured and can be read. When the driver
  54. captures continuously (as opposed to, for example, still images) the
  55. function may return immediately.
  56. When use of the :c:func:`write()` function has been negotiated and the
  57. driver does not stream yet, the :c:func:`poll()` function starts
  58. streaming. When that fails it returns a ``POLLERR`` as above. Otherwise
  59. it waits until the driver is ready for a non-blocking
  60. :c:func:`write()` call.
  61. If the caller is only interested in events (just ``POLLPRI`` is set in
  62. the ``events`` field), then :c:func:`poll()` will *not* start
  63. streaming if the driver does not stream yet. This makes it possible to
  64. just poll for events and not for buffers.
  65. All drivers implementing the :c:func:`read()` or :c:func:`write()`
  66. function or streaming I/O must also support the :c:func:`poll()`
  67. function.
  68. For more details see the :c:func:`poll()` manual page.
  69. Return Value
  70. ============
  71. On success, :c:func:`poll()` returns the number structures which have
  72. non-zero ``revents`` fields, or zero if the call timed out. On error -1
  73. is returned, and the ``errno`` variable is set appropriately:
  74. EBADF
  75. One or more of the ``ufds`` members specify an invalid file
  76. descriptor.
  77. EBUSY
  78. The driver does not support multiple read or write streams and the
  79. device is already in use.
  80. EFAULT
  81. ``ufds`` references an inaccessible memory area.
  82. EINTR
  83. The call was interrupted by a signal.
  84. EINVAL
  85. The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use
  86. ``getrlimit()`` to obtain this value.