1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L 354f38fcaSMauro Carvalho Chehab 454f38fcaSMauro Carvalho Chehab.. _func-poll: 554f38fcaSMauro Carvalho Chehab 654f38fcaSMauro Carvalho Chehab*********** 754f38fcaSMauro Carvalho ChehabV4L2 poll() 854f38fcaSMauro Carvalho Chehab*********** 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho ChehabName 1154f38fcaSMauro Carvalho Chehab==== 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho Chehabv4l2-poll - Wait for some event on a file descriptor 1454f38fcaSMauro Carvalho Chehab 1554f38fcaSMauro Carvalho ChehabSynopsis 1654f38fcaSMauro Carvalho Chehab======== 1754f38fcaSMauro Carvalho Chehab 1854f38fcaSMauro Carvalho Chehab.. code-block:: c 1954f38fcaSMauro Carvalho Chehab 2054f38fcaSMauro Carvalho Chehab #include <sys/poll.h> 2154f38fcaSMauro Carvalho Chehab 2254f38fcaSMauro Carvalho Chehab.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout ) 2354f38fcaSMauro Carvalho Chehab 2454f38fcaSMauro Carvalho ChehabArguments 2554f38fcaSMauro Carvalho Chehab========= 2654f38fcaSMauro Carvalho Chehab 2754f38fcaSMauro Carvalho Chehab 2854f38fcaSMauro Carvalho ChehabDescription 2954f38fcaSMauro Carvalho Chehab=========== 3054f38fcaSMauro Carvalho Chehab 31*407e84cdSMauro Carvalho ChehabWith the :c:func:`poll()` function applications can suspend execution 3254f38fcaSMauro Carvalho Chehabuntil the driver has captured data or is ready to accept data for 3354f38fcaSMauro Carvalho Chehaboutput. 3454f38fcaSMauro Carvalho Chehab 3554f38fcaSMauro Carvalho ChehabWhen streaming I/O has been negotiated this function waits until a 3654f38fcaSMauro Carvalho Chehabbuffer has been filled by the capture device and can be dequeued with 3754f38fcaSMauro Carvalho Chehabthe :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this 3854f38fcaSMauro Carvalho Chehabfunction waits until the device is ready to accept a new buffer to be 3954f38fcaSMauro Carvalho Chehabqueued up with the :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` ioctl for 4054f38fcaSMauro Carvalho Chehabdisplay. When buffers are already in the outgoing queue of the driver 4154f38fcaSMauro Carvalho Chehab(capture) or the incoming queue isn't full (display) the function 4254f38fcaSMauro Carvalho Chehabreturns immediately. 4354f38fcaSMauro Carvalho Chehab 44*407e84cdSMauro Carvalho ChehabOn success :c:func:`poll()` returns the number of file descriptors 4554f38fcaSMauro Carvalho Chehabthat have been selected (that is, file descriptors for which the 46*407e84cdSMauro Carvalho Chehab``revents`` field of the respective ``struct pollfd`` structure 4754f38fcaSMauro Carvalho Chehabis non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM`` 4854f38fcaSMauro Carvalho Chehabflags in the ``revents`` field, output devices the ``POLLOUT`` and 4954f38fcaSMauro Carvalho Chehab``POLLWRNORM`` flags. When the function timed out it returns a value of 5054f38fcaSMauro Carvalho Chehabzero, on failure it returns -1 and the ``errno`` variable is set 5154f38fcaSMauro Carvalho Chehabappropriately. When the application did not call 52*407e84cdSMauro Carvalho Chehab:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` the :c:func:`poll()` 5354f38fcaSMauro Carvalho Chehabfunction succeeds, but sets the ``POLLERR`` flag in the ``revents`` 5454f38fcaSMauro Carvalho Chehabfield. When the application has called 5554f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` for a capture device but 5654f38fcaSMauro Carvalho Chehabhasn't yet called :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`, the 57*407e84cdSMauro Carvalho Chehab:c:func:`poll()` function succeeds and sets the ``POLLERR`` flag in 5854f38fcaSMauro Carvalho Chehabthe ``revents`` field. For output devices this same situation will cause 59*407e84cdSMauro Carvalho Chehab:c:func:`poll()` to succeed as well, but it sets the ``POLLOUT`` and 6054f38fcaSMauro Carvalho Chehab``POLLWRNORM`` flags in the ``revents`` field. 6154f38fcaSMauro Carvalho Chehab 6254f38fcaSMauro Carvalho ChehabIf an event occurred (see :ref:`VIDIOC_DQEVENT`) 6354f38fcaSMauro Carvalho Chehabthen ``POLLPRI`` will be set in the ``revents`` field and 64*407e84cdSMauro Carvalho Chehab:c:func:`poll()` will return. 6554f38fcaSMauro Carvalho Chehab 66*407e84cdSMauro Carvalho ChehabWhen use of the :c:func:`read()` function has been negotiated and the 67*407e84cdSMauro Carvalho Chehabdriver does not capture yet, the :c:func:`poll()` function starts 6854f38fcaSMauro Carvalho Chehabcapturing. When that fails it returns a ``POLLERR`` as above. Otherwise 6954f38fcaSMauro Carvalho Chehabit waits until data has been captured and can be read. When the driver 7054f38fcaSMauro Carvalho Chehabcaptures continuously (as opposed to, for example, still images) the 7154f38fcaSMauro Carvalho Chehabfunction may return immediately. 7254f38fcaSMauro Carvalho Chehab 73*407e84cdSMauro Carvalho ChehabWhen use of the :c:func:`write()` function has been negotiated and the 74*407e84cdSMauro Carvalho Chehabdriver does not stream yet, the :c:func:`poll()` function starts 7554f38fcaSMauro Carvalho Chehabstreaming. When that fails it returns a ``POLLERR`` as above. Otherwise 7654f38fcaSMauro Carvalho Chehabit waits until the driver is ready for a non-blocking 77*407e84cdSMauro Carvalho Chehab:c:func:`write()` call. 7854f38fcaSMauro Carvalho Chehab 7954f38fcaSMauro Carvalho ChehabIf the caller is only interested in events (just ``POLLPRI`` is set in 80*407e84cdSMauro Carvalho Chehabthe ``events`` field), then :c:func:`poll()` will *not* start 8154f38fcaSMauro Carvalho Chehabstreaming if the driver does not stream yet. This makes it possible to 8254f38fcaSMauro Carvalho Chehabjust poll for events and not for buffers. 8354f38fcaSMauro Carvalho Chehab 84*407e84cdSMauro Carvalho ChehabAll drivers implementing the :c:func:`read()` or :c:func:`write()` 85*407e84cdSMauro Carvalho Chehabfunction or streaming I/O must also support the :c:func:`poll()` 8654f38fcaSMauro Carvalho Chehabfunction. 8754f38fcaSMauro Carvalho Chehab 88*407e84cdSMauro Carvalho ChehabFor more details see the :c:func:`poll()` manual page. 8954f38fcaSMauro Carvalho Chehab 9054f38fcaSMauro Carvalho ChehabReturn Value 9154f38fcaSMauro Carvalho Chehab============ 9254f38fcaSMauro Carvalho Chehab 93*407e84cdSMauro Carvalho ChehabOn success, :c:func:`poll()` returns the number structures which have 9454f38fcaSMauro Carvalho Chehabnon-zero ``revents`` fields, or zero if the call timed out. On error -1 9554f38fcaSMauro Carvalho Chehabis returned, and the ``errno`` variable is set appropriately: 9654f38fcaSMauro Carvalho Chehab 9754f38fcaSMauro Carvalho ChehabEBADF 9854f38fcaSMauro Carvalho Chehab One or more of the ``ufds`` members specify an invalid file 9954f38fcaSMauro Carvalho Chehab descriptor. 10054f38fcaSMauro Carvalho Chehab 10154f38fcaSMauro Carvalho ChehabEBUSY 10254f38fcaSMauro Carvalho Chehab The driver does not support multiple read or write streams and the 10354f38fcaSMauro Carvalho Chehab device is already in use. 10454f38fcaSMauro Carvalho Chehab 10554f38fcaSMauro Carvalho ChehabEFAULT 10654f38fcaSMauro Carvalho Chehab ``ufds`` references an inaccessible memory area. 10754f38fcaSMauro Carvalho Chehab 10854f38fcaSMauro Carvalho ChehabEINTR 10954f38fcaSMauro Carvalho Chehab The call was interrupted by a signal. 11054f38fcaSMauro Carvalho Chehab 11154f38fcaSMauro Carvalho ChehabEINVAL 11254f38fcaSMauro Carvalho Chehab The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use 11354f38fcaSMauro Carvalho Chehab ``getrlimit()`` to obtain this value. 114