tcp 中文man页面

系统
本协议是对 RFC973, RFC1122 和 RFC2001 定义的协议及其 NewReno 和 SACK 扩充部份实现的。它在建立在互联网协议 ip(7) 之上的两个套接字之间提供了可靠的面向数据流的全双工连接。 TCP 协议确保了数据按序到达并在数据包丢失时自动重发。它产生和校验每个数据包的校验和 (checksum) 用以捕捉数据传输时错误。TCP 不保留记录的上下限。

NAME

tcp - 传输控制协议 (TCP)  

总缆 SYNOPSIS

#include <sys/socket.h>
#include <netinet/in.h>
tcp_socket = socket(PF_INET, SOCK_STREAM, 0);  

描述 DESCRIPTION

本协议是对 RFC973, RFC1122 和 RFC2001 定义的协议及其 NewReno 和 SACK 扩充部份实现的。它在建立在互联网协议 ip(7) 之上的两个套接字之间提供了可靠的面向数据流的全双工连接。 TCP 协议确保了数据按序到达并在数据包丢失时自动重发。它产生和校验每个数据包的校验和 (checksum) 用以捕捉数据传输时错误。TCP 不保留记录的上下限。

初始的 TCP 接口不包含远端或本地址并且没有规定明确。在产生一个出站 (outgoing) TCP 连接时使用 connect(2) 来与另个套接字建立一个网络接口。在接收一个入站 (incoming) 连接时,套接字使用 bind(2) 先取得本地地址和端口,然后调用 listen(2) 使套接字进入侦听状态。随后可以用 accept(2). 接受为每一个入站 (incoming) 连接建立的新套接字。一个已经经过 acceptconnect 成功调用的套接字表示它已完全明确,可以进行数据传送。在侦听状态或尚未建立连接的网络接口之间数据传送将不能进行。

Linux 2.2 支持 RFC1323 TCP 高性能扩展。这包括采用大 TCP 数据滑移窗以支持高延时或高带宽下的多连接。为实现这些功能,必须增加接收与发送的数据缓存区。它们可以使用 net.core.wmem_defaultnet.core.rmem_default sysctl 进行全局设定,或用 SO_SNDBUF SO_RCVBUF 套接字选项对套接字进行单独设定。套接字缓存区的最大尺寸,受到由全局变量 net.core.rmem_maxnet.core.wmem_max 两个 sysctl 限制。详细细节,请参见 socket(7).

TCP 支持紧急数据。紧急数据用来通知接收方,在数据流中有需要尽快处理的重要信息。发送紧急数据,需在 send(2). 中指定 MSG_OOB 选项。当紧急数据接收后,内核发送 SIGURG 信号到读进程或者那些用 ioctl 设置了 FIOCSPGRPFIOCSETOWN 套接字的进程或进程组.当打开了 SO_OOBINLINE 套接字选项, 那么紧急数据被放入普通数据流中。 (可以用 SIOCATMARK ioctl 来测试), 否则只有设置了 sendmsg(2) 中的 MSG_OOB 标志时,数据才能被接收。

地址格式 ADDRESS FORMATS

TCP 是建立在 IP 之上(参见 ip(7)). ip(7) 定义定义的地址格式也适用于 TCP. TCP只支持点对点通讯,不支持全局及多址广播。  

系统控制 SYSCTLS

可以通过访问 /proc/sys/net/ipv4/* 目录下的文件或通过 sysctl(2) 接口进行访问这些 sysctl. 此外大多数 IP sysctl 也同样适用于 TCP; 参见 ip(7).

tcp_window_scaling
打开 RFC1323 协议中 TCP 滑移数据窗尺寸调整.
tcp_sack
打开 RFC2018 协议中 TCP 选择性确认.
tcp_timestamps
打开 RFC1323 协议中 TCP 时间戳.
tcp_fin_timeout
规定强迫关闭套接字前,等待最后结束数据包的秒数。这确实与 TCP 协议中有关规定相违背。但这是防止拒绝服务攻击所要求的。
tcp_keepalive_probes
丢弃数据包前,进行最大 TCP 保持连接侦测. 保持连接仅在 SO_KEEPALIVE 套接字选项被打开时才被发送.
tcp_keepalive_time
从不再传送数据到向连接上发送保持连接信号之间所需的秒数,默认为 10800 秒(3 小时)。
tcp_max_ka_probes
在一定时间发送保持连接时间侦测包的数量。为防止突发信号,此值不宜设置太高。
tcp_stdurg
使 TCP 紧急指针字段遵循在 RFC973 协议中的严格解释。缺省情况下,紧急指针字段使用与 BSD 相兼容,指针指向紧急数据后的第一个字节。在 RFC973 协议中是指向紧急数据后的最后一个字节。打开这一选项可能造成操作互换性问题。
tcp_syncookies
打开 TCP 同步标签(syncookie),内核必须打开了 CONFIG_SYN_COOKIES 项进行编译. 同步标签(Syncookie)防止一个套接字在有过多试图连接到达时的过载。当使用同步标签(syncookie)时,客户机可能探测不到一个超时时间短的过载主机。
tcp_max_syn_backlog
每个接口中待发数据队列 (backlog) 长度。Linux 2.2 中,在 listen(2) 中的定义只说明了已建立的套接字中待发数据队列(backlog)长度。每个侦测套接字的还未建立的套接字(在 SYN_RECV 状态中的)的最大队列长度用这个 sysctl 设置。当更多的连接请求到达时,Linux 系统将开始丢弃数据包。当同步标签(syncookie)被设置成打开,数据包仍能被回应时,这个值将被忽略。
tcp_retries1
定义放弃回应一个 TCP 连接请求前发送重试信号的次数。
tcp_retries2
定义放弃在已建立通讯状态下一个 TCP 数据包前重发的次数。
tcp_syn_retries
定义在放弃发送初始同步数据包(SYN packet)到远端主机前重试的次数并返回出错消息,此值必须小于255。这仅对出站(outgoing)连接超时有效;对于进站(incoming)连接重发数由 tcp_retries1 定义。
tcp_retrans_collapse
在重发时试图发送全尺寸数据包。用来解决一些堆栈中的 TCP 缺陷(BUG)。

接口选项 SOCKET OPTIONS

设置或取得 TCP 接口选项,调用 getsockopt(2) 进行读操作或调用 setsockopt(2) 将接口系列选项参数传送到 SOL_TCP 中去.另外,大多数 SOL_IP 接口选项对 TCP 接口也适用。更多资料,请参见 ip(7).

TCP_NODELAY
关闭 Nagle 算法。这意味着数据包将尽可能快地被发送而没有因有网络中更多的数据包造成的延时,期待一个整数表示的布尔标志。
TCP_MAXSEG
设置或接收最大出站 TCP 数据段尺寸。如果这个选项在建立连接前的设置,它将改变发送到另一端初始信息包中的 MSS 值。这个值大于 MTU 接口值将被忽略而不起作用。
TCP_CORK
设置此项将不发送部份帧。所有排队的部份帧只在此项清除后,才能发送。在调用 sendfile(2) 前准备数据报头或对网络吞吐量进行优化有用处。此选项不能与 TCP_NODELAY 联用.

输入输出控制字 IOCTLS

这些 ioctl 可以用 ioctl(2) 进行访问。正确调用句法为:

int value;
error = ioctl(tcp_socket, ioctl_type, &value);
FIONREAD
返回接收缓存中排队的未读数据的数量。变量参数是指向一个整数的指针。
SIOCATMARK
如果用户程序已经接收了所有紧急数据,此项返回值为 0。它与 SO_OOBINLINE 联用。变量参数是对测试结果,指向一个整数的指针。
TIOCOUTQ
返回在接口(socket)发送队列中待发送数据数,该指针返回是一个整数数值。

出错处理 ERROR HANDLING

当网络发生错误时,TCP 协议将尝试重新发送数据包,当重发一定失败次数后,产生超时错 ETIMEDOUT 或报告在此连接上最后出错消息。

有时程序需要更快地侦测到出错状态。这可以通过打开 SOL_IP 级别的 IP_RECVERR 接口选项。当此项打开后,所有入站 (incoming) 错误被立即送到用户程序中。小心使用该选项-它使 TCP 协议对路由的改变和其他正常网络状态变化的容错性下降。  

附注 NOTES

当建立一个连接时发生错误引发一个对 SIGPIPE 接口写操作,此操作仅当 SO_KEEPOPEN 接口选项被设置时才能进行。

TCP 并不具有真正的额外频带(out-of-band)数据; 虽然它可以有紧急数据。在 Linux 中这意味着如果有其他端发送紧急数据时,旧的紧急数据将被当作普通数据插入数据流中。(即使 SO_OOBINLINE 值没有被设置).这与基于 BSD 堆栈定义不同.

缺省状态下,Linux 使用与 BSD 兼容的紧急数据指针字段。这与 RFC1122 协议相违背, 但这是与其他堆栈协议相互操作性所要求。它可以用 tcp_stdurg sysctl 加以改变.

已知错误 ERRORS

EPIPE
另一端意外关闭了套接字连接或对一个关闭了的套接字进行读操作。
ETIMEDOUT
一段时间后,另一端不确认重发数据。
EAFNOTSUPPORT
sin_family 传递套接字地址类型而不是在 AF_INET中的。

任何定义为 ip(7) 出错或普通套接字出错可能返回为 TCP 出错.

不足之处 BUGS

不是所有的错误都列入了文档。

没有描述有关透明代理的选项  

版本 VERSIONS

有关 sysctl 是在 Linux 2.2 中新增的。 IP_RECVERR 是 Linux 2.2 中的新特性。 TCP_CORK 在 2.2 中是新的内容.  

又见 SEE ALSO

socket(7), socket(2), ip(7), sendmsg(2), recvmsg(2).
RFC793 协议中对 TCP 有关描述.
RFC1122 协议中对 TCP 要求和一份关于 Nagle 算法描述。
RFC2001 协议中一些 TCP 算法。

#p#

NAME

tcp - TCP protocol  

SYNOPSIS

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
tcp_socket = socket(PF_INET, SOCK_STREAM, 0);  

DESCRIPTION

This is an implementation of the TCP protocol defined in RFC793, RFC1122 and RFC2001 with the NewReno and SACK extensions. It provides a reliable, stream oriented, full duplex connection between two sockets on top of ip(7), for both v4 and v6 versions. TCP guarantees that the data arrives in order and retransmits lost packets. It generates and checks a per packet checksum to catch transmission errors. TCP does not preserve record boundaries.

A fresh TCP socket has no remote or local address and is not fully specified. To create an outgoing TCP connection use connect(2) to establish a connection to another TCP socket. To receive new incoming connections bind(2) the socket first to a local address and port and then call listen(2) to put the socket into listening state. After that a new socket for each incoming connection can be accepted using accept(2). A socket which has had accept or connect successfully called on it is fully specified and may transmit data. Data cannot be transmitted on listening or not yet connected sockets.

Linux supports RFC1323 TCP high performance extensions. These include Protection Against Wrapped Sequence Numbers (PAWS), Window Scaling and Timestamps. Window scaling allows the use of large (> 64K) TCP windows in order to support links with high latency or bandwidth. To make use of them, the send and receive buffer sizes must be increased. They can be set globally with the net.ipv4.tcp_wmem and net.ipv4.tcp_rmem sysctl variables, or on individual sockets by using the SO_SNDBUF and SO_RCVBUF socket options with the setsockopt(2) call.

The maximum sizes for socket buffers declared via the SO_SNDBUF and SO_RCVBUF mechanisms are limited by the global net.core.rmem_max and net.core.wmem_max sysctls. Note that TCP actually allocates twice the size of the buffer requested in the setsockopt(2) call, and so a succeeding getsockopt(2) call will not return the same size of buffer as requested in the setsockopt(2) call. TCP uses this for administrative purposes and internal kernel structures, and the sysctl variables reflect the larger sizes compared to the actual TCP windows. On individual connections, the socket buffer size must be set prior to the listen() or connect() calls in order to have it take effect. See socket(7) for more information.

TCP supports urgent data. Urgent data is used to signal the receiver that some important message is part of the data stream and that it should be processed as soon as possible. To send urgent data specify the MSG_OOB option to send(2). When urgent data is received, the kernel sends a SIGURG signal to the reading process or the process or process group that has been set for the socket using the SIOCSPGRP or FIOSETOWN ioctls. When the SO_OOBINLINE socket option is enabled, urgent data is put into the normal data stream (and can be tested for by the SIOCATMARK ioctl), otherwise it can be only received when the MSG_OOB flag is set for sendmsg(2).

Linux 2.4 introduced a number of changes for improved throughput and scaling, as well as enhanced functionality. Some of these features include support for zerocopy sendfile(2), Explicit Congestion Notification, new management of TIME_WAIT sockets, keep-alive socket options and support for Duplicate SACK extensions.  

ADDRESS FORMATS

TCP is built on top of IP (see ip(7)). The address formats defined by ip(7) apply to TCP. TCP only supports point-to-point communication; broadcasting and multicasting are not supported.  

SYSCTLS

These variables can be accessed by the /proc/sys/net/ipv4/* files or with the sysctl(2) interface. In addition, most IP sysctls also apply to TCP; see ip(7).

tcp_abort_on_overflow
Enable resetting connections if the listening service is too slow and unable to keep up and accept them. It is not enabled by default. It means that if overflow occurred due to a burst, the connection will recover. Enable this option _only_ if you are really sure that the listening daemon cannot be tuned to accept connections faster. Enabling this option can harm the clients of your server.
tcp_adv_win_scale
Count buffering overhead as bytes/2^tcp_adv_win_scale (if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale), if it is <= 0. The default is 2.

The socket receive buffer space is shared between the application and kernel. TCP maintains part of the buffer as the TCP window, this is the size of the receive window advertised to the other end. The rest of the space is used as the "application" buffer, used to isolate the network from scheduling and application latencies. The tcp_adv_win_scale default value of 2 implies that the space used for the application buffer is one fourth that of the total.

tcp_app_win
This variable defines how many bytes of the TCP window are reserved for buffering overhead.

A maximum of (window/2^tcp_app_win, mss) bytes in the window are reserved for the application buffer. A value of 0 implies that no amount is reserved. The default value is 31.

tcp_dsack
Enable RFC2883 TCP Duplicate SACK support. It is enabled by default.
tcp_ecn
Enable RFC2884 Explicit Congestion Notification. It is not enabled by default. When enabled, connectivity to some destinations could be affected due to older, misbehaving routers along the path causing connections to be dropped.
tcp_fack
Enable TCP Forward Acknowledgement support. It is enabled by default.
tcp_fin_timeout
How many seconds to wait for a final FIN packet before the socket is forcibly closed. This is strictly a violation of the TCP specification, but required to prevent denial-of-service (DoS) attacks. The default value in 2.4 kernels is 60, down from 180 in 2.2.
tcp_keepalive_intvl
The number of seconds between TCP keep-alive probes. The default value is 75 seconds.
tcp_keepalive_probes
The maximum number of TCP keep-alive probes to send before giving up and killing the connection if no response is obtained from the other end. The default value is 9.
tcp_keepalive_time
The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are only sent when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours). An idle connection is terminated after approximately an additional 11 minutes (9 probes an interval of 75 seconds apart) when keep-alive is enabled.

Note that underlying connection tracking mechanisms and application timeouts may be much shorter.

tcp_max_orphans
The maximum number of orphaned (not attached to any user file handle) TCP sockets allowed in the system. When this number is exceeded, the orphaned connection is reset and a warning is printed. This limit exists only to prevent simple DoS attacks. Lowering this limit is not recommended. Network conditions might require you to increase the number of orphans allowed, but note that each orphan can eat up to ~64K of unswappable memory. The default initial value is set equal to the kernel parameter NR_FILE. This initial default is adjusted depending on the memory in the system.
tcp_max_syn_backlog
The maximum number of queued connection requests which have still not received an acknowledgement from the connecting client. If this number is exceeded, the kernel will begin dropping requests. The default value of 256 is increased to 1024 when the memory present in the system is adequate or greater (>= 128Mb), and reduced to 128 for those systems with very low memory (<= 32Mb). It is recommended that if this needs to be increased above 1024, TCP_SYNQ_HSIZE in include/net/tcp.h be modified to keep TCP_SYNQ_HSIZE*16<=tcp_max_syn_backlog, and the kernel be recompiled.
tcp_max_tw_buckets
The maximum number of sockets in TIME_WAIT state allowed in the system. This limit exists only to prevent simple DoS attacks. The default value of NR_FILE*2 is adjusted depending on the memory in the system. If this number is exceeded, the socket is closed and a warning is printed.
tcp_mem
This is a vector of 3 integers: [low, pressure, high]. These bounds are used by TCP to track its memory usage. The defaults are calculated at boot time from the amount of available memory.

low - TCP doesn't regulate its memory allocation when the number of pages it has allocated globally is below this number.

pressure - when the amount of memory allocated by TCP exceeds this number of pages, TCP moderates its memory consumption. This memory pressure state is exited once the number of pages allocated falls below the low mark.

high - the maximum number of pages, globally, that TCP will allocate. This value overrides any other limits imposed by the kernel.

tcp_orphan_retries
The maximum number of attempts made to probe the other end of a connection which has been closed by our end. The default value is 8.
tcp_reordering
The maximum a packet can be reordered in a TCP packet stream without TCP assuming packet loss and going into slow start. The default is 3. It is not advisable to change this number. This is a packet reordering detection metric designed to minimize unnecessary back off and retransmits provoked by reordering of packets on a connection.
tcp_retrans_collapse
Try to send full-sized packets during retransmit. This is enabled by default.
tcp_retries1
The number of times TCP will attempt to retransmit a packet on an established connection normally, without the extra effort of getting the network layers involved. Once we exceed this number of retransmits, we first have the network layer update the route if possible before each new retransmit. The default is the RFC specified minimum of 3.
tcp_retries2
The maximum number of times a TCP packet is retransmitted in established state before giving up. The default value is 15, which corresponds to a duration of approximately between 13 to 30 minutes, depending on the retransmission timeout. The RFC1122 specified minimum limit of 100 seconds is typically deemed too short.
tcp_rfc1337
Enable TCP behaviour conformant with RFC 1337. This is not enabled by default. When not enabled, if a RST is received in TIME_WAIT state, we close the socket immediately without waiting for the end of the TIME_WAIT period.
tcp_rmem
This is a vector of 3 integers: [min, default, max]. These parameters are used by TCP to regulate receive buffer sizes. TCP dynamically adjusts the size of the receive buffer from the defaults listed below, in the range of these sysctl variables, depending on memory available in the system.

min - minimum size of the receive buffer used by each TCP socket. The default value is 4K, and is lowered to PAGE_SIZE bytes in low memory systems. This value is used to ensure that in memory pressure mode, allocations below this size will still succeed. This is not used to bound the size of the receive buffer declared using SO_RCVBUF on a socket.

default - the default size of the receive buffer for a TCP socket. This value overwrites the initial default buffer size from the generic global net.core.rmem_default defined for all protocols. The default value is 87380 bytes, and is lowered to 43689 in low memory systems. If larger receive buffer sizes are desired, this value should be increased (to affect all sockets). To employ large TCP windows, the net.ipv4.tcp_window_scaling must be enabled (default).

max - the maximum size of the receive buffer used by each TCP socket. This value does not override the global net.core.rmem_max. This is not used to limit the size of the receive buffer declared using SO_RCVBUF on a socket. The default value of 87380*2 bytes is lowered to 87380 in low memory systems.

tcp_sack
Enable RFC2018 TCP Selective Acknowledgements. It is enabled by default.
tcp_stdurg
Enable the strict RFC793 interpretation of the TCP urgent-pointer field. The default is to use the BSD-compatible interpretation of the urgent-pointer, pointing to the first byte after the urgent data. The RFC793 interpretation is to have it point to the last byte of urgent data. Enabling this option may lead to interoperatibility problems.
tcp_synack_retries
The maximum number of times a SYN/ACK segment for a passive TCP connection will be retransmitted. This number should not be higher than 255. The default value is 5.
tcp_syncookies
Enable TCP syncookies. The kernel must be compiled with CONFIG_SYN_COOKIES. Send out syncookies when the syn backlog queue of a socket overflows. The syncookies feature attempts to protect a socket from a SYN flood attack. This should be used as a last resort, if at all. This is a violation of the TCP protocol, and conflicts with other areas of TCP such as TCP extensions. It can cause problems for clients and relays. It is not recommended as a tuning mechanism for heavily loaded servers to help with overloaded or misconfigured conditions. For recommended alternatives see tcp_max_syn_backlog, tcp_synack_retries, tcp_abort_on_overflow.
tcp_syn_retries
The maximum number of times initial SYNs for an active TCP connection attempt will be retransmitted. This value should not be higher than 255. The default value is 5, which corresponds to approximately 180 seconds.
tcp_timestamps
Enable RFC1323 TCP timestamps. This is enabled by default.
tcp_tw_recycle
Enable fast recycling of TIME-WAIT sockets. It is not enabled by default. Enabling this option is not recommended since this causes problems when working with NAT (Network Address Translation).
tcp_window_scaling
Enable RFC1323 TCP window scaling. It is enabled by default. This feature allows the use of a large window (> 64K) on a TCP connection, should the other end support it. Normally, the 16 bit window length field in the TCP header limits the window size to less than 64K bytes. If larger windows are desired, applications can increase the size of their socket buffers and the window scaling option will be employed. If tcp_window_scaling is disabled, TCP will not negotiate the use of window scaling with the other end during connection setup.
tcp_wmem
This is a vector of 3 integers: [min, default, max]. These parameters are used by TCP to regulate send buffer sizes. TCP dynamically adjusts the size of the send buffer from the default values listed below, in the range of these sysctl variables, depending on memory available.

min - minimum size of the send buffer used by each TCP socket. The default value is 4K bytes. This value is used to ensure that in memory pressure mode, allocations below this size will still succeed. This is not used to bound the size of the send buffer declared using SO_SNDBUF on a socket.

default - the default size of the send buffer for a TCP socket. This value overwrites the initial default buffer size from the generic global net.core.wmem_default defined for all protocols. The default value is 16K bytes. If larger send buffer sizes are desired, this value should be increased (to affect all sockets). To employ large TCP windows, the sysctl variable net.ipv4.tcp_window_scaling must be enabled (default).

max - the maximum size of the send buffer used by each TCP socket. This value does not override the global net.core.wmem_max. This is not used to limit the size of the send buffer declared using SO_SNDBUF on a socket. The default value is 128K bytes. It is lowered to 64K depending on the memory available in the system.

SOCKET OPTIONS

To set or get a TCP socket option, call getsockopt(2) to read or setsockopt(2) to write the option with the option level argument set to SOL_TCP. In addition, most SOL_IP socket options are valid on TCP sockets. For more information see ip(7).

TCP_CORK
If set, don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. This option cannot be combined with TCP_NODELAY. This option should not be used in code intended to be portable.
TCP_DEFER_ACCEPT
Allows a listener to be awakened only when data arrives on the socket. Takes an integer value (seconds), this can bound the maximum number of attempts TCP will make to complete the connection. This option should not be used in code intended to be portable.
TCP_INFO
Used to collect information about this socket. The kernel returns a struct tcp_info as defined in the file /usr/include/linux/tcp.h. This option should not be used in code intended to be portable.
TCP_KEEPCNT
The maximum number of keepalive probes TCP should send before dropping the connection. This option should not be used in code intended to be portable.
TCP_KEEPIDLE
The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes, if the socket option SO_KEEPALIVE has been set on this socket. This option should not be used in code intended to be portable.
TCP_KEEPINTVL
The time (in seconds) between individual keepalive probes. This option should not be used in code intended to be portable.
TCP_LINGER2
The lifetime of orphaned FIN_WAIT2 state sockets. This option can be used to override the system wide sysctl tcp_fin_timeout on this socket. This is not to be confused with the socket(7) level option SO_LINGER. This option should not be used in code intended to be portable.
TCP_MAXSEG
The maximum segment size for outgoing TCP packets. If this option is set before connection establishment, it also changes the MSS value announced to the other end in the initial packet. Values greater than the (eventual) interface MTU have no effect. TCP will also impose its minimum and maximum bounds over the value provided.
TCP_NODELAY
If set, disable the Nagle algorithm. This means that segments are always sent as soon as possible, even if there is only a small amount of data. When not set, data is buffered until there is a sufficient amount to send out, thereby avoiding the frequent sending of small packets, which results in poor utilization of the network. This option cannot be used at the same time as the option TCP_CORK.
TCP_QUICKACK
Enable quickack mode if set or disable quickack mode if cleared. In quickack mode, acks are sent immediately, rather than delayed if needed in accordance to normal TCP operation. This flag is not permanent, it only enables a switch to or from quickack mode. Subsequent operation of the TCP protocol will once again enter/leave quickack mode depending on internal protocol processing and factors such as delayed ack timeouts occurring and data transfer. This option should not be used in code intended to be portable.
TCP_SYNCNT
Set the number of SYN retransmits that TCP should send before aborting the attempt to connect. It cannot exceed 255. This option should not be used in code intended to be portable.
TCP_WINDOW_CLAMP
Bound the size of the advertised window to this value. The kernel imposes a minimum size of SOCK_MIN_RCVBUF/2. This option should not be used in code intended to be portable.

IOCTLS

These ioctls can be accessed using ioctl(2). The correct syntax is:

int value;
error = ioctl(tcp_socket, ioctl_type, &value);
SIOCINQ
Returns the amount of queued unread data in the receive buffer. Argument is a pointer to an integer. The socket must not be in LISTEN state, otherwise an error (EINVAL) is returned.
SIOCATMARK
Returns true when the all urgent data has been already received by the user program. This is used together with SO_OOBINLINE. Argument is an pointer to an integer for the test result.
SIOCOUTQ
Returns the amount of unsent data in the socket send queue in the passed integer value pointer. The socket must not be in LISTEN state, otherwise an error (EINVAL) is returned.

ERROR HANDLING

When a network error occurs, TCP tries to resend the packet. If it doesn't succeed after some time, either ETIMEDOUT or the last received error on this connection is reported.

Some applications require a quicker error notification. This can be enabled with the SOL_IP level IP_RECVERR socket option. When this option is enabled, all incoming errors are immediately passed to the user program. Use this option with care - it makes TCP less tolerant to routing changes and other normal network conditions.  

NOTES

When an error occurs doing a connection setup occurring in a socket write SIGPIPE is only raised when the SO_KEEPALIVE socket option is set.

TCP has no real out-of-band data; it has urgent data. In Linux this means if the other end sends newer out-of-band data the older urgent data is inserted as normal data into the stream (even when SO_OOBINLINE is not set). This differs from BSD based stacks.

Linux uses the BSD compatible interpretation of the urgent pointer field by default. This violates RFC1122, but is required for interoperability with other stacks. It can be changed by the tcp_stdurg sysctl.  

ERRORS

EPIPE
The other end closed the socket unexpectedly or a read is executed on a shut down socket.
ETIMEDOUT
The other end didn't acknowledge retransmitted data after some time.
EAFNOTSUPPORT
Passed socket address type in sin_family was not AF_INET.

Any errors defined for ip(7) or the generic socket layer may also be returned for TCP.  

BUGS

Not all errors are documented.
IPv6 is not described.  

VERSIONS

Support for Explicit Congestion Notification, zerocopy sendfile, reordering support and some SACK extensions (DSACK) were introduced in 2.4. Support for forward acknowledgement (FACK), TIME_WAIT recycling, per connection keepalive socket options and sysctls were introduced in 2.3.

The default values and descriptions for the sysctl variables given above are applicable for the 2.4 kernel.  

AUTHORS

This man page was originally written by Andi Kleen. It was updated for 2.4 by Nivedita Singhvi with input from Alexey Kuznetsov's Documentation/networking/ip-sysctls.txt document.  

SEE ALSO

socket(7), socket(2), ip(7), bind(2), listen(2), accept(2), connect(2), sendmsg(2), recvmsg(2), sendfile(2), sysctl(2), getsockopt(2).

RFC793 for the TCP specification.
RFC1122 for the TCP requirements and a description of the Nagle algorithm.
RFC1323 for TCP timestamp and window scaling options.
RFC1644 for a description of TIME_WAIT assassination hazards.
RFC2481 for a description of Explicit Congestion Notification.
RFC2581 for TCP congestion control algorithms.
RFC2018 and RFC2883 for SACK and extensions to SACK.

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-11-01 13:46:50

中文mantac

2011-08-25 16:55:26

gets中文man

2011-08-25 15:49:02

freopen中文man

2011-08-25 16:00:56

fflush中文man

2011-08-25 16:08:55

fsetpos中文man

2011-08-25 15:33:18

exit中文man

2011-08-25 10:55:37

services中文man

2011-08-25 09:35:26

units中文man

2011-08-24 13:57:35

DECLARE中文man

2011-08-11 15:28:43

ali中文man

2011-08-23 17:24:11

userdel中文man

2011-08-23 17:33:22

rdev中文man

2011-08-23 18:05:21

ABORT中文man

2011-08-18 19:15:25

group中文man

2011-08-23 10:17:54

bdflush中文man

2011-08-23 10:48:03

exportfs中文man
点赞
收藏

51CTO技术栈公众号