18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: MC
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _request-func-poll:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci**************
78c2ecf20Sopenharmony_cirequest poll()
88c2ecf20Sopenharmony_ci**************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cirequest-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``ufds``
288c2ecf20Sopenharmony_ci   List of file descriptor events to be watched
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci``nfds``
318c2ecf20Sopenharmony_ci   Number of file descriptor events at the \*ufds array
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci``timeout``
348c2ecf20Sopenharmony_ci   Timeout to wait for events
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciDescription
378c2ecf20Sopenharmony_ci===========
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciWith the :c:func:`poll()` function applications can wait
408c2ecf20Sopenharmony_cifor a request to complete.
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciOn success :c:func:`poll()` returns the number of file
438c2ecf20Sopenharmony_cidescriptors that have been selected (that is, file descriptors for which the
448c2ecf20Sopenharmony_ci``revents`` field of the respective struct :c:type:`pollfd`
458c2ecf20Sopenharmony_ciis non-zero). Request file descriptor set the ``POLLPRI`` flag in ``revents``
468c2ecf20Sopenharmony_ciwhen the request was completed.  When the function times out it returns
478c2ecf20Sopenharmony_cia value of zero, on failure it returns -1 and the ``errno`` variable is
488c2ecf20Sopenharmony_ciset appropriately.
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciAttempting to poll for a request that is not yet queued will
518c2ecf20Sopenharmony_ciset the ``POLLERR`` flag in ``revents``.
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciReturn Value
548c2ecf20Sopenharmony_ci============
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciOn success, :c:func:`poll()` returns the number of
578c2ecf20Sopenharmony_cistructures which have non-zero ``revents`` fields, or zero if the call
588c2ecf20Sopenharmony_citimed out. On error -1 is returned, and the ``errno`` variable is set
598c2ecf20Sopenharmony_ciappropriately:
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci``EBADF``
628c2ecf20Sopenharmony_ci    One or more of the ``ufds`` members specify an invalid file
638c2ecf20Sopenharmony_ci    descriptor.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci``EFAULT``
668c2ecf20Sopenharmony_ci    ``ufds`` references an inaccessible memory area.
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci``EINTR``
698c2ecf20Sopenharmony_ci    The call was interrupted by a signal.
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci``EINVAL``
728c2ecf20Sopenharmony_ci    The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use
738c2ecf20Sopenharmony_ci    ``getrlimit()`` to obtain this value.
74