socket

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



åå
       socket - éä¿¡ã®ããã®ç«¯ç¹(endpoint)ãä½æãã

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

       int socket(int domain, int type, int protocol);

æ¸å¼
       socket ã¯éä¿¡ã®ããã®ç«¯ç¹(endpoint)ãä½æããã£ã¹ã¯ãªãã¿ã¼(descriptor)ãè¿ãã

       domain ãã©ã¡ã¼ã¿ã¼ã¯éä¿¡ãè¡ãªããã¡ã¤ã³(domain)ãæå®ãã; ããã¯ã©ã® ãã‐
       ãã³ã«ã»ãã¡ããª(protocol family)ã使ç¨ããããæå®ããã ãããã®ãã¡ããªã¯
       sys/socket.h ã¤ã³ã¯ã«ã¼ãã»ãã¡ã¤ã«ã«å®ç¾©ããã¦ããã

       ç¾å¨ãç解ã§ãããã©ã¼ãããã¯


              AF_UNIX  (UNIX åé¨ãããã³ã«)

              AF_INET  (ARPA ã¤ã³ã¿ã¼ãããã»ãããã³ã«)

              AF_ISO   (ISO ãããã³ã«)

              AF_NS    (Xerox ãããã¯ã¼ã¯ã»ã·ã¹ãã ã»ãããã³ã«)

              AF_IMPLINK
                       (IMP “host at IMP” ãªã³ã¯å±¤)

       ã½ãã±ã㯠type ã§æå®ãããåãæã¡ãããã¯éä¿¡ã®æ¹å¼(semantics)ãæå®ããã
       ç¾å¨ãå®ç¾©ããã¦ããåã¯:

              SOCK_STREAM
              SOCK_DGRAM
              SOCK_RAW
              SOCK_SEQPACKET
              SOCK_RDM

       SOCK_STREAM åã¯ãã¤ãã»ã¹ããªã¼ã (byte
       stream)ã«åºã¥ãããé åºæ§ãä¿¡é ¼æ§ã®ããäºç¹éæ¥ç¶ã« ããéä¿¡ãæä¾ããã帯åå¤(out-
       of-band)ãã¼ã¿è»¢éã¡ã«ããºã ã ãµãã¼ããããã SOCK_DGRAM
       ã½ã±ããã¯ãã¼ã¿ã°ã©ã (datagram)(æ¥ç¶ç¡ããä¿¡é ¼æ§ç¡ãã(å¸åçã«
       å°ããª)åºå®æ大é·ã¡ãã»ã¼ã¸) SOCK_SEQPACKET
       ã½ã±ããã¯åºå®æ大é·ã®ãã¼ã¿ã°ã©ã 転éãã¹ã«åºã¥ããé åºæ§ãä¿¡é ¼æ§ã®ãã
       äºç¹éæ¥ç¶ã«ããéä¿¡ãæä¾ãããåãåãå´ã¯å®å¨ãªãã±ãã(packet)ã ããããã® read
       ã·ã¹ãã ã»ã³ã¼ã«ãç¨ãã¦èªã¿åããã¨ãè¦æ±ãããã ãã®æ§è³ªã¯ãã‐
       ãã³ã«ç¹æã§ãããç¾å¨ã®ã¨ãã AF_NS ã®ããã ãã«å®è£ããã¦ããã SOCK_RAW
       ã¯åé¨ãããã¯ã¼ã¯ã»ãããã³ã«ãã¤ã³ã¿ã¼ãã§ã¼ãº(interface)ã¸ã®ã¢ã¯ã»ã¹ã æä¾ããã
       SOCK_RAW ã¯ã¹ã¼ãã¼ã»ã¦ã¼ã¶ã¼ã®ã¿ãå¯è½ã§ããã SOCK_RDM,
       ã¯è¨ç»ããã¦ãããã®ã®ã¾ã å®è£ããã¦ããªãã§ããã«ã¯è¨è¿°ããªãã

       protocol ã¯ã½ã±ããã«ãã£ã¦ä½¿ç¨ãããåºæã®ãããã³ã«ãæå®ãããé常ã¯ããããã®
       ã½ã±ããã¯ä¸ãããããããã³ã«ã»ãã¡ããªã®ç¨®é¡ãã¨ã«ä¸ã¤ã®ãããã³ã«
       ã®ã¿ããµãã¼ããããããããå¤ãã®ãããã³ã«ãåå¨ãã¦ããã¾ããªãã
       ãã®å ´åã«ã¯ãã®æ¹æ³ã«ããåºæã®ãããã³ã«ãæå®ããå¿è¦ãããã 使ç¨ããããã‐
       ãã³ã«çªå·ã¯éä¿¡ã®è¡ãªããã“éä¿¡ãã¡ã¤ã³”ã« åºæã§ãã; protocols(5)
       ãåç§ãããã¨ã

       SOCK_STREAM åã®ã½ã±ããã¯ãã¤ã(pipe)ã®ãããªå¨äºéãã¤ãã»ã¹ããªã¼ã ã§ããã
       ã¹ããªã¼ã ã¯ã½ã±ããã¯ãã¼ã¿ãéã£ããåãããããåã« æ¥ç¶
       ç¶æã«ãªã£ã¦ãªããã°ãªããªããä»ã®ã½ã±ããã¸ã®æ¥ç¶ã¯ connect(2)
       ã³ã¼ã«ã«ãã£ã¦è¡ãªããããä¸åº¦æ¥ç¶ããããã¼ã¿ã¯ read(2) 㨠write(2) ã³ã¼ã«ã
       send(2) 㨠recv(2) ã³ã¼ã«ã®å¤ç¨®ã使ç¨ãã¦è»¢éã§ããã
       ã»ãã·ã§ã³(session)ãå®äºããã close(2) ãè¡ãªãããã帯åå¤ãã¼ã¿ã®è»¢éã send(2)
       ã«è¨è¿°ããã¦ããã åä¿¡ã recv(2) ã«è¨è¿°ããã¦ããã

       SOCK_STREAM ã®å®è£ã«ä½¿ç¨ãããéä¿¡ãããã³ã«ã¯ãã¼ã¿ã«æ失ãéè¤ã
       ãªããã¨ãä¿è¨¼ãããããç¸æã®ãããã³ã«ããããã¡ã¼ç©ºéãæ㤠ãã¼ã¿ã®æ‐
       çãé©å½ãªæéã®ãã¡ã«è»¢éã§ããªããã°ãæ¥ç¶ã¯ æãããã¨ãã¦å¤æãã¦ãã³ã¼ã«ã¯ -1
       ãè¿ãã¦ã¨ã©ã¼ã示ãã errno ã°ãã¼ãã«å¤æ°ã« ETIMEDOUT ãè¨å®ããã ãã®ãã‐
       ãã³ã«ã¯ãªãã·ã§ã³ã§
       ä»ã®éä¿¡ããªãå ´åã«ã¯ç´ï¼åãã¨ã«å¼·å¶çã«è»¢éãè¡ãªãã½ã±ããã æãã(warm)
       ä¿ã¤ãã¨ãã§ããã ããä¼æ¢ããæ¥ç¶ã®ç¸æããæ¡å¼µãããæé(ä¾ãã°5å)ã®éå¿çãå¼ãåºã
       ãªãã£ãå ´åã«ã¯ã¨ã©ã¼ã示ãããã ããããã»ã¹ãå£ããã¹ããªã¼ã ã«ãã¼ã¿ãéã£ãå ´åã¯
       SIGPIPE ã·ã°ãã«ãéããã; ããã¯é常ã®ãã®ã·ã°ãã«ãæ±ã£ã¦ããªãããã»ã¹ ãçµäºãããã

       SOCK_SEQPACKET ã½ã±ãã㯠SOCK_STREAM ã½ã±ããã¨åãã·ã¹ãã ã»ã³ã¼ã«ã使ç¨ããã
       å¯ä¸ã®éã㯠read(2) ã³ã¼ã«ãè¦æ±ãããéã®ãã¼ã¿ã®ã¿ãè¿ããå°çãããã±ããã®æ®ãã®é¨åã
       æ¨ã¦ã¦ãã¾ããã¨ã§ããã

       SOCK_DGRAM 㨠SOCK_RAW ã½ã±ãã㯠send(2)
       ã³ã¼ã«ã§æå®ãããç¸æã¸ãã¼ã¿ã°ã©ã ãéããã¨ã許ããã¦ããã ãã¼ã¿ã°ã©ã ã¯ä¸è¬ã«
       recvfrom(2) ã§åãã¨ãã ããã¯è¿ãã¢ãã¬ã¹ã¨ãã¦æ¬¡ã®ãã¼ã¿ã°ã©ã ãè¿ãã

       fcntl(2) ã³ã¼ã«ã¯ãã³ãå¤ãã¼ã¿ãåãã¨ã£ãæã« SIGURG ã·ã°ãã«ãåãã¨ããã‐
       ã»ã¹ã»ã°ã«ã¼ããæå®ããã®ã«ä½¿ç¨ã§ããã ã¾ãéåæ¢(non-blocking) I/O ã SIGIO
       ãéãã I/O ã¤ãã³ãã®éåæ(asynchronous)éç¥ãå¯è½ã«ããã

       ã½ã±ããã®æä½ã¯ã½ã±ããã»ã¬ãã«ã® ãªãã·ã§ã³(options) ã«ãã£ã¦å¶å¾¡ãããã
       ãããã®ãªãã·ã§ã³ã¯ sys/socket.h ãã¡ã¤ã«ã«å®ç¾©ããã¦ããã setsockopt(2) ã¨
       getsockopt(2) ã¯ãããããªãã·ã§ã³ã®è¨å®ã¨åå¾ãè¡ãªãã

è¿ãå¤
       ã¨ã©ã¼ãçºçããå ´å㯠-1 ãè¿ãããã以å¤ã¯è¿ãå¤ã¯
       ã½ã±ãããåç§ãããã£ã¹ã¯ãªãã¿ã¼ã§ããã

ã¨ã©ã¼
       EPROTONOSUPPORT
               ãã®ãã¡ã¤ã³ã§ã¯æå®ããããããã³ã«ã¾ãã¯ãããã³ã«ã»ã¿ã¤ã(type)ã
               ãµãã¼ãããã¦ããªãã

       EMFILE  ããã»ã¹ãããã®ãã£ã¹ã¯ãªãã¿ã¼ã»ãã¼ãã«ã«ç©ºãããªãã

       ENFILE  ã·ã¹ãã ã»ãã¡ã¤ã«ã»ãã¼ãã«ã«ç©ºãããªãã

       EACCES  æå®ãããã¿ã¤ãã¾ãã¯ãããã³ã«ã®ã½ã±ãããä½æãã許å¯ãä¸ãããã¦ããªãã

       ENOBUFS ååãªãããã¡ã¼ç©ºéã使ç¨ã§ããªããååãªè³æºã解æ¾ãããã¾ã§ã¯ã½ã±ããã
               ä½æãããã¨ã¯ã§ããªãã


æºæ
       4.4BSD ( socket é¢æ°ã¯ 4.2BSD ã§ç¾ãããã) ä¸è¬ã«(System V ã®å¤ç¨®ãå«ãã¦)
       BSD ã®ã½ã±ãã層ã®ã¯ãã¼ã³ããµãã¼ããã¦ãã BSD 以å¤ã®ã·ã¹ãã ã¸ã ã¾ãã¯ãBSD
       以å¤ã®ã·ã¹ãã ããã®ç§»æ¤ãã§ããã

é¢é£é ç®
       accept(2), bind(2), connect(2), getprotoent(3), getsockname(2),
       getsockopt(2), ioctl(2), listen(2), read(2), recv(2), select(2),
       send(2), shutdown(2), socketpair(2), write(2)

       "An Introductory 4.3 BSD Interprocess Communication Tutorial" 㯠UNIX
       Programmer's Supplementary Documents Volume 1 ã¨ãã¦åçãããã

       "BSD Interprocess Communication Tutorial" 㯠UNIX Programmer's
       Supplementary Documents Volume 1 ã¨ãã¦åçãããã



BSD Man Page                     24 July 1993                        SOCKET(2)