⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>socket</title></head><body bgcolor="white"><basefont size="3"> <a name="socket"></a> <a name="tag_03_708"></a><!-- socket --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_708_01"></a>NAME</h4><blockquote>socket - create an endpoint for communication</blockquote><h4><a name="tag_03_708_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>&gt;<br><br> int socket(int</tt> <i>domain</i><tt>, int</tt> <i>type</i><tt>, int</tt> <i>protocol</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_708_03"></a>DESCRIPTION</h4><blockquote><p>The <i>socket</i>() function shall create an unbound socket in a communications domain, and return a file descriptor that can beused in later function calls that operate on sockets.</p><p>The <i>socket</i>() function takes the following arguments:</p><dl compact><dt><i>domain</i></dt><dd>Specifies the communications domain in which a socket is to be created.</dd><dt><i>type</i></dt><dd>Specifies the type of socket to be created.</dd><dt><i>protocol</i></dt><dd>Specifies a particular protocol to be used with the socket. Specifying a <i>protocol</i> of 0 causes <i>socket</i>() to use anunspecified default protocol appropriate for the requested socket type.</dd></dl><p>The <i>domain</i> argument specifies the address family used in the communications domain. The address families supported by thesystem are implementation-defined.</p><p>Symbolic constants that can be used for the domain argument are defined in the <a href="../basedefs/sys/socket.h.html"><i>&lt;sys/socket.h&gt;</i></a> header.</p><p>The <i>type</i> argument specifies the socket type, which determines the semantics of communication over the socket. Thefollowing socket types are defined; implementations may specify additional socket types:</p><dl compact><dt>SOCK_STREAM</dt><dd>Provides sequenced, reliable, bidirectional, connection-mode byte streams, and may provide a transmission mechanism forout-of-band data.</dd><dt>SOCK_DGRAM</dt><dd>Provides datagrams, which are connectionless-mode, unreliable messages of fixed maximum length.</dd><dt>SOCK_SEQPACKET</dt><dd>Provides sequenced, reliable, bidirectional, connection-mode transmission paths for records. A record can be sent using one ormore output operations and received using one or more input operations, but a single operation never transfers part of more thanone record. Record boundaries are visible to the receiver via the MSG_EOR flag.</dd></dl><p>If the <i>protocol</i> argument is non-zero, it shall specify a protocol that is supported by the address family. If the<i>protocol</i> argument is zero, the default protocol for this address family and type shall be used. The protocols supported bythe system are implementation-defined.</p><p>The process may need to have appropriate privileges to use the <i>socket</i>() function or to create some sockets.</p></blockquote><h4><a name="tag_03_708_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>socket</i>() shall return a non-negative integer, the socket file descriptor. Otherwise, a valueof -1 shall be returned and <i>errno</i> set to indicate the error.</p></blockquote><h4><a name="tag_03_708_05"></a>ERRORS</h4><blockquote><p>The <i>socket</i>() function shall fail if:</p><dl compact><dt>[EAFNOSUPPORT]</dt><dd><br>The implementation does not support the specified address family.</dd><dt>[EMFILE]</dt><dd>No more file descriptors are available for this process.</dd><dt>[ENFILE]</dt><dd>No more file descriptors are available for the system.</dd><dt>[EPROTONOSUPPORT]</dt><dd><br>The protocol is not supported by the address family, or the protocol is not supported by the implementation.</dd><dt>[EPROTOTYPE]</dt><dd>The socket type is not supported by the protocol.</dd></dl><p>The <i>socket</i>() function may fail if:</p><dl compact><dt>[EACCES]</dt><dd>The process does not have appropriate privileges.</dd><dt>[ENOBUFS]</dt><dd>Insufficient resources were available in the system to perform the operation.</dd><dt>[ENOMEM]</dt><dd>Insufficient memory was available to fulfill the request.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_708_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_708_07"></a>APPLICATION USAGE</h4><blockquote><p>The documentation for specific address families specifies which protocols each address family supports. The documentation forspecific protocols specifies which socket types each protocol supports.</p><p>The application can determine whether an address family is supported by trying to create a socket with <i>domain</i> set to theprotocol in question.</p></blockquote><h4><a name="tag_03_708_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_708_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_708_10"></a>SEE ALSO</h4><blockquote><p><a href="accept.html"><i>accept</i>()</a> , <a href="bind.html"><i>bind</i>()</a> , <a href="connect.html"><i>connect</i>()</a>, <a href="getsockname.html"><i>getsockname</i>()</a> , <a href="getsockopt.html"><i>getsockopt</i>()</a> , <a href="listen.html"><i>listen</i>()</a> , <a href="recv.html"><i>recv</i>()</a> , <a href="recvfrom.html"><i>recvfrom</i>()</a> , <ahref="recvmsg.html"><i>recvmsg</i>()</a> , <a href="send.html"><i>send</i>()</a> , <a href="sendmsg.html"><i>sendmsg</i>()</a> , <ahref="setsockopt.html"><i>setsockopt</i>()</a> , <a href="shutdown.html"><i>shutdown</i>()</a> , <a href="socketpair.html"><i>socketpair</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/netinet/in.h.html"><i>&lt;netinet/in.h&gt;</i></a>, <a href="../basedefs/sys/socket.h.html"><i>&lt;sys/socket.h&gt;</i></a></p></blockquote><h4><a name="tag_03_708_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -