1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*4882a593Smuzhiyun.. c:namespace:: V4L 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun.. _func-poll: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun*********** 7*4882a593SmuzhiyunV4L2 poll() 8*4882a593Smuzhiyun*********** 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunName 11*4882a593Smuzhiyun==== 12*4882a593Smuzhiyun 13*4882a593Smuzhiyunv4l2-poll - Wait for some event on a file descriptor 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunSynopsis 16*4882a593Smuzhiyun======== 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun.. code-block:: c 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun #include <sys/poll.h> 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout ) 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunArguments 25*4882a593Smuzhiyun========= 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunDescription 29*4882a593Smuzhiyun=========== 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunWith the :c:func:`poll()` function applications can suspend execution 32*4882a593Smuzhiyununtil the driver has captured data or is ready to accept data for 33*4882a593Smuzhiyunoutput. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunWhen streaming I/O has been negotiated this function waits until a 36*4882a593Smuzhiyunbuffer has been filled by the capture device and can be dequeued with 37*4882a593Smuzhiyunthe :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. For output devices this 38*4882a593Smuzhiyunfunction waits until the device is ready to accept a new buffer to be 39*4882a593Smuzhiyunqueued up with the :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` ioctl for 40*4882a593Smuzhiyundisplay. When buffers are already in the outgoing queue of the driver 41*4882a593Smuzhiyun(capture) or the incoming queue isn't full (display) the function 42*4882a593Smuzhiyunreturns immediately. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunOn success :c:func:`poll()` returns the number of file descriptors 45*4882a593Smuzhiyunthat have been selected (that is, file descriptors for which the 46*4882a593Smuzhiyun``revents`` field of the respective ``struct pollfd`` structure 47*4882a593Smuzhiyunis non-zero). Capture devices set the ``POLLIN`` and ``POLLRDNORM`` 48*4882a593Smuzhiyunflags in the ``revents`` field, output devices the ``POLLOUT`` and 49*4882a593Smuzhiyun``POLLWRNORM`` flags. When the function timed out it returns a value of 50*4882a593Smuzhiyunzero, on failure it returns -1 and the ``errno`` variable is set 51*4882a593Smuzhiyunappropriately. When the application did not call 52*4882a593Smuzhiyun:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` the :c:func:`poll()` 53*4882a593Smuzhiyunfunction succeeds, but sets the ``POLLERR`` flag in the ``revents`` 54*4882a593Smuzhiyunfield. When the application has called 55*4882a593Smuzhiyun:ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` for a capture device but 56*4882a593Smuzhiyunhasn't yet called :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`, the 57*4882a593Smuzhiyun:c:func:`poll()` function succeeds and sets the ``POLLERR`` flag in 58*4882a593Smuzhiyunthe ``revents`` field. For output devices this same situation will cause 59*4882a593Smuzhiyun:c:func:`poll()` to succeed as well, but it sets the ``POLLOUT`` and 60*4882a593Smuzhiyun``POLLWRNORM`` flags in the ``revents`` field. 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunIf an event occurred (see :ref:`VIDIOC_DQEVENT`) 63*4882a593Smuzhiyunthen ``POLLPRI`` will be set in the ``revents`` field and 64*4882a593Smuzhiyun:c:func:`poll()` will return. 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunWhen use of the :c:func:`read()` function has been negotiated and the 67*4882a593Smuzhiyundriver does not capture yet, the :c:func:`poll()` function starts 68*4882a593Smuzhiyuncapturing. When that fails it returns a ``POLLERR`` as above. Otherwise 69*4882a593Smuzhiyunit waits until data has been captured and can be read. When the driver 70*4882a593Smuzhiyuncaptures continuously (as opposed to, for example, still images) the 71*4882a593Smuzhiyunfunction may return immediately. 72*4882a593Smuzhiyun 73*4882a593SmuzhiyunWhen use of the :c:func:`write()` function has been negotiated and the 74*4882a593Smuzhiyundriver does not stream yet, the :c:func:`poll()` function starts 75*4882a593Smuzhiyunstreaming. When that fails it returns a ``POLLERR`` as above. Otherwise 76*4882a593Smuzhiyunit waits until the driver is ready for a non-blocking 77*4882a593Smuzhiyun:c:func:`write()` call. 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunIf the caller is only interested in events (just ``POLLPRI`` is set in 80*4882a593Smuzhiyunthe ``events`` field), then :c:func:`poll()` will *not* start 81*4882a593Smuzhiyunstreaming if the driver does not stream yet. This makes it possible to 82*4882a593Smuzhiyunjust poll for events and not for buffers. 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunAll drivers implementing the :c:func:`read()` or :c:func:`write()` 85*4882a593Smuzhiyunfunction or streaming I/O must also support the :c:func:`poll()` 86*4882a593Smuzhiyunfunction. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunFor more details see the :c:func:`poll()` manual page. 89*4882a593Smuzhiyun 90*4882a593SmuzhiyunReturn Value 91*4882a593Smuzhiyun============ 92*4882a593Smuzhiyun 93*4882a593SmuzhiyunOn success, :c:func:`poll()` returns the number structures which have 94*4882a593Smuzhiyunnon-zero ``revents`` fields, or zero if the call timed out. On error -1 95*4882a593Smuzhiyunis returned, and the ``errno`` variable is set appropriately: 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunEBADF 98*4882a593Smuzhiyun One or more of the ``ufds`` members specify an invalid file 99*4882a593Smuzhiyun descriptor. 100*4882a593Smuzhiyun 101*4882a593SmuzhiyunEBUSY 102*4882a593Smuzhiyun The driver does not support multiple read or write streams and the 103*4882a593Smuzhiyun device is already in use. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunEFAULT 106*4882a593Smuzhiyun ``ufds`` references an inaccessible memory area. 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunEINTR 109*4882a593Smuzhiyun The call was interrupted by a signal. 110*4882a593Smuzhiyun 111*4882a593SmuzhiyunEINVAL 112*4882a593Smuzhiyun The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use 113*4882a593Smuzhiyun ``getrlimit()`` to obtain this value. 114