全部博文(41)
分类: LINUX
2009-07-30 15:15:57
tcp.c文件的tcp_select_window函数
978计划工作组
int tcp_select_window(struct sock *sk)
{
int new_window = sk->prot->rspace(sk);
if(sk->window_clamp)
new_window=min(sk->window_clamp,new_window);
/*
* Two things are going on here. First, we don't ever offer a
* window less than min(sk->mss, MAX_WINDOW/2). This is the
* receiver side of SWS as specified in RFC1122.
* Second, we always give them at least the window they
* had before, in order to avoid retracting window. This
* is technically allowed, but RFC1122 advises against it and
* in practice it causes trouble.
*
* Fixme: This doesn't correctly handle the case where
* new_window > sk->window but not by enough to allow for the
* shift in sequence space.
*/
if (new_window < min(sk->mss, MAX_WINDOW/2) || new_window < sk->window)
return(sk->window);
return(new_window);
}
用于填充TCP头的窗口大小,也就是struct tcphdr结构的window域。
new_window:新窗口大小,窗口大小即接收数据包的最大字节数。TCP首部的第15和16字节声明了本地窗口大小,远端发送的数据包字节数不能超过此值。
sk->prot->rspace(sk):取得接收缓冲区空闲区域的大小。
new_window=min(sk->window_clamp,new_window);
sk->window_clamp:0表示窗口非节制,非0表示窗口节制,窗口节制的情况下新窗口大小不能超过window_clamp的大小。
new_window=min(sk->window_clamp,new_window):取节制窗口和接收缓冲区空闲区域的最小值作为新窗口的值。
return(sk->window);
sk->mss:最大报文长度,mss = mtu – ip头 – tcp头。
MAX_WINDOW/2:
sk->window:原窗口尺寸,如果新窗口尺寸小于原窗口尺寸,那么就返回原窗口尺寸;这样做是遵循RFC793文档的不降低窗口大小值原则。