epoll_wait

EPOLL_WAIT(2)              Linux Programmer's Manual             EPOLL_WAIT(2)



åå
       epoll_wait, epoll_pwait - epoll ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã® I/O ã¤ãã³ããå¾ã¤

æ¸å¼
       #include <sys/epoll.h>

       int epoll_wait(int epfd, struct epoll_event *events,
                      int maxevents, int timeout);
       int epoll_pwait(int epfd, struct epoll_event *events,
                      int maxevents, int timeout,
                      const sigset_t *sigmask);

説æ
       epoll_wait() ã·ã¹ãã ã³ã¼ã«ã¯ããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ epfd ã§åç§ããã epoll(7)
       ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ããã¤ãã³ããå¾ã¤ã events ãæãã¡ã¢ãªé åã«ã¯ã
       å¼ã³åºãå´ãå©ç¨å¯è½ãªã¤ãã³ããæ ¼ç´ããããæ大 maxevents åã®ã¤ãã³ãã
       epoll_wait() ã«ãã£ã¦è¿ãããã maxevents å¼ãæ°ã¯ 0 ãã大ãããªããã°ãªããªãã

       timeout å¼ãæ°ã¯ã epoll_wait() ãåæ¢ããæå°æéãããªç§ã§æå® ãã (ãã®åæ‐
       ¢æéã¯ã·ã¹ãã ã¯ããã¯ã®ç²åº¦ã«åãä¸ããããã«ã¼ãã«ã®
       ã¹ã±ã¸ã¥ã¼ãªã³ã°é延ã«ããå°ãã ãé·ããªãå¯è½æ§ããã)ã timeout ã -1 ã«æå®ããã¨ã
       epoll_wait() ã¯ç¡éã«åæ¢ããã timeout ã 0 ã«æå®ããã¨ã epoll_wait()
       ã¯å©ç¨å¯è½ãªã¤ãã³ãã ãªãã¦ããããã«è¿ãã

       struct epoll_event ã¯ä»¥ä¸ã®ããã«å®ç¾©ããã:

           typedef union epoll_data {
               void    *ptr;
               int      fd;
               uint32_t u32;
               uint64_t u64;
           } epoll_data_t;

           struct epoll_event {
               uint32_t     events;    /* epoll ã¤ãã³ã */
               epoll_data_t data;      /* ã¦ã¼ã¶ãã¼ã¿å¤æ° */
           };

       è¿ãããæ§é ä½ã® data ã¡ã³ãã«ã¯ãã¦ã¼ã¶ã epoll_ctl(2)  (EPOLL_CTL_ADD,
       EPOLL_CTL_MOD)  ã§æå®ãããã¼ã¿ãæ ¼ç´ãããã ä¸æ¹ã events
       ã¡ã³ãã«ã¯è¿ãããå©ç¨å¯è½ãªã¤ãã³ãã®ããããã£ã¼ã«ããæ ¼ç´ãããã

   epoll_pwait()
       epoll_wait()  㨠epoll_pwait()  ã®é¢ä¿ã¯ã select(2)  㨠pselect(2)
       ã®é¢ä¿ã¨åæ§ã§ããã pselect(2)  åæ§ã epoll_pwait()
       ã使ãã¨ãã¢ããªã±ã¼ã·ã§ã³ã¯ããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãæºåã§ããç¶æã«ãªããã
       ã·ã°ãã«ãææãããã¾ã§ãå®å¨ã«å¾ã¤ãã¨ãã§ããã

       以ä¸ã® epoll_pwait()  ã®å¼ã³åºãã¯ã

           ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);

       次ã®å¼ã³åºãã atomic ã«å®è¡ããã®ã¨ç価ã§ããã

           sigset_t origmask;

           sigprocmask(SIG_SETMASK, &sigmask, &origmask);
           ready = epoll_wait(epfd, &events, maxevents, timeout);
           sigprocmask(SIG_SETMASK, &origmask, NULL);

       sigmask å¼ãæ°ã«ã¯ NULL ãæå®ãã¦ãããã ãã®å ´åã«ã¯ã epoll_pwait()  ã¯
       epoll_wait() ã¨ç価ã¨ãªãã

