select

å称
     select — åæçãªå¥åºåã®å¤éå

ã©ã¤ãã©ãª
     Standard C Library (libc, -lc)

æ¸å¼
     <sys/select.h> int select(int nfds, fd_set *readfds, fd_set *writefds,
     fd_set *exceptfds, struct timeval *timeout) FD_SET(fd, &fdset) FD_CLR(fd,
     &fdset) FD_ISSET(fd, &fdset) FD_ZERO(&fdset)

解説
     select() ã·ã¹ãã ã³ã¼ã«ã¯ã readfds, writefds ããã³ exceptfds
     ã§ã¢ãã¬ã¹ã渡ãããå¥åºåè¨è¿°åéåã調ã¹ã ãããã®è¨è¿°åã®ããã¤ãããããããèª‐
     åãæºåå®äºã§ãããã æ¸è¾¼ã¿æºåå®äºã§ããããã¾ãã¯ä¿çããã¦ããä¾å¤æ¡ä»¶ããããã調ã¹ã¾ãã
     æ¤åºå¯è½ãªå¯ä¸ã®ä¾å¤æ¡ä»¶ã¯ãã½ã±ããä¸ã«åä¿¡ãã帯åå¤ã®ãã¼ã¿ã§ãã æåã® nfds
     åã®è¨è¿°åãåéååã§ãã§ãã¯ããã¾ãã ããªãã¡ãè¨è¿°åéåä¸ã® 0 ï½ nfds-1 ã®è¨è¿°å‐
     ã調ã¹ããã¾ãã æ»ãæã« select() ã·ã¹ãã ã³ã¼ã«ã¯æå®ã®è¨è¿°å‐
     éåããè¦æ±ãããæä½ã®æºåãã§ãã¦ããè¨è¿°å㧠æ§æãããé¨åéåã§ç½®ãæãã¾ãã select()
     ã¯ããã¹ã¦ã®éåã®ä¸ã§æºåãã§ããè¨è¿°åã®ç·æ°ãè¿ãã¾ãã

     è¨è¿°åã®éåã¯ãæ´æ°éååã®ããããã£ã¼ã«ãã¨ãã¦ä¿åããã¾ãã ãã®ãããªè¨è¿°å‐
     éåãæä½ããããã«æ¬¡ã®ãã¯ããç¨æããã¦ãã¾ã: FD_ZERO(&fdset) ã¯è¨è¿°åéå fdset
     ã空éåã§åæåãã¾ãã FD_SET(fd, &fdset) ã¯ç¹å®ã®è¨è¿°å fd ã fdset ã«å«ãã¾ãã
     FD_CLR(fd, &fdset) 㯠fd ã fdset ããåé¤ãã¾ãã FD_ISSET(fd, &fdset) 㯠fd ã
     fdset ã®ã¡ã³ãã§ããå ´åã¯é 0 ã®å¤ããããã§ãªãå ´å㯠0 ãè¿ãã¾ãã ãããã®ãã¯ã‐
     ã®åä½ã¯ãè¨è¿°åã®å¤ã 0 æªæºã§ããããã¾ã㯠FD_SETSIZE
     以ä¸ã§ããå ´åã¯æªå®ç¾©ã§ãã FD_SETSIZE
     ã¯é常ãå°ãªãã¨ããã·ã¹ãã ããµãã¼ãããè¨è¿°åã®æ大æ°ã«çãããªãã¾ãã

     timeout ããNULL ãã¤ã³ã¿ã§ãªãå ´åãããã¯ã»ã¬ã¯ã·ã§ã³ã®å®äºã
     å¾ã¤æ大ééãæå®ãã¾ãã ã·ã¹ãã ã®æ´»åæ§ãããã®ééãä¸å®æé延é·ãããã¨ãããã¾ãã

     timeout ã NULL ãã¤ã³ã¿ã®å ´åã select() ã¯ç¡æéã«ãããã¯ãã¾ãã

     ãã¼ãªã³ã°ã®ããã«ã¯ã timeout å¼æ°ã¯ NULL ã§ãªããå¤ã 0 ã® timeval
     æ§é ä½ãæãã¦ããã¹ãã§ãã

     readfds, writefds ããã³ exceptfds ã®ã©ãã«ã¤ãã¦ãããããã®è¨è¿°åãèå³ããªãå ´åã¯
     NULL ãã¤ã³ã¿ãæå®ã§ãã¾ãã

æ»ãå¤
     select() ã·ã¹ãã ã³ã¼ã«ã¯è¨è¿°åéåã«å«ã¾ãã¦ããæºåã®ã§ããè¨è¿°åã®æ°ãè¿ãã
     ã¨ã©ã¼ãèµ·ããå ´å㯠-1 ãè¿ãã¾ãã ã¿ã¤ã ãªããããæ¥ãã¨ã select() 㯠0 ãè¿ãã¾ãã
     ã·ã¹ãã ã³ã¼ã«ã®å²ãè¾¼ã¾ãããã¨ã«ãããã®ãå«ã㦠select()
     ãã¨ã©ã¼ã§æ»ãå ´åã¯ãè¨è¿°åéåã¯å¤æ´ããã¾ããã

ã¨ã©ã¼
     select() ããæ»ãã¨ã©ã¼ã¯æ¬¡ã®ãã¨ã示ãã¾ã:

     [EBADF]            è¨è¿°åéåã®ã©ãããç¡å¹ãªè¨è¿°åãæå®ãã¦ãã¾ããã

     [EFAULT]           readfds, writefds, exceptfds ã¾ã㯠timeout ã®å¼æ°ã® 1
                        ã¤ãç¡å¹ãªã¢ãã¬ã¹ãæãã¦ãã¾ãã

     [EINTR]            ã¿ã¤ã ãªããããåããåãããã¯é¸æããã¤ãã³ãã®ãããããèµ·ããåã«ã
                        ã·ã°ãã«ãééããã¾ããã

     [EINVAL]           æå®ã®ã¿ã¤ã ãªãããã¯ç¡å¹ã§ãã
                        ã©ãããè² ã§ããããã¾ãã¯å¤§ãããã¾ãã

     [EINVAL]           nfds å¼æ°ãç¡å¹ã§ããã

é¢é£é ç®
     accept(2), connect(2), getdtablesize(2), gettimeofday(2), kqueue(2),
     poll(2), read(2), recv(2), send(2), write(2), clocks(7)

注
     FD_SETSIZE ã®ããã©ã«ãã®ãµã¤ãºã¯ç¾æç¹ã§ã¯ 1024 ã§ãã
     å¤æ°ã®ãªã¼ãã³ãã¡ã¤ã«ã使ç¨ããå¯è½æ§ãããããã°ã©ã 㧠select() ãå®è¡ããããã«ã
     <sys/types.h> ãåãè¾¼ãããããå«ããåã«ããã°ã©ã 㧠FD_SETSIZE
     ãå®ç¾©ãããã¨ã§ããã®ãµã¤ãºãå¢å ã§ãã¾ãã

     nfds ããªã¼ãã³ãã¡ã¤ã«ã®æ°ãã大ããå ´åã select() ãæªä½¿ç¨ã®ãã¡ã¤ã«è¨è¿°å‐
     ã調æ»ãããã¨ã¯ä¿è¨¼ããã¦ãã¾ããã æ´å²çãªçç±ã§ã select() ã¯æåã® 256 åã®è¨è¿°å‐
     ãå¿ã調æ»ãã¾ãã

ãã°
     Version 2 of the Single UNIX Specification (“SUSv2”) ã§ã¯ãã·ã¹ãã ãåã®
     timeout ãé©å½ã«æ´æ°ãããã¨ã許ãã¦ãã¾ãã ãããã£ã¦ãã¿ã¤ã ã¢ã¦ãã®å¤ã select()
     ã·ã¹ãã ã³ã¼ã«ã«ãã£ã¦å¤æ´ãããªãã¨æ³å®ããã®ã¯è³¢æã§ã¯ããã¾ããã

è¦æ ¼
     select() ã·ã¹ãã ã³ã¼ã«ããã³ FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO()
     ãã¯ã㯠IEEE Std 1003.1-2001 (“POSIX.1”) ã«é©åãã¾ãã

æ´å²
     select() ã·ã¹ãã ã³ã¼ã«ã¯ 4.2BSD ã§ç»å ´ãã¾ããã