Rechercher une page de manuel
poll
Langue: ja
Version: 2006-03-13 (openSuse - 09/10/07)
Section: 2 (Appels système)
̾Á°
poll, ppoll - ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë¤ª¤±¤ë¥¤¥Ù¥ó¥È¤òÂԤĽñ¼°
#include <poll.h> int poll(struct pollfd *fds, nfds_t nfds, int timeout); #define _GNU_SOURCE #include <poll.h> int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask);
ÀâÌÀ
poll() ¤Ï select(2) ¤ÈƱÍͤλŻö¤ò¹Ô¤¦¡¢¤Ä¤Þ¤ê¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿½¸¹ç¤Î¤¤¤º¤ì¤«°ì¤Ä¤¬ I/O ¤ò¼Â¹Ô²Äǽ¤Ê¾õÂ֤ˤʤë¤Î¤òÂԤġ£´Æ»ë¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿½¸¹ç¤Ï¡¢ fds °ú¤¿ô¤Ç»ØÄꤹ¤ë¡£ fds ¤Ï¡¢°Ê²¼¤Î·¿¤Î¹½Â¤ÂΤΠnfds ¸Ä¤ÎÇÛÎó¤Ç¤¢¤ë¡£
struct pollfd { int fd; /* file descriptor */ short events; /* requested events */ short revents; /* returned events */ };¹½Â¤ÂΤΠfd ¤Ë¤Ï¥ª¡¼¥×¥ó¤·¤¿¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÆþ¤ì¤ë¡£
¹½Â¤ÂΤΠevents Í×ÁǤÏÆþÎϥѥé¥á¡¼¥¿¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¶½Ì£¤ò»ý¤Ã¤Æ¤¤¤ë¥¤¥Ù¥ó¥È¤Î ¥Ó¥Ã¥È¥Þ¥¹¥¯¤ò»ØÄꤹ¤ë¡£
revents Í×ÁǤϽÐÎϥѥé¥á¡¼¥¿¤Ç¡¢¼ÂºÝ¤Ëµ¯¤³¤Ã¤¿¥¤¥Ù¥ó¥È¤¬¥«¡¼¥Í¥ë¤Ë¤è¤êÀßÄꤵ¤ì¤ë¡£ revents ¤ÇÊÖ¤µ¤ì¤ë¥Ó¥Ã¥ÈÎó¤Ë¤Ï¡¢ events ¤Ç»ØÄꤷ¤¿¤â¤Î¤Î¤É¤ì¤«¡¢¤â¤·¤¯¤Ï POLLERR, POLLHUP, POLLNVAL ¤Î¤¦¤Á¤Î°ì¤Ä¤¬´Þ¤Þ¤ì¤ë (POLLERR, POLLHUP, POLLNVAL ¤Î 3¤Ä¤Î¥Ó¥Ã¥È¤Ï events ¤Ë»ØÄꤷ¤Æ¤â°ÕÌ£¤¬¤Ê¤¯¡¢Âбþ¤·¤¿¾õÂÖ¤¬¿¿¤Î¾ì¹ç¤Ë revents ¤ËÀßÄꤵ¤ì¤ë)¡£
¤É¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë¤âÍ׵ᤷ¤¿¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤Æ¤ª¤é¤º¡¢ ¥¨¥é¡¼¤âµ¯¤³¤é¤Ê¤¤¾ì¹ç¡¢ poll() ¤Ï¥¤¥Ù¥ó¥È¤Î¤¦¤Á¤¤¤º¤ì¤«°ì¤Ä¤¬È¯À¸¤¹¤ë¤Þ¤ÇÄä»ß (block) ¤¹¤ë¡£
timeout °ú¤¿ô¤Ï poll() ¤¬Ää»ß¤¹¤ë»þ´Ö¤Î¾å¸Â¤òÀßÄꤹ¤ë¤â¤Î¤Ç¡¢¥ß¥êÉÃñ°Ì¤Ç»ØÄꤹ¤ë¡£ timeout ¤ËÉé¤ÎÃͤò»ØÄꤹ¤ë¤È¡¢¥¿¥¤¥à¥¢¥¦¥È»þ´Ö¤¬Ìµ¸Â¤È¤Ê¤ë¡£
events ¤Ë»ØÄꤷ¤¿¤ê¡¢ revents ¤ÇÊÖ¤µ¤ì¤ë¥Ó¥Ã¥È¤Ï <poll.h> ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
-
- POLLIN
- Æɤ߽Ф·²Äǽ¤Ê¥Ç¡¼¥¿¤¬¤¢¤ë¡£
- POLLPRI
- Æɤ߽Ф·²Äǽ¤Ê¶ÛµÞ¥Ç¡¼¥¿ (urgent data) ¤¬¤¢¤ë (Î㤨¤Ð¡¢TCP ¥½¥±¥Ã¥È¤ÎÂÓ°è³° (out-of-band data) ¥Ç¡¼¥¿¤ò¼õ¿®¤·¤¿¾ì¹ç¤ä¡¢ ¥Ñ¥±¥Ã¥È¥â¡¼¥É¤Îµ¼»÷üËö¤Î¥Þ¥¹¥¿¤¬¥¹¥ì¡¼¥Ö¦¤ÎÊѲ½¤ò¸«¤Ä¤±¤¿¤È¤)¡£
- POLLOUT
- ½ñ¤¹þ¤ß¤¬Ää»ß (block) ¤·¤Ê¤¤¾õÂ֤Ǥ¢¤ë¡£
- POLLRDHUP (Linux 2.6.17 °Ê¹ß)
- ¥¹¥È¥ê¡¼¥à¥½¥±¥Ã¥È¤Î¾ü¤¬¡¢¥³¥Í¥¯¥·¥ç¥ó¤ò close ¤·¤¿¤«¡¢ ¥³¥Í¥¯¥·¥ç¥ó¤Î½ñ¤¹þ¤ß¦¤ò shutdown ¤·¤¿¡£ ¤³¤ÎÄêµÁ¤ò͸ú¤Ë¤¹¤ë¤Ë¤Ï¡¢ _GNU_SOURCE µ¡Ç½¸¡ºº¥Þ¥¯¥í¤òÄêµÁ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
- POLLERR
- ¥¨¥é¡¼¾õÂÖ (½ÐÎϤξì¹ç¤Î¤ß)¡£
- POLLHUP
- ¥Ï¥ó¥°¥¢¥Ã¥×¤·¤¿ (½ÐÎϤξì¹ç¤Î¤ß)¡£
- POLLNVAL
- ÉÔÀµ¤ÊÍ×µá: fd ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤Ê¤¤ (½ÐÎϤξì¹ç¤Î¤ß)¡£
_XOPEN_SOURCE ¤òÄêµÁ¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤¿¾ì¹ç¤Ë¤Ï¡¢°Ê²¼¤ÎÄêµÁ¤â¹Ô¤ï¤ì¤ë¡£ ¤¿¤À¤·¡¢¾åµ¤Î¥ê¥¹¥È¤Ë¤¢¤ë¥Ó¥Ã¥È°Ê¾å¤Î¾ðÊó¤¬ÆÀ¤é¤ì¤ëÌõ¤Ç¤Ï¤Ê¤¤¡£
-
- POLLRDNORM
- POLLIN ¤ÈƱ¤¸¡£
- POLLRDBAND
- Í¥ÀèÂÓ°è¥Ç¡¼¥¿ (priority band data) ¤¬Æɤ߽Ф·²Äǽ¤Ç¤¢¤ë (ÉáÄÌ¤Ï Linux ¤Ç¤Ï»ÈÍѤµ¤ì¤Ê¤¤)¡£
- POLLWRNORM
- POLLOUT ¤ÈƱ¤¸¡£
- POLLWRBAND
- Í¥ÀèÂÓ°è¥Ç¡¼¥¿ (priority data) ¤¬½ñ¤¹þ¤ß²Äǽ¤Ç¤¢¤ë¡£
Linux ¤Ç¤Ï POLLMSG ¤âÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤¬¡¢»ÈÍѤµ¤ì¤Æ¤¤¤Ê¤¤¡£
ppoll()
poll() ¤È ppoll() ¤Î´Ø·¸¤Ï select(2) ¤È pselect(2) ¤Î´Ø·¸¤ÈƱ¤¸¤è¤¦¤Ê¤â¤Î¤Ç¤¢¤ë: pselect(2) ¤ÈƱÍͤˡ¢ ppoll() ¤ò»È¤¦¤È¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¾õÂÖÊѲ½ ¤â¤·¤¯¤Ï¥·¥°¥Ê¥ë¤ÎÊ᪤ò°ÂÁ´¤ËÂԤĤ³¤È¤¬¤Ç¤¤ë¡£timeout °ú¤¿ô¤Î°ã¤¤¤ò½ü¤¯¤È¡¢°Ê²¼¤Î ppoll() ¤Î¸Æ¤Ó½Ð¤·¤Ï¡¢
ready = ppoll(&fds, nfds, timeout, &sigmask);¼¡¤Î¥³¡¼¥ë¤ò atomic ¤Ë¼Â¹Ô¤¹¤ë¤Î¤ÈÅù²Á¤Ç¤¢¤ë¡£
sigset_t origmask; sigprocmask(SIG_SETMASK, &sigmask, &origmask); ready = poll(&fds, nfds, timeout); sigprocmask(SIG_SETMASK, &origmask, NULL);
¤Ê¤¼ ppoll() ¤¬É¬ÍפʤΤ«¤Ë¤Ä¤¤¤Æ¤ÎÀâÌÀ¤Ï pselect(2) ¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
timeout °ú¤¿ô¤Ï ppoll() ¤¬Ää»ß¤¹¤ë»þ´Ö¤Î¾å¸Â¤ò»ØÄꤹ¤ë¤â¤Î¤Ç¤¢¤ë¡£ ¤³¤Î°ú¤¿ô¤Ë¤Ï°Ê²¼¤Î·¿¤Î¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤ò»ØÄꤹ¤ë¡£
struct timespec { long tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ };
timeout ¤Ë NULL ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢ ppoll ¤Ï̵¸Â¤ËÄä»ß¤¹¤ë¤³¤È¤¬¤¢¤êÆÀ¤ë¡£
ÊÖ¤êÃÍ
À®¸ù¤·¤¿¾ì¹ç¤ÏÀµ¤Î¿ô¤òÊÖ¤¹¡£¤³¤Î¿ô¤Ï 0 °Ê³°¤Î revents Í×ÁǤò»ý¤Ä¹½Â¤ÂΤοô¤Ç¤¢¤ë (Ê̤θÀ¤¤Êý¤ò¤¹¤ë¤È¡¢¤³¤ì¤é¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿ ¤Ë¤Ï¥¤¥Ù¥ó¥È¤«¥¨¥é¡¼Êó¹ð¤¬¤¢¤ë)¡£ ÃÍ 0 ¤Ï¡¢¥¿¥¤¥à¥¢¥¦¥È¤È¤Ê¤ê¡¢¤É¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤â¥¤¥Ù¥ó¥È¤¬ ȯÀ¸¤·¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï -1 ¤¬ÊÖ¤µ¤ì¡¢ errno ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£¥¨¥é¡¼
- EBADF
- ½¸¹ç¤Î¤É¤ì¤«¤ËÉÔÀµ¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¡£
- EFAULT
- °ú¤¿ô¤È¤·¤Æ»ØÄꤷ¤¿ÇÛÎ󤬡¢¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë ´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¡£
- EINTR
- Í׵ᤵ¤ì¤¿¥¤¥Ù¥ó¥È¤Î¤É¤ì¤«¤¬µ¯¤³¤ëÁ°¤Ë¥·¥°¥Ê¥ë¤¬È¯À¸¤·¤¿¡£
- EINVAL
- nfds ¤ÎÃͤ¬ RLIMIT_NOFILE ¤òĶ¤¨¤¿¡£
- ENOMEM
- ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¦¥Æ¡¼¥Ö¥ë¤ò³ÎÊݤ¹¤ë¤¿¤á¤Î¥á¥â¥ê¤¬¤Ê¤¤¡£
¥Ð¡¼¥¸¥ç¥ó
poll() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 2.1.23 ¤ÇƳÆþ¤µ¤ì¤¿¡£ poll() ¥é¥¤¥Ö¥é¥ê¡¦¥³¡¼¥ë¤Ï libc 5.4.28 ¤«¤éƳÆþ¤µ¤ì¤¿ (¤³¤ì¤Ï¥«¡¼¥Í¥ë¤¬ poll() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë select(2) ¤ò»ÈÍѤ·¤Æ¥¨¥ß¥å¥ì¡¼¥È¤ò¹Ô¤¦)¡£ppoll() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï ¥«¡¼¥Í¥ë 2.6.16 ¤Ç Linux ¤ËÄɲ䵤줿¡£ ppoll() ¥é¥¤¥Ö¥é¥ê¥³¡¼¥ë¤Ï glibc 2.4 ¤ËÄɲ䵤줿¡£
½àµò
poll() ¤Ï POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£ ppoll() ¤Ï Linux ¸ÇͤǤ¢¤ë¡£Ãí°Õ
¤¤¤¯¤Ä¤«¤Î¼ÂÁõ¤Ç¤Ï¡¢ÃÍ -1 ¤ò»ý¤Ã¤¿Èóɸ½à¤ÎÄê¿ô INFTIM ¤¬ÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢ timeout ¤Î»ØÄê¤Ë»ÈÍѤǤ¤ë¡£ ¤³¤ÎÄê¿ô¤Ï glibc ¤Ç¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£Linux ¤Ç¤ÎÃí°Õ
Linux ¤Î ppoll() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï timeout °ú¤¿ô¤òÊѹ¹¤¹¤ë¡£ ¤·¤«¤·¡¢glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï¡¢¥·¥¹¥Æ¥à¥³¡¼¥ë¤ËÅϤ¹ timeout °ú¤¿ô ¤È¤·¤Æ¥í¡¼¥«¥ëÊÑ¿ô¤ò»È¤¦¤³¤È¤Ç¤³¤ÎÆ°ºî¤ò±£Ê䷤Ƥ¤¤ë¡£ ¤³¤Î¤¿¤á¡¢glibc ¤Î ppoll() ´Ø¿ô¤Ï timeout °ú¤¿ô¤òÊѹ¹¤·¤Ê¤¤¡£¥Ð¥°
select(2) ¤Î¡Ö¥Ð¥°¡×¤ÎÀá¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¡¢¸í¤Ã¤¿½àÈ÷´°Î»ÄÌÃÎ (spurious readiness notifications) ¤Ë¤Ä¤¤¤Æ¤ÎµÄÏÀ¤ò»²¾È¤Î¤³¤È¡£´ØÏ¢¹àÌÜ
select(2), select_tut(2), feature_test_macros(7)Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre