*
* TCP_NODELAY is a mechanism to turn off the use of this algorithm.
* If this option is turned on and there is data to be sent out, TCP
* bypasses the congestion-avoidance algorithm: any available data
* segments are sent out if there is enough space in the send window.
*
* .SS "TCP_MAXSEG -- Changing TCP MSS for the connection"
* Specify the TCP_MAXSEG option to decrease the maximum allowable size of an
* outgoing TCP segment. This option cannot be used to increase the MSS.
* .CS
* setsockopt (sock, IPPROTO_TCP, TCP_MAXSEG, &optval, sizeof (optval));
* .CE
* The value at is an integer set to the desired MSS (eg. 1024).
*
* When a TCP socket is created, the MSS is initialized to the default MSS
* value which is determined by the configuration parameter `TCP_MSS_DFLT' (512
* by default). When a connection request is received from the other end with
* an MSS option, the MSS is modified depending on the value of the received
* MSS and on the results of Path MTU Discovery (which is enabled by default).
* The MSS may be set as high as the outgoing interface MTU (1460 for an
* Ethernet). Therefore, after a call to `socket' but before a connection is
* established, an application can only decrease the MSS from its default of 512.
* After a connection is established, the application can decrease the MSS from
* whatever value was selected.
*
* .SS "SO_DEBUG -- Debugging the underlying protocol"
* Specify the SO_DEBUG option to let the underlying protocol module record
* debug information.
* .CS
* setsockopt (sock, SOL_SOCKET, SO_DEBUG, &optval, sizeof (optval));
* .CE
* The value at for this option is an integer (type `int'),
* either 1 (on) or 0 (off).
*
* OPTION FOR DATAGRAM SOCKETS
* The following section discusses an option for datagram (UDP) sockets.
*
* .SS "SO_BROADCAST -- Sending to Multiple Destinations"
* Specify the SO_BROADCAST option when an application needs to send
* data to more than one destination:
* .CS
* setsockopt (sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval));
* .CE
* The value at is an integer (type ), either 1 (on) or 0
* (off).
*
* OPTIONS FOR DATAGRAM AND RAW SOCKETS
* The following section discusses options for multicasting on UDP and RAW
* sockets.
*
* .SS "IP_ADD_MEMBERSHIP -- Join a Multicast Group"
* Specify the IP_ADD_MEMBERSHIP option when a process needs to join
* multicast group:
* .CS
* setsockopt (sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ipMreq,
* sizeof (ipMreq));
* .CE
* The value of is an 'ip_mreq' structure.
* `ipMreq.imr_multiaddr.s_addr' is the internet multicast address
* `ipMreq.imr_interface.s_addr' is the internet unicast address of the
* interface through which the multicast packet needs to pass.
*
* .SS "IP_DROP_MEMBERSHIP -- Leave a Multicast Group"
* Specify the IP_DROP_MEMBERSHIP option when a process needs to leave
* a previously joined multicast group:
* .CS
* setsockopt (sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ipMreq,
* sizeof (ipMreq));
* .CE
* The value of is an 'ip_mreq' structure.
* `ipMreq.imr_multiaddr.s_addr' is the internet multicast address.
* `ipMreq.imr_interface.s_addr' is the internet unicast address of the
* interface to which the multicast address was bound.
*
* .SS "IP_MULTICAST_IF -- Select a Default Interface for Outgoing Multicasts"
* Specify the IP_MULTICAST_IF option when an application needs to specify
* an outgoing network interface through which all multicast packets
* are sent:
* .CS
* setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ifAddr,
* sizeof (mCastAddr));
* .CE
* The value of is an 'in_addr' structure.
* `ifAddr.s_addr' is the internet network interface address.
详情回复
发表于 2009-11-14 22:34
/*******************************************************************************
*
* setsockopt - set socket options
*
* This routine sets the options associated with a socket.
* To manipulate options at the "socket" level, should be SOL_SOCKET.
* Any other levels should use the appropriate protocol number.
*
* OPTIONS FOR STREAM SOCKETS
* The following sections discuss the socket options available for
* stream (TCP) sockets.
*
* .SS "SO_KEEPALIVE -- Detecting a Dead Connection"
* Specify the SO_KEEPALIVE option to make the transport protocol (TCP)
* initiate a timer to detect a dead connection:
* .CS
* setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof (optval));
* .CE
* This prevents an application from hanging on an invalid connection.
* The value at for this option is an integer (type `int'),
* either 1 (on) or 0 (off).
*
* The integrity of a connection is verified by transmitting
* zero-length TCP segments triggered by a timer, to force a response
* from a peer node. If the peer does not respond after repeated
* transmissions of the KEEPALIVE segments, the connection is dropped,
* all protocol data structures are reclaimed, and processes sleeping
* on the connection are awakened with an ETIMEDOUT error.
*
* The ETIMEDOUT timeout can happen in two ways. If the connection is
* not yet established, the KEEPALIVE timer expires after idling
* for TCPTV_KEEP_INIT. If the connection is established, the
* KEEPALIVE timer starts up when there is no traffic for
* TCPTV_KEEP_IDLE. If no response is received from the peer after
* sending the KEEPALIVE segment TCPTV_KEEPCNT times with interval
* TCPTV_KEEPINTVL, TCP assumes that the connection is invalid.
* The TCPTV_KEEP_INIT, TCPTV_KEEP_IDLE, TCPTV_KEEPCNT, and TCPTV_KEEPINTVL
* parameters are defined in the file target/h/netinet/tcp_timer.h.
*
* .SS "SO_LINGER -- Closing a Connection"
* Specify the SO_LINGER option to determine whether TCP should perform a
* "graceful" close:
* .CS
* setsockopt (sock, SOL_SOCKET, SO_LINGER, &optval, sizeof (optval));
* .CE
* To achieve a "graceful" close in response to the shutdown of a connection,
* TCP puts itself through an elaborate set of state transitions. The goal is
* to assure that all the unacknowledged data in the transmission channel are
* acknowledged, and that the peer is shut down properly.
*
* The value at indicates the amount of time to linger if
* there is unacknowledged data, using `struct linger' in
* target/h/sys/socket.h. The `linger' structure has two members:
* `l_onoff' and `l_linger'. `l_onoff' can be set to 1 to turn on the
* SO_LINGER option, or set to 0 to turn off the SO_LINGER option.
* `l_linger' indicates the amount of time to linger. If `l_onoff' is
* turned on and `l_linger' is set to 0, a default value TCP_LINGERTIME
* (specified in netinet/tcp_timer.h) is used for incoming
* connections accepted on the socket.
*
* When SO_LINGER is turned on and the `l_linger' field is set to 0,
* TCP simply drops the connection by sending out an RST (if a
* connection is already established). This frees up the space for the TCP
* protocol control block, and wakes up all tasks sleeping on the
* socket.
*
* For the client side socket, the value of `l_linger' is not changed
* if it is set to 0. To make sure that the value of `l_linger' is 0
* on a newly accepted socket connection, issue another setsockopt()
* after the accept() call.
*
* Currently the exact value of `l_linger' time is actually ignored
* (other than checking for 0); that is, TCP performs the state
* transitions if `l_linger' is not 0, but does not explicitly use its
* value.
*
* .SS "TCP_NODELAY -- Delivering Messages Immediately"
* Specify the TCP_NODELAY option for real-time protocols, such as the X
* Window System Protocol, that require immediate delivery of many small
* messages:
* .CS
* setsockopt (sock, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof (optval));
* .CE
* The value at is an integer (type `int') set to either 1
* (on) or 0 (off).
*
* By default, the VxWorks TCP implementation employs an algorithm that
* attempts to avoid the congestion that can be produced by a large number
* of small TCP segments. This typically arises with virtual terminal
* applications (such as telnet or rlogin) across networks that have
* low bandwidth and long delays. The algorithm attempts to have no
* more than one outstanding unacknowledged segment in the transmission
* channel while queueing up the rest of the smaller segments for later
* transmission. Another segment is sent only if enough new data is
* available to make up a maximum sized segment, or if the outstanding
* data is acknowledged.
*
* This congestion-avoidance algorithm works well for virtual terminal
* protocols and bulk data transfer protocols such as FTP without any
* noticeable side effects. However, real-time protocols that require
* immediate delivery of many small messages, such as the X Window
* System Protocol, need to defeat this facility to guarantee proper
* responsiveness in their operation.
*
* TCP_NODELAY is a mechanism to turn off the use of this algorithm.
* If this option is turned on and there is data to be sent out, TCP
* bypasses the congestion-avoidance algorithm: any available data
* segments are sent out if there is enough space in the send window.
*
* .SS "TCP_MAXSEG -- Changing TCP MSS for the connection"
* Specify the TCP_MAXSEG option to decrease the maximum allowable size of an
* outgoing TCP segment. This option cannot be used to increase the MSS.
* .CS
* setsockopt (sock, IPPROTO_TCP, TCP_MAXSEG, &optval, sizeof (optval));
* .CE
* The value at is an integer set to the desired MSS (eg. 1024).
*
* When a TCP socket is created, the MSS is initialized to the default MSS
* value which is determined by the configuration parameter `TCP_MSS_DFLT' (512
* by default). When a connection request is received from the other end with
* an MSS option, the MSS is modified depending on the value of the received
* MSS and on the results of Path MTU Discovery (which is enabled by default).
* The MSS may be set as high as the outgoing interface MTU (1460 for an
* Ethernet). Therefore, after a call to `socket' but before a connection is
* established, an application can only decrease the MSS from its default of 512.
* After a connection is established, the application can decrease the MSS from
* whatever value was selected.
*
* .SS "SO_DEBUG -- Debugging the underlying protocol"
* Specify the SO_DEBUG option to let the underlying protocol module record
* debug information.
* .CS
* setsockopt (sock, SOL_SOCKET, SO_DEBUG, &optval, sizeof (optval));
* .CE
* The value at for this option is an integer (type `int'),
* either 1 (on) or 0 (off).
*
* OPTION FOR DATAGRAM SOCKETS
* The following section discusses an option for datagram (UDP) sockets.
*
* .SS "SO_BROADCAST -- Sending to Multiple Destinations"
* Specify the SO_BROADCAST option when an application needs to send
* data to more than one destination:
* .CS
* setsockopt (sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval));
* .CE
* The value at is an integer (type ), either 1 (on) or 0
* (off).
*
* OPTIONS FOR DATAGRAM AND RAW SOCKETS
* The following section discusses options for multicasting on UDP and RAW
* sockets.
*
* .SS "IP_ADD_MEMBERSHIP -- Join a Multicast Group"
* Specify the IP_ADD_MEMBERSHIP option when a process needs to join
* multicast group:
* .CS
* setsockopt (sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ipMreq,
* sizeof (ipMreq));
* .CE
* The value of is an 'ip_mreq' structure.
* `ipMreq.imr_multiaddr.s_addr' is the internet multicast address
* `ipMreq.imr_interface.s_addr' is the internet unicast address of the
* interface through which the multicast packet needs to pass.
*
* .SS "IP_DROP_MEMBERSHIP -- Leave a Multicast Group"
* Specify the IP_DROP_MEMBERSHIP option when a process needs to leave
* a previously joined multicast group:
* .CS
* setsockopt (sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ipMreq,
* sizeof (ipMreq));
* .CE
* The value of is an 'ip_mreq' structure.
* `ipMreq.imr_multiaddr.s_addr' is the internet multicast address.
* `ipMreq.imr_interface.s_addr' is the internet unicast address of the
* interface to which the multicast address was bound.
*
* .SS "IP_MULTICAST_IF -- Select a Default Interface for Outgoing Multicasts"
* Specify the IP_MULTICAST_IF option when an application needs to specify
* an outgoing network interface through which all multicast packets
* are sent:
* .CS
* setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ifAddr,
* sizeof (mCastAddr));
* .CE
* The value of is an 'in_addr' structure.
* `ifAddr.s_addr' is the internet network interface address.