tcp连接在断网后的恢复能力
int nonagle)
1512 { 1513 struct sk_buff *skb = sk->sk_send_head; 1514 1515 if (skb) { 1516 if (!tcp_skb_is_last(sk, skb)) 1517 nonagle = TCP_NAGLE_PUSH; 1518 if (!tcp_snd_test(tp, skb, cur_mss, nonagle) || 1519 tcp_write_xmit(sk, nonagle)) 1520 tcp_check_probe_timer(sk, tp); 1521 } 1522 tcp_cwnd_validate(sk, tp); 1523 } 1518行的这个"||"符号很讲究,只有tcp_snd_test返回1了,tcp_write_xmit才会被执行.我们先看tcp_snd_test [net/ipv4/tcp.h --> tcp_snd_test] 1452 static __inline__ int tcp_snd_test(struct tcp_opt *tp, struct sk_buff *skb, 1453 unsigned cur_mss, int nonagle) 1454 { 1455 int pkts = tcp_skb_pcount(skb); 1456 1457 if (!pkts) { 1458 tcp_set_skb_tso_segs(skb, tp->mss_cache_std); 1459 pkts = tcp_skb_pcount(skb); 1460 } 1461 1462 /* RFC 1122 - section 4.2.3.4 1463 * 1464 * We must queue if 1465 * 1466 * a) The right edge of this frame exceeds the window 1467 * b) There are packets in flight and we have a small segment 1468 * [SWS avoidance and Nagle algorithm] 1469 * (part of SWS is done on packetization) 1470 * Minshall version sounds: there are no _small_
1471 * segments in flight. (tcp_nagle_check) 1472 * c) We have too many packets ''in flight'' 1473 * 1474 * Don''t use the nagle rule for urgent data (or 1475 * for the final FIN -DaveM). 1476 * 1477 * Also, Nagle rule does not apply to frames, which 1478 * sit in the middle of queue (they have no chances 1479 * to get new data) and if room at tail of skb is 1480 * not enough to save something seriously (<32 for now). 1481 */ 1482 1483 /* Don''t be strict about the congestion window for the 1484 * final FIN frame. -DaveM 1485 */ 1486 return (((nonagle&TCP_NAGLE_PUSH) || tp->urg_mode 1487 || !tcp_nagle_check(tp, skb, cur_mss, nonagle)) && 1488 (((tcp_packets_in_flight(tp) (pkts-1)) < tp->snd_cwnd) || 1489 (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN)) && 1490 !after(TCP_SKB_CB(skb)->end_seq, tp->snd_una tp->snd_wnd)); 1491 } 这个函数的注释比实现代码还多,return后面复杂的条件判断可以被拆开:其实是三个条件的“and”操作,我们看第二个条件,就是: (((tcp_packets_in_flight(tp) (pkts-1)) < tp->snd_cwnd) || (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN)) 其中,tcp_packets_in_flight是指正在“飞行中”的packet数,也就是正在网络上的包数,它的计算方法是: 发送过一次的包数 重发过的包数 - 队列中存留的包数 而TCPCB_FLAG_FIN是指一端 |
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |