^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) .. c:namespace:: MC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) .. _request-func-poll:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) **************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) request poll()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) **************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) request-poll - Wait for some event on a file descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) Synopsis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .. code-block:: c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sys/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ``ufds``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) List of file descriptor events to be watched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ``nfds``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Number of file descriptor events at the \*ufds array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ``timeout``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Timeout to wait for events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) With the :c:func:`poll()` function applications can wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) for a request to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) On success :c:func:`poll()` returns the number of file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) descriptors that have been selected (that is, file descriptors for which the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ``revents`` field of the respective struct :c:type:`pollfd`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) is non-zero). Request file descriptor set the ``POLLPRI`` flag in ``revents``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) when the request was completed. When the function times out it returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) a value of zero, on failure it returns -1 and the ``errno`` variable is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) set appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) Attempting to poll for a request that is not yet queued will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) set the ``POLLERR`` flag in ``revents``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) Return Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) On success, :c:func:`poll()` returns the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) structures which have non-zero ``revents`` fields, or zero if the call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) timed out. On error -1 is returned, and the ``errno`` variable is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) appropriately:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ``EBADF``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) One or more of the ``ufds`` members specify an invalid file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ``EFAULT``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ``ufds`` references an inaccessible memory area.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ``EINTR``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) The call was interrupted by a signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ``EINVAL``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ``getrlimit()`` to obtain this value.