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

📄 accept.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>accept</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4>NAME</h4><blockquote>accept - accept a new connection on a socket</blockquote><h4>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="syssocket.h.html">sys/socket.h</a>&gt;int accept (int <I>socket</I>, struct sockaddr *<I>address</I>,                                 socklen_t *<I>address_len</I>);</code></pre></blockquote><h4>DESCRIPTION</h4><blockquote>The<i>accept()</i>function extracts the first connection on the queue of pending connections,creates a new socket with the same socket type protocol and address family asthe specified socket, and allocates a new file descriptor for that socket.<p>The function takes the following arguments:<dl compact><dt><I>socket</I><dd>Specifies a socket that was created with<i><a href="socket.html">socket()</a></i>,has been bound to an address with<i><a href="bind.html">bind()</a></i>,and has issued a successful call to<i><a href="listen.html">listen()</a></i>.<dt><I>address</I><dd>Either a null pointer, or a pointer to a <B>sockaddr</B> structurewhere the address of the connecting socket will be returned.<dt><I>address_len</I><dd>Points to a <B>socklen_t</B> which on input specifies the length of the supplied<B>sockaddr</B> structure, and on output specifies the length of the storedaddress.</dl><p>If <I>address</I> is not a null pointer, the address of the peerfor the accepted connection is stored in the <B>sockaddr</B> structurepointed to by <I>address</I>, and the length of this address isstored in the object pointed to by <I>address_len</I>.<p>If the actual length of the address is greater than the length of the supplied<B>sockaddr</B> structure, the stored address will be truncated.<p>If the protocol permits connections by unbound clients, and the peer is notbound, then the value stored in the object pointed to by <I>address</I> isunspecified.<p>If the listen queue is empty of connection requests and O_NONBLOCK is not seton the file descriptor for the socket,<i>accept()</i>will block until a connection is present.If the<i><a href="listen.html">listen()</a></i>queue is empty of connection requests andO_NONBLOCK is set on the file descriptor for the socket,<i>accept()</i>will fail and set <I>errno</I> to [EAGAIN] or [EWOULDBLOCK]. <p>The accepted socket cannot itself accept more connections.  Theoriginal socket remains open and can accept more connections.</blockquote><h4>RETURN VALUE</h4><blockquote>Upon successful completion,<i>accept()</i>returns the nonnegative file descriptor of the accepted socket.  Otherwise,-1 is returned and <I>errno</I> is set to indicate the error.</blockquote><h4>ERRORS</h4><blockquote>The<i>accept()</i>function will fail if:<dl compact><dt>[EAGAIN] or [EWOULDBLOCK]<dd><br>O_NONBLOCK is set for the socket file descriptor and no connectionsare present to be accepted.<dt>[EBADF]<dd>The <I>socket</I> argument is not a valid file descriptor.<dt>[ECONNABORTED]<dd>A connection has been aborted.<dt>[EFAULT]<dd>The <I>address</I>or <I>address_len</I>parameter can not be accessed or written.<dt>[EINTR]<dd>The<i>accept()</i>function was interrupted by a signal that was caught before a valid connectionarrived.<dt>[EINVAL]<dd>The <I>socket</I> is not accepting connections.<dt>[EMFILE]<dd>{OPEN_MAX} file descriptors are currently open in the calling process.<dt>[ENFILE]<dd>The maximum number of file descriptors in the system are already open.<dt>[ENOTSOCK]<dd>The <I>socket</I> argument does not refer to a socket.<dt>[EOPNOTSUPP]<dd>The socket type of the specified socket does not support acceptingconnections.</dl><p>The<i>accept()</i>function may fail if:<dl compact><dt>[ENOBUFS]<dd>No buffer space is available.<dt>[ENOMEM]<dd>There was insufficient memory available to complete the operation.<dt>[ENOSR]<dd>There was insufficient STREAMS resources available to complete the operation.<dt>[EPROTO]<dd>A protocol error has occurred; for example, the STREAMS protocol stack has notbeen initialised.</dl></blockquote><h4>APPLICATION USAGE</h4><blockquote>When a connection is available,<i><a href="select.html">select()</a></i>will indicate that the file descriptor for the socket is ready for reading.</blockquote><h4>SEE ALSO</h4><blockquote><i><a href="bind.html">bind()</a></i>,<i><a href="connect.html">connect()</a></i>,<i><a href="listen.html">listen()</a></i>,<i><a href="socket.html">socket()</a></i>,<i><a href="syssocket.h.html">&lt;sys/socket.h&gt;</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>

⌨️ 快捷键说明

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