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

📄 socklib.html

📁 Vxworks API操作系统和驱动程序设计API。压缩的HTML文件
💻 HTML
📖 第 1 页 / 共 4 页
字号:
</blockQuote><h4>IP_TTL-- set the time-to-live field in outgoing datagrams</h4><blockQuote>Sets the Time-To-Live field for each packet sent from this socket.<pre>    setsockopt (sock, IPPROTO_IP, IP_TTL, &amp;optval, sizeof(optval));</pre>Here <i>optval</i> is an integer (type <i>int</i>), indicating the number of hopsa packet can take before it is discarded.<p></blockQuote><h4>IP_RECVRETOPTS -- [un-]set queueing of reversed source route</h4><blockQuote>Sets whether or not reversed source route queueing will be enabled forincoming datagrams. (Not implemented)<pre>    setsockopt (sock, IPPROTO_IP, IP_RECVRETOPTS, &amp;optval, sizeof(optval));</pre>Here <i>optval</i> is a boolean (type <i>int</i>).  However, this option iscurrently not implemented, so setting it will not change the behaviorof the system.<p></blockQuote><h4>IP_RECVDSTADDR -- [un-]set queueing of IP destination address</h4><blockQuote>Sets whether or not the socket will receive the IP address of thedestination of an incoming datagram in control data.<pre>    setsockopt (sock, IPPROTO_IP, IP_RECVDSTADDR, &amp;optval, sizeof(optval));</pre>Here <i>optval</i> is a boolean (type <i>int</i>).<p></blockquote><h4>OPTIONS FOR BOTH STREAM AND DATAGRAM SOCKETS</h4><blockquote><p>The following sections describe options that can be used with eitherstream or datagram sockets.<p></blockQuote><h4>SO_REUSEADDR -- Reusing a Socket Address</h4><blockQuote>Specify the <b>SO_REUSEADDR</b> option to bind a stream socket to a localport that may be still bound to another stream socket:<pre>    setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &amp;optval, sizeof (optval));</pre>The value at <i>optval</i> is an integer (type <i>int</i>), either 1 (on) or 0(off).<p>When the <b>SO_REUSEADDR</b> option is turned on, applications may bind a stream socket to a local port. This is possible even if the port is still bound to another stream socket.  It is even  possible if that other socket is associated with a "zombie" protocol control block context that has not yet freed from previous sessions.  The uniqueness of port number combinations for each connection is still preserved through sanity checks performed at actual connection setup time.  If this option is not turned on and an application attempts to bind to a port that is being used by a zombie protocol control block, the <b><a href="./sockLib.html#bind">bind</a>(&nbsp;)</b> call fails.<p></blockQuote><h4>SO_REUSEPORT -- Reusing a Socket address and port</h4><blockQuote>This option is similar to the <b>SO_REUSEADDR</b> option but it allows binding tothe same local address and port combination. <pre>    setsockopt (sock, SOL_SOCKET, SO_REUSEPORT, &amp;optval, sizeof (optval));</pre>The value at <i>optval</i> is an integer (type <i>int</i>), either 1 (on) or 0 (off).<p>The <b>SO_REUSEPORT</b> option is mainly required by multicast applications wherea number of applications need to bind to the same multicast address and portto receive multicast data. Unlike <b>SO_REUSEADDR</b> where only the laterapplications need to set this option, with <b>SO_REUSEPORT</b> all applicationsincluding the first to bind to the port are required to set this option. Formulticast addresses <b>SO_REUSEADDR</b> and <b>SO_REUSEPORT</b> show the same behavior so<b>SO_REUSEADDR</b> can be used instead. <p></blockQuote><h4>SO_SNDBUF -- Specifying the Size of the Send Buffer</h4><blockQuote>Specify the <b>SO_SNDBUF</b> option to adjust the maximum size of thesocket-level send buffer:<pre>    setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &amp;optval, sizeof (optval));</pre>The value at <i>optval</i> is an integer (type <b>int</b>) that specifies thesize of the socket-level send buffer to be allocated.<p>When stream or datagram sockets are created, each transport protocolreserves a set amount of space at the socket level for use when thesockets are attached to a protocol.  For TCP, the default size ofthe send buffer is 8192 bytes.  For UDP, the default size of thesend buffer is 9216 bytes.  Socket-level buffers are allocateddynamically from the mbuf pool.<p>The effect of setting the maximum size of buffers (for both <b>SO_SNDBUF</b> and <b>SO_RCVBUF</b>, described below) is not actually to allocate the mbufs from the mbuf pool.  Instead, the effect is to set the high-water mark in the protocol data structure, which is used later to limit the amount of mbuf allocation.  Thus, the maximum size specified for the socket level send and receive buffers can affect the performance of bulk data transfers.  For example, the size of the TCP receive windows is limited by the remaining socket-level buffer space.  These parameters must be adjusted to produce the optimal result for a given application.<p></blockQuote><h4>SO_RCVBUF -- Specifying the Size of the Receive Buffer</h4><blockQuote>Specify the <b>SO_RCVBUF</b> option to adjust the maximum size of thesocket-level receive buffer:<pre>    setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &amp;optval, sizeof (optval));</pre>The value at <i>optval</i> is an integer (type <b>int</b>) that specifies thesize of the socket-level receive buffer to be allocated.<p>When stream or datagram sockets are created, each transport protocolreserves a set amount of space at the socket level for use when thesockets are attached to a protocol.  For TCP, the default size is8192 bytes.  UDP reserves 41600 bytes, enough space for up to fortyincoming datagrams (1 Kbyte each).<p>See the <b>SO_SNDBUF</b> discussion above for a discussion of the impact ofbuffer size on application performance.<p></blockQuote><h4>SO_OOBINLINE -- Placing Urgent Data in the Normal Data Stream</h4><blockQuote>Specify the <b>SO_OOBINLINE</b> option to place urgent data within thenormal receive data stream:<pre>    setsockopt (sock, SOL_SOCKET, SO_OOBINLINE, &amp;optval, sizeof (optval));</pre>TCP provides an expedited data service that does not conform to thenormal constraints of sequencing and flow control of datastreams. The expedited service delivers "out-of-band" (urgent) dataahead of other "normal" data to provide interrupt-like services (forexample, when you hit a CTRL-C during telnet or rlogin session whiledata is being displayed on the screen.)<p>TCP does not actually maintain a separate stream to support theurgent data.  Instead, urgent data delivery is implemented as apointer (in the TCP header) which points to the sequence number ofthe octet following the urgent data. If more than one transmissionof urgent data is received from the peer, they are all put into thenormal stream. This is intended for applications that cannot affordto miss out on any urgent data but are usually too slow to respondto them promptly.<p></blockquote><h4>RETURNS</h4><blockquote><p><p>OK, or ERROR if there is an invalid socket, an unknown option, an optionlength greater than MLEN, insufficient mbufs, or the call is unable to setthe specified option.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="getsockopt"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>getsockopt(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>getsockopt(&nbsp;)</strong> - get socket options</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS getsockopt    (    int    s,                 /* socket */    int    level,             /* protocol level for options */    int    optname,           /* name of option */    char * optval,            /* where to put option */    int *  optlen             /* where to put option length */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine returns relevant option values associated with a socket.To manipulate options at the "socket" level, <i>level</i> should be <b>SOL_SOCKET</b>.Any other levels should use the appropriate protocol number.The <i>optlen</i> parameter should be initialized to indicate the amount ofspace referenced by <i>optval</i>.  On return, the value of the option is copied to<i>optval</i> and the actual size of the option is copied to <i>optlen</i>.<p>Although <i>optval</i> is passed as a char *, the actual variable whose address gets passed in should be an integer or a structure, depending on which <i>optname</i> is being passed. Refer to <b><a href="./sockLib.html#setsockopt">setsockopt</a>(&nbsp;)</b> to determine the correct type of the actual variable (whose address should then be cast to a char *).<p></blockquote><h4>RETURNS</h4><blockquote><p><p>OK, or ERROR if there is an invalid socket, an unknown option, or the callis unable to get the specified option.<p></blockquote><h4>EXAMPLE</h4><blockquote><p>Because <b>SO_REUSEADDR</b> has an integer parameter, the variable to bepassed to <b><a href="./sockLib.html#getsockopt">getsockopt</a>(&nbsp;)</b> should be declared as<pre>   int reuseVal;</pre>and passed in as <pre>   (char *)&amp;reuseVal.</pre>Otherwise the user might mistakenly declare <b>reuseVal</b> as a character,in which case <b><a href="./sockLib.html#getsockopt">getsockopt</a>(&nbsp;)</b> will only return the first byte of theinteger representing the state of this option.  Then whether the returnvalue is correct or always 0 depends on the endian-ness of the machine.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#setsockopt">setsockopt</a>(&nbsp;)</b><hr><a name="getsockname"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>getsockname(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>getsockname(&nbsp;)</strong> - get a socket name</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS getsockname    (    int               s,      /* socket descriptor */    struct sockaddr * name,   /* where to return name */    int *             namelen /* space available in name, later filled in */                              /* with actual name size */     )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine gets the current name for the specified socket <i>s</i>.The <i>namelen</i> parameter should be initialized to indicate the amount ofspace referenced by <i>name</i>.  On return, the name of the socket is copied to<i>name</i> and the actual size of the socket name is copied to <i>namelen</i>.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK, or ERROR if the socket is invalid.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="getpeername"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>getpeername(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>getpeername(&nbsp;)</strong> - get the name of a connected peer</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS getpeername    (    int               s,      /* socket descriptor */    struct sockaddr * name,   /* where to put name */    int *             namelen /* space available in name, later filled in */                              /* with actual name size */     )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine gets the name of the peer connected to socket <i>s</i>.The <i>namelen</i> parameter should be initialized to indicate the amount ofspace referenced by <i>name</i>.  On return, the name of the socket is copied to<i>name</i> and the actual size of the socket name is copied to <i>namelen</i>.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK, or ERROR if the socket is invalidor not connected.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="shutdown"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>shutdown(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>shutdown(&nbsp;)</strong> - shut down a network connection</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS shutdown    (    int s,                    /* socket to shut down */    int how                   /* 0 = receives disallowed 1 = sends */                              /* disallowed 2 = sends and receives */                              /* disallowed */     )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine shuts down all, or part, of a connection-based socket <i>s</i>.If the value of <i>how</i> is 0, receives are disallowed.  If <i>how</i> is 1,sends are disallowed.  If <i>how</i> is 2, both sends and receives aredisallowed.<p></blockquote><h4>RETURNS</h4><blockquote><p>ERROR if the socket is invalid or has no registeredsocket-specific routines; otherwise <b><a href="./sockLib.html#shutdown">shutdown</a>(&nbsp;)</b> returns the return valuefrom the socket-specific shutdown routine (typically OK in the case ofa successful shutdown or ERROR otherwise).</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b></body></html>

⌨️ 快捷键说明

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