요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
.. c:namespace:: MC
.. _request-func-poll:
**************
request poll()
**************
Name
====
request-poll - Wait for some event on a file descriptor
Synopsis
========
.. code-block:: c
#include <sys/poll.h>
.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
Arguments
=========
``ufds``
List of file descriptor events to be watched
``nfds``
Number of file descriptor events at the \*ufds array
``timeout``
Timeout to wait for events
Description
===========
With the :c:func:`poll()` function applications can wait
for a request to complete.
On success :c:func:`poll()` returns the number of file
descriptors that have been selected (that is, file descriptors for which the
``revents`` field of the respective struct :c:type:`pollfd`
is non-zero). Request file descriptor set the ``POLLPRI`` flag in ``revents``
when the request was completed. When the function times out it returns
a value of zero, on failure it returns -1 and the ``errno`` variable is
set appropriately.
Attempting to poll for a request that is not yet queued will
set the ``POLLERR`` flag in ``revents``.
Return Value
============
On success, :c:func:`poll()` returns the number of
structures which have non-zero ``revents`` fields, or zero if the call
timed out. On error -1 is returned, and the ``errno`` variable is set
appropriately:
``EBADF``
One or more of the ``ufds`` members specify an invalid file
descriptor.
``EFAULT``
``ufds`` references an inaccessible memory area.
``EINTR``
The call was interrupted by a signal.
``EINVAL``
The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use
``getrlimit()`` to obtain this value.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
이름, 선언과 인자
1-35`poll()`은 하나 이상의 file descriptor event를 기다리며 request 완료를 감시하는 데 사용합니다.
#include <sys/poll.h>
int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
감시 배열, 항목 수와 대기 시간을 전달합니다.
.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
.. c:namespace:: MC
.. _request-func-poll:
**************
request poll()
**************
Name
====
request-poll - Wait for some event on a file descriptor
Synopsis
========
.. code-block:: c
#include <sys/poll.h>
.. c:function:: int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
Arguments
=========
``ufds``
List of file descriptor events to be watched
``nfds``
Number of file descriptor events at the \*ufds array
``timeout``
Timeout to wait for events
POLLPRI completion과 POLLERR
36-52성공하면 `poll()`은 해당 `struct pollfd`의 `revents`가 non-zero인 선택된 fd 개수를 반환합니다.
Request가 완료되면 request fd의 `revents`에 `POLLPRI`가 설정됩니다. Timeout이면 0, 실패하면 -1을 반환하고 `errno`를 설정합니다.
아직 queue하지 않은 request를 poll하면 완료를 기다리는 대신 `revents`에 `POLLERR`가 설정됩니다.
Return value와 revents를 함께 해석합니다.
Description
===========
With the :c:func:`poll()` function applications can wait
for a request to complete.
On success :c:func:`poll()` returns the number of file
descriptors that have been selected (that is, file descriptors for which the
``revents`` field of the respective struct :c:type:`pollfd`
is non-zero). Request file descriptor set the ``POLLPRI`` flag in ``revents``
when the request was completed. When the function times out it returns
a value of zero, on failure it returns -1 and the ``errno`` variable is
set appropriately.
Attempting to poll for a request that is not yet queued will
set the ``POLLERR`` flag in ``revents``.
오류 코드
53-73성공 시 non-zero `revents`를 가진 structure 개수를 반환하고 timeout이면 0입니다. System call 오류는 -1과 errno로 보고합니다.
일반 poll argument와 signal 오류입니다.
Return Value
============
On success, :c:func:`poll()` returns the number of
structures which have non-zero ``revents`` fields, or zero if the call
timed out. On error -1 is returned, and the ``errno`` variable is set
appropriately:
``EBADF``
One or more of the ``ufds`` members specify an invalid file
descriptor.
``EFAULT``
``ufds`` references an inaccessible memory area.
``EINTR``
The call was interrupted by a signal.
``EINVAL``
The ``nfds`` value exceeds the ``RLIMIT_NOFILE`` value. Use
``getrlimit()`` to obtain this value.
요약·해설
request-func-poll.rst:1-73완료된 request는 `POLLPRI`, 아직 queue되지 않은 request는 `POLLERR`로 구분합니다. Return value는 event가 설정된 pollfd 개수이며 timeout은 0입니다.