connection socket pool
时间:2010-04-10 来源:xiaosuo
测试代码:
#include <stdio.h> |
以下是抓包的输出:
# tcpdump -i lo -n tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes 22:43:17.608723 IP 192.168.235.10.60438 > 192.168.235.10.22: S 3365801819:3365801819(0) win 32792 <mss 16396,sackOK,timestamp 21687344 0,nop,wscale 5> 22:43:17.609661 IP 192.168.235.10.22 > 192.168.235.10.60438: S 3378619916:3378619916(0) ack 3365801820 win 32768 <mss 16396,sackOK,timestamp 21687345 21687344,nop,wscale 5> 22:43:17.609690 IP 192.168.235.10.60438 > 192.168.235.10.22: . ack 1 win 1025 <nop,nop,timestamp 21687345 21687345> 22:43:17.610715 IP 192.168.235.10.60438 > 192.168.235.10.22: R 1:1(0) ack 1 win 1025 <nop,nop,timestamp 21687346 21687345> 22:43:17.613609 IP 192.168.235.10.60439 > 192.168.235.10.22: S 3365834590:3365834590(0) win 32792 <mss 16396,sackOK,timestamp 21687349 0,nop,wscale 5> 22:43:17.614335 IP 192.168.235.10.22 > 192.168.235.10.60439: S 3372878782:3372878782(0) ack 3365834591 win 32768 <mss 16396,sackOK,timestamp 21687350 21687349,nop,wscale 5> 22:43:17.614351 IP 192.168.235.10.60439 > 192.168.235.10.22: . ack 1 win 1025 <nop,nop,timestamp 21687350 21687350> 22:43:17.614633 IP 192.168.235.10.60439 > 192.168.235.10.22: F 1:1(0) ack 1 win 1025 <nop,nop,timestamp 21687350 21687350> 22:43:17.617225 IP 192.168.235.10.22 > 192.168.235.10.60439: . ack 2 win 1024 <nop,nop,timestamp 21687353 21687350> 22:43:17.729908 IP 192.168.235.10.22 > 192.168.235.10.60439: P 1:22(21) ack 2 win 1024 <nop,nop,timestamp 21687465 21687350> 22:43:17.729943 IP 192.168.235.10.60439 > 192.168.235.10.22: R 3365834592:3365834592(0) win 0 |
我们尽量在收到对方的FIN包,也就是read(2)等返回0的时候再调用connect(AF_UNSPEC)关闭连接,防止造成误会。
可能的应用:反向HTTP代理中,由代理服务器发往HTTP服务器的连接。