è¿ãå¤
       æåããå ´åã epoll_wait()  ã¯è¦æ±ããã I/O
       ã«å¯¾ãã¦æºåãã§ãã¦ãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã®æ°ãè¿ãã ã¾ãè¦æ±ããã timeout
       ããªç§ã®éã«ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãæºåã§ããªãå ´åã¯ã0 ãè¿ãã
       ã¨ã©ã¼ãèµ·ãã£ãå ´åã epoll_wait()  㯠-1 ãè¿ãã errno ãé©åã«è¨å®ããã

ã¨ã©ã¼
       EBADF  epfd ãæå¹ãªãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã§ãªãã

       EFAULT events ã§æãããã¡ã¢ãªé åã«æ¸ãè¾¼ã¿æ¨©éã§ã¢ã¯ã»ã¹ã§ããªãã

       EINTR  è¦æ±ãããã©ã®ã¤ãã³ããçºçãããã㤠timeout ã®æéãåããåã«ã
              ã·ã¹ãã ã³ã¼ã«ãã·ã°ãã«ãã³ãã©ã«ãã£ã¦å²ãè¾¼ã¾ããã signal(7) åç§ã

       EINVAL epfd ã epoll ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã§ãªãã ã¾ã㯠maxevents ã 0
              以ä¸ã§ããã

ãã¼ã¸ã§ã³
       epoll_wait() ã¯ã«ã¼ãã« 2.6 ã§è¿½å ãããã ã©ã¤ãã©ãªã«ãããµãã¼ã㯠glibc
       ãã¼ã¸ã§ã³ 2.3.2 以éã§æä¾ããã¦ããã

       epoll_pwait() ã¯ã«ã¼ãã« 2.6.19 㧠Linux ã«è¿½å ãããã
       ã©ã¤ãã©ãªã«ãããµãã¼ã㯠glibc ãã¼ã¸ã§ã³ 2.6 以éã§æä¾ããã¦ããã

æºæ
       epoll_wait() 㯠Linux ç¬èªã§ããã

注æ
       ããã¹ã¬ããã epoll_pwait() ãå¼ã³åºãã¦åæ¢ããã¦ããéã«ã å¥ã®ã¹ã¬ããã wait ä¸ã®
       epoll ã¤ã³ã¹ãã¼ã«ã«ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã
       追å ãããã¨ããããæ°ãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã§ã¤ãã³ããçºçããã¨ã epoll_wait()
       ã®å¼ã³åºãã«ããåæ¢ã解é¤ããããã¨ã«ãªãã

       epoll_wait() ã§ç£è¦ä¸ã® epoll
       ã¤ã³ã¹ã¿ã³ã¹åã®ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãå¥ã®ã¹ã¬ããã«ãã£ã¦ã¯ã‐
       ã¼ãºãããå ´åã«ä½ãèµ·ãããã®è°è«ã«ã¤ãã¦ã¯ã select(2) ãåç§ãã¦ã»ããã

ãã°
       ãã¼ã¸ã§ã³ 2.6.37 ããåã®ã«ã¼ãã«ã§ã¯ããããã LONG_MAX / HZ ããªç§ãã大ãã
       timeout å¤ã¯ -1 (ã¤ã¾ãç¡é大) ã¨ãã¦æ±ãããããããã£ã¦ãä¾ãã°ãsizeof(long) ã 4
       ã§ãã«ã¼ãã«ã® HZ ã®å¤ã 1000 ã®ã·ã¹ãã ã§ã¯ã 35.79
       åããã大ããªã¿ã¤ã ã¢ã¦ãã¯ç¡é大ã¨ãã¦æ±ãããã¨ãããã¨ã§ããã

é¢é£é ç®
       epoll_create(2), epoll_ctl(2), epoll(7)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.51 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



Linux                             2012-08-17                     EPOLL_WAIT(2)