listen

å称
     listen — ã½ã±ããä¸ã®æ¥ç¶ããªã¹ã³ãã

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

æ¸å¼
     <sys/types.h> <sys/socket.h> int listen(int s, int backlog)

解説
     socket(2) ã§æåã«ã½ã±ãããä½æããã çä¿¡æ¥ç¶ãåãå¥ããææããã³çä¿¡æ¥ç¶ç¨ã®å¾ã¡è¡åéçã
     listen() ã§æå®ãããå¾ãæ¥ç¶ã accept(2) ã§åãå¥ãããã¾ãã listen()
     ã·ã¹ãã ã³ã¼ã«ã¯ãã¿ã¤ãã SOCK_STREAM ã¾ã㯠SOCK_SEQPACKET
     ã®ã½ã±ããã«ã ãé©ç¨ããã¾ãã

     backlog å¼æ°ã¯ã延æä¸ã®æ¥ç¶ã®å¾ã¡è¡åã伸ã°ãéã®æ大é·ãå®ç¾©ãã¾ãã
     å¾ã¡è¡åãæºæ¯ã®ã¨ãã«æ¥ç¶è¦æ±ãå°çããã¨ãã¯ã©ã¤ã¢ã³ã㯠ECONNREFUSED
     ã示ãã¨ã©ã¼ãåä¿¡ããå¯è½æ§ãããã¾ãã TCP ã®å ´åã¯ãæ¥ç¶ã¯é»ã£ã¦è½ã¨ããã¾ãã

     FreeBSD 4.5 以å㧠syncache ãå°å¥ãããã¾ã§ã¯ã backlog
     å¼æ°ã¯ä¸å®å¨ãªæ¥ç¶ã®å¾ã¡è¡åã®é·ããå®ç¾©ãã¦ãã¾ããã ãã®å¾ã¡è¡åã«ã¯ãTCP ã® 3
     ã¦ã§ã¤ãã³ãã·ã§ã¼ã¯ãå®äºãããã¹ãå¦çä¸ã® TCP ã½ã±ãããä¿æããã¦ãã¾ãã
     ãããã®ä¸å®å¨ãªæ¥ç¶ã¯ãç¾å¨ãã¹ã¦ syncache ã«ä¿æããã
     ããã¯å¾ã¡è¡åã®é·ãã«å½±é¿ããã¾ããã backlog
     å¤ãå¢ãããã¨ã«ãããµã¼ãã¹ä¸è½æ»æã«å¯¾å¦ããå¿è¦ã¯ããã¯ãããã¾ããã

     sysctl(3) MIB å¤æ° “kern.ipc.somaxconn” 㯠backlog ã®ãã¼ããªããããæå®ãã¾ãã
     kern.ipc.somaxconn ãã大ããå¤ãã¾ã㯠0 ããå°ããå¤ãæå®ããã¦ããå ´åã backlog
     ã®æå®ã¯ç¡è¦ãã㦠kern.ipc.somaxconn ã®å¤ã«ããã¾ãã

ACCEPT ãã£ã«ã¿ã¨ã®ç¸äºä½ç¨
     ã½ã±ããã«å¯¾ã㦠accept ãã£ã«ã¿ã使ç¨ããã¨ã æ¥ç¶æ¸ã¿ã§ãããã®ã® accept
     ãã£ã«ã¿ã®åºæºã«ã¾ã åè´ããªãã½ã±ããã ä¿æããããã®ç¬¬ 2 ã®å¾ã¡è¡åã使ç¨ããã¾ãã
     ã²ã¨ãã³åºæºã«åè´ããã°ããããã®ã½ã±ããã¯æ¥ç¶å®äºæ¸ã®å¾ã¡è¡åã«ç§»åããã accept(2)
     ã®å¯¾è±¡ã«ãªãã¾ãã 第 2 ã®å¾ã¡è¡åãæºæ¯ã®ã¨ãã«æ°è¦æ¥ç¶ãå°çããã¨ã accept
     ãã£ã«ã¿ã®åºæºã«ã¾ã åè´ããªãæå¤ã®ã½ã±ãããçµäºããã¾ãã

     ãã®ç¬¬ 2 ã®å¾ã¡è¡åã¯ã第 1 ã® listen å¾ã¡è¡åã®ããã«ã backlog
     å¼æ°ã«å¾ã£ã¦å¤§ãããå¤ããã¾ãã

æ»ãå¤
     The listen() function returns the value 0 if successful; otherwise the
     value -1 is returned and the global variable errno is set to indicate the
     error.

ã¨ã©ã¼
     listen() ã·ã¹ãã ã³ã¼ã«ã¯æ¬¡ã®å ´åã«å¦çã失æãã¾ã:

     [EBADF]            å¼æ° s ãæå¹ãªè¨è¿°åã§ã¯ããã¾ããã

     [EINVAL]           ãã®ã½ã±ããã¯ãã§ã«æ¥ç¶ããã¦ããããæ¥ç¶ç¢ºç«ä¸ã§ãã

     [ENOTSOCK]         å¼æ° s ãã½ã±ããã§ã¯ããã¾ããã

     [EOPNOTSUPP]       ã½ã±ãããã listen() ããµãã¼ãããã¿ã¤ãã§ã¯ããã¾ããã

é¢é£é ç®
     accept(2), connect(2), socket(2), sysctl(3), sysctl(8), accept_filter(9)

æ´å²
     listen() ã·ã¹ãã ã³ã¼ã«ã¯ 4.2BSD ã§ç»å ´ãã¾ããã å®è¡æã«æ大 backlog ãè¨‐
     å®ã§ããæ©è½ãããã³è¨±å®¹ã§ããæ大å¤ãæå®ããå ´åã«è² ã® backlog ã使ç¨ããæ©è½ã¯
     FreeBSD 2.2 ã§ç»å ´ãã¾ããã