18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci.. c:namespace:: V4L 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci.. _func-poll: 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci*********** 78c2ecf20Sopenharmony_ciV4L2 poll() 88c2ecf20Sopenharmony_ci*********** 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciName 118c2ecf20Sopenharmony_ci==== 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_civ4l2-poll - Wait for some event on a file descriptor 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciSynopsis 168c2ecf20Sopenharmony_ci======== 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci.. code-block:: c 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci #include <sys/poll.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout ) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciArguments 258c2ecf20Sopenharmony_ci========= 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciDescription 298c2ecf20Sopenharmony_ci=========== 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciWith the :c:func:`poll()` function applications can suspend execution 328c2ecf20Sopenharmony_ciuntil the driver has captured data or is ready to accept data for 338c2ecf20Sopenharmony_cioutput. 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciWhen streaming I/O has been negotiated this function waits until a 368c2ecf20Sopenharmony_cibuffer has been filled by the capture device and can be dequeued with 378c2ecf20Sopenharmony_cithe :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this 388c2ecf20Sopenharmony_cifunction waits until the device is ready to accept a new buffer to be 398c2ecf20Sopenharmony_ciqueued up with the :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` ioctl for 408c2ecf20Sopenharmony_cidisplay. When buffers are already in the outgoing queue of the driver 418c2ecf20Sopenharmony_ci(capture) or the incoming queue isn't full (display) the function 428c2ecf20Sopenharmony_cireturns immediately. 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciOn success :c:func:`poll()` returns the number of file descriptors 458c2ecf20Sopenharmony_cithat have been selected (that is, file descriptors for which the 468c2ecf20Sopenharmony_ci``revents`` field of the respective ``struct pollfd`` structure 478c2ecf20Sopenharmony_ciis non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM`` 488c2ecf20Sopenharmony_ciflags in the ``revents`` field, output devices the ``POLLOUT`` and 498c2ecf20Sopenharmony_ci``POLLWRNORM`` flags. When the function timed out it returns a value of 508c2ecf20Sopenharmony_cizero, on failure it returns -1 and the ``errno`` variable is set 518c2ecf20Sopenharmony_ciappropriately. When the application did not call 528c2ecf20Sopenharmony_ci:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` the :c:func:`poll()` 538c2ecf20Sopenharmony_cifunction succeeds, but sets the ``POLLERR`` flag in the ``revents`` 548c2ecf20Sopenharmony_cifield. When the application has called 558c2ecf20Sopenharmony_ci:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` for a capture device but 568c2ecf20Sopenharmony_cihasn't yet called :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`, the 578c2ecf20Sopenharmony_ci:c:func:`poll()` function succeeds and sets the ``POLLERR`` flag in 588c2ecf20Sopenharmony_cithe ``revents`` field. For output devices this same situation will cause 598c2ecf20Sopenharmony_ci:c:func:`poll()` to succeed as well, but it sets the ``POLLOUT`` and 608c2ecf20Sopenharmony_ci``POLLWRNORM`` flags in the ``revents`` field. 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciIf an event occurred (see :ref:`VIDIOC_DQEVENT`) 638c2ecf20Sopenharmony_cithen ``POLLPRI`` will be set in the ``revents`` field and 648c2ecf20Sopenharmony_ci:c:func:`poll()` will return. 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciWhen use of the :c:func:`read()` function has been negotiated and the 678c2ecf20Sopenharmony_cidriver does not capture yet, the :c:func:`poll()` function starts 688c2ecf20Sopenharmony_cicapturing. When that fails it returns a ``POLLERR`` as above. Otherwise 698c2ecf20Sopenharmony_ciit waits until data has been captured and can be read. When the driver 708c2ecf20Sopenharmony_cicaptures continuously (as opposed to, for example, still images) the 718c2ecf20Sopenharmony_cifunction may return immediately. 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciWhen use of the :c:func:`write()` function has been negotiated and the 748c2ecf20Sopenharmony_cidriver does not stream yet, the :c:func:`poll()` function starts 758c2ecf20Sopenharmony_cistreaming. When that fails it returns a ``POLLERR`` as above. Otherwise 768c2ecf20Sopenharmony_ciit waits until the driver is ready for a non-blocking 778c2ecf20Sopenharmony_ci:c:func:`write()` call. 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciIf the caller is only interested in events (just ``POLLPRI`` is set in 808c2ecf20Sopenharmony_cithe ``events`` field), then :c:func:`poll()` will *not* start 818c2ecf20Sopenharmony_cistreaming if the driver does not stream yet. This makes it possible to 828c2ecf20Sopenharmony_cijust poll for events and not for buffers. 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciAll drivers implementing the :c:func:`read()` or :c:func:`write()` 858c2ecf20Sopenharmony_cifunction or streaming I/O must also support the :c:func:`poll()` 868c2ecf20Sopenharmony_cifunction. 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ciFor more details see the :c:func:`poll()` manual page. 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ciReturn Value 918c2ecf20Sopenharmony_ci============ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciOn success, :c:func:`poll()` returns the number structures which have 948c2ecf20Sopenharmony_cinon-zero ``revents`` fields, or zero if the call timed out. On error -1 958c2ecf20Sopenharmony_ciis returned, and the ``errno`` variable is set appropriately: 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciEBADF 988c2ecf20Sopenharmony_ci One or more of the ``ufds`` members specify an invalid file 998c2ecf20Sopenharmony_ci descriptor. 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciEBUSY 1028c2ecf20Sopenharmony_ci The driver does not support multiple read or write streams and the 1038c2ecf20Sopenharmony_ci device is already in use. 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciEFAULT 1068c2ecf20Sopenharmony_ci ``ufds`` references an inaccessible memory area. 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ciEINTR 1098c2ecf20Sopenharmony_ci The call was interrupted by a signal. 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ciEINVAL 1128c2ecf20Sopenharmony_ci The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use 1138c2ecf20Sopenharmony_ci ``getrlimit()`` to obtain this value. 114