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

📄 setsockopt.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>setsockopt</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>setsockopt - set the socket options</blockquote><h4>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="syssocket.h.html">sys/socket.h</a>&gt;int setsockopt(int <I>socket</I>, int <I>level</I>, int <I>option_name</I>, const void                *<I>option_value</I>, socklen_t <I>option_len</I>);</code></pre></blockquote><h4>DESCRIPTION</h4><blockquote>The<i>setsockopt()</i>function sets the option specified by the <I>option_name</I> argument, at theprotocol level specified by the <I>level</I> argument, to the value pointed toby the <I>option_value</I> argument for the socket associated with the filedescriptor specified by the <I>socket</I> argument.<p>The <I>level</I> argumentspecifies the protocol level at which the option resides.  To set options atthe socket level, specify the <I>level</I> argument as SOL_SOCKET.  To setoptions at other levels, supply the appropriate protocol number for theprotocol controlling the option.  For example, to indicate that an option willbe interpreted by the TCP (Transport Control Protocol), set <I>level</I> to theprotocol number of TCP, as defined in the &lt;<B>netinet/in.h</B>&gt; header, or asdetermined by using<i><a href="getprotobyname.html">getprotobyname()</a></i>.<p>The <I>option_name</I> argumentspecifies a single option to set.  The <I>option_name</I> argument and anyspecified options are passed uninterpreted to the appropriate protocol modulefor interpretations.  The &lt;<B>sys/socket.h</B>&gt; header defines the socket leveloptions.  The optionsare as follows:<dl compact><dt>SO_DEBUG<dd>Turns on recording of debugging information.  This option enables or disablesdebugging in the underlying protocol modules.  This option takes an<B>int</B> value.This is a boolean option.<dt>SO_BROADCAST<dd>Permits sending of broadcast messages, if this is supported by the protocol.This option takes an <B>int</B> value.This is a boolean option.<dt>SO_REUSEADDR<dd>Specifies that the rules used in validating addresses supplied to<i><a href="bind.html">bind()</a></i>should allow reuse of local addresses, if this is supported by the protocol.This option takes an <B>int</B> value.This is a boolean option.<dt>SO_KEEPALIVE<dd>Keeps connections active by enabling the periodic transmission of messages, ifthis is supported by the protocol.  This option takes an <B>int</B> value.If the connected socket fails to respond to these messages, the connection isbroken and processes writing to that socket are notified with a SIGPIPEsignal.This is a boolean option.<dt>SO_LINGER<dd>Lingers on a<i><a href="close.html">close()</a></i>if data is present.  This option controls the action taken when unsentmessages queue on a socket and<i><a href="close.html">close()</a></i>is performed.  If SO_LINGER is set, the system blocks the process during<i><a href="close.html">close()</a></i>until it can transmit the data or until the time expires.  If SO_LINGER is notspecified, and<i><a href="close.html">close()</a></i>is issued, the system handles the call in a way that allows the process tocontinue as quickly as possible.  This option takes a <B>linger</B> structure,as defined in the &lt;<B>sys/socket.h</B>&gt; header, to specify the state ofthe option and linger interval.<dt>SO_OOBINLINE<dd>Leaves received out-of-band data (data marked urgent) in line.This option takes an <B>int</B> value.This is a boolean option.<dt>SO_SNDBUF<dd>Sets send buffer size. This option takes an <B>int</B>value.<dt>SO_RCVBUF<dd>Sets receive buffer size.  This option takes an <B>int</B>value.<dt>SO_DONTROUTE<dd>Requests that outgoing messages bypassthe standard routing facilities.The destination must be on a directly-connected network, and messages are directed to the appropriate network interface accordingto the destination address. The effect, if any,of this option depends on what protocol isin use. This option takes an <B>int</B>value.This is a boolean option.<dt>SO_RCVLOWAT<dd>Sets the minimum number of bytes to process for socket input operations.  The default valuefor SO_RCVLOWAT is 1.  If SO_RCVLOWAT is set to a larger value, blocking receive calls normally wait until they have received the smaller of thelow water mark value or the requested amount. (They may return less than the low water mark if an error occurs, a signal is caught, or the type of data next in the receive queue isdifferent than that returned, e.g. out of band data). This option takes an <B>int</B>value.Note that not all implementations allow this option to be set.<dt>SO_RCVTIMEO<dd>Sets the timeout value that specifies the maximum amountof time an input function waits until it completes.It accepts a <B>timeval</B>structure with the number of seconds and microseconds specifying the limit on how long to wait for an input operationto complete.  If a receive operation has blockedfor this much time without receiving additionaldata, it returns with a partial count or<I>errno</I>set to [EAGAIN] or [EWOULDBLOCK] if no data were received.  The default for thisoption is zero, which indicates that a receiveoperationwill not time out.This option takes a <B>timeval</B>structure.Note that not all implementations allow this option to be set.<dt>SO_SNDLOWAT<dd>Sets the minimum number of bytes to process forsocket output operations. Non-blocking outputoperations  will process no data if flow controldoes not allow the smaller of the send lowwater mark value or the entire request to be processed.This option takes an <B>int</B>value.Note that not all implementations allow this option to be set.<dt>SO_SNDTIMEO<dd>Sets the timeout value specifying the amount of time that an output function blocks because flow control prevents data from being sent.If a send operation has blocked for this time, it returns with a partial count orwith errno set to [EAGAIN] ore [EWOULDBLOCK] if no data were sent.  The default for this option is zero, which indicates that a send operationwill not time out.This option stores a <B>timeval</B>structure.Note that not all implementations allow this option to be set.</dl><p>For boolean options, 0 indicates that the option is disabled and 1 indicatesthat the option is enabled.<p>Options at other protocol levels vary in format and name.</blockquote><h4>RETURN VALUE</h4><blockquote>Upon successful completion,<i>setsockopt()</i>returns 0.  Otherwise, -1 is returned and <I>errno</I>is set to indicate the error.</blockquote><h4>ERRORS</h4><blockquote>The<i>setsockopt()</i>function will fail if:<dl compact><dt>[EBADF]<dd>The <I>socket</I> argument is not a valid file descriptor.<dt>[EDOM]<dd>The send and receive timeout values are toobig to fit into the timeout fields in the socket structure.<dt>[EFAULT]<dd>The <I>option_value</I>parameter can not be accessed or written.<dt>[EINVAL]<dd>The specified option is invalid at the specified socket level or the sockethas been shut down.<dt>[EISCONN]<dd>The socket is already connected, and a specified option can not be set while the socket is connected.<dt>[ENOPROTOOPT]<dd>The option is not supported by the protocol.<dt>[ENOTSOCK]<dd>The <I>socket</I> argument does not refer to a socket.</dl><p>The<i>setsockopt()</i>function may fail if:<dl compact><dt>[ENOMEM]<dd>There was insufficient memory available for the operation to complete.<dt>[ENOBUFS]<dd>Insufficient resources are available in the system to complete the call.<dt>[ENOSR]<dd>There were insufficient STREAMS resources available for the operation tocomplete.</dl></blockquote><h4>APPLICATION USAGE</h4><blockquote>The<i>setsockopt()</i>function provides an application program with the means to control socketbehaviour.  An application program can use<i>setsockopt()</i>to allocate buffer space, control timeouts, or permit socket databroadcasts.  The<i><a href="syssocket.h.html">&lt;sys/socket.h&gt;</a></i>header defines the socket-level options available to<i>setsockopt()</i>.<p>Options may exist at multiple protocol levels.The SO_ options are always present at the uppermost socket level.</blockquote><h4>SEE ALSO</h4><blockquote><i><a href="bind.html">bind()</a></i>,<i><a href="endprotoent.html">endprotoent()</a></i>,<i><a href="getsockopt.html">getsockopt()</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 + -