162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _func-poll: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci*********** 762306a36Sopenharmony_ciV4L2 poll() 862306a36Sopenharmony_ci*********** 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_civ4l2-poll - Wait for some event on a file descriptor 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. code-block:: c 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci #include <sys/poll.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout ) 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciArguments 2562306a36Sopenharmony_ci========= 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciDescription 2962306a36Sopenharmony_ci=========== 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciWith the :c:func:`poll()` function applications can suspend execution 3262306a36Sopenharmony_ciuntil the driver has captured data or is ready to accept data for 3362306a36Sopenharmony_cioutput. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciWhen streaming I/O has been negotiated this function waits until a 3662306a36Sopenharmony_cibuffer has been filled by the capture device and can be dequeued with 3762306a36Sopenharmony_cithe :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this 3862306a36Sopenharmony_cifunction waits until the device is ready to accept a new buffer to be 3962306a36Sopenharmony_ciqueued up with the :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` ioctl for 4062306a36Sopenharmony_cidisplay. When buffers are already in the outgoing queue of the driver 4162306a36Sopenharmony_ci(capture) or the incoming queue isn't full (display) the function 4262306a36Sopenharmony_cireturns immediately. 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciOn success :c:func:`poll()` returns the number of file descriptors 4562306a36Sopenharmony_cithat have been selected (that is, file descriptors for which the 4662306a36Sopenharmony_ci``revents`` field of the respective ``struct pollfd`` structure 4762306a36Sopenharmony_ciis non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM`` 4862306a36Sopenharmony_ciflags in the ``revents`` field, output devices the ``POLLOUT`` and 4962306a36Sopenharmony_ci``POLLWRNORM`` flags. When the function timed out it returns a value of 5062306a36Sopenharmony_cizero, on failure it returns -1 and the ``errno`` variable is set 5162306a36Sopenharmony_ciappropriately. When the application did not call 5262306a36Sopenharmony_ci:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` the :c:func:`poll()` 5362306a36Sopenharmony_cifunction succeeds, but sets the ``POLLERR`` flag in the ``revents`` 5462306a36Sopenharmony_cifield. When the application has called 5562306a36Sopenharmony_ci:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` for a capture device but 5662306a36Sopenharmony_cihasn't yet called :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`, the 5762306a36Sopenharmony_ci:c:func:`poll()` function succeeds and sets the ``POLLERR`` flag in 5862306a36Sopenharmony_cithe ``revents`` field. For output devices this same situation will cause 5962306a36Sopenharmony_ci:c:func:`poll()` to succeed as well, but it sets the ``POLLOUT`` and 6062306a36Sopenharmony_ci``POLLWRNORM`` flags in the ``revents`` field. 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciIf an event occurred (see :ref:`VIDIOC_DQEVENT`) 6362306a36Sopenharmony_cithen ``POLLPRI`` will be set in the ``revents`` field and 6462306a36Sopenharmony_ci:c:func:`poll()` will return. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciWhen use of the :c:func:`read()` function has been negotiated and the 6762306a36Sopenharmony_cidriver does not capture yet, the :c:func:`poll()` function starts 6862306a36Sopenharmony_cicapturing. When that fails it returns a ``POLLERR`` as above. Otherwise 6962306a36Sopenharmony_ciit waits until data has been captured and can be read. When the driver 7062306a36Sopenharmony_cicaptures continuously (as opposed to, for example, still images) the 7162306a36Sopenharmony_cifunction may return immediately. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciWhen use of the :c:func:`write()` function has been negotiated and the 7462306a36Sopenharmony_cidriver does not stream yet, the :c:func:`poll()` function starts 7562306a36Sopenharmony_cistreaming. When that fails it returns a ``POLLERR`` as above. Otherwise 7662306a36Sopenharmony_ciit waits until the driver is ready for a non-blocking 7762306a36Sopenharmony_ci:c:func:`write()` call. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciIf the caller is only interested in events (just ``POLLPRI`` is set in 8062306a36Sopenharmony_cithe ``events`` field), then :c:func:`poll()` will *not* start 8162306a36Sopenharmony_cistreaming if the driver does not stream yet. This makes it possible to 8262306a36Sopenharmony_cijust poll for events and not for buffers. 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciAll drivers implementing the :c:func:`read()` or :c:func:`write()` 8562306a36Sopenharmony_cifunction or streaming I/O must also support the :c:func:`poll()` 8662306a36Sopenharmony_cifunction. 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciFor more details see the :c:func:`poll()` manual page. 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ciReturn Value 9162306a36Sopenharmony_ci============ 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciOn success, :c:func:`poll()` returns the number structures which have 9462306a36Sopenharmony_cinon-zero ``revents`` fields, or zero if the call timed out. On error -1 9562306a36Sopenharmony_ciis returned, and the ``errno`` variable is set appropriately: 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciEBADF 9862306a36Sopenharmony_ci One or more of the ``ufds`` members specify an invalid file 9962306a36Sopenharmony_ci descriptor. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciEBUSY 10262306a36Sopenharmony_ci The driver does not support multiple read or write streams and the 10362306a36Sopenharmony_ci device is already in use. 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciEFAULT 10662306a36Sopenharmony_ci ``ufds`` references an inaccessible memory area. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciEINTR 10962306a36Sopenharmony_ci The call was interrupted by a signal. 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ciEINVAL 11262306a36Sopenharmony_ci The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use 11362306a36Sopenharmony_ci ``getrlimit()`` to obtain this value. 114