TCP shutdown VS HTTP KeepAlive

本文讨论了在进行HTTP客户端性能测试时遇到的多线程、Socket关闭与数据传输间断的问题。通过使用Wireshark进行分析,揭示了在关闭写端Socket后,服务器可能停止进一步内容发送的现象。分析了HTTP/1.1中Connection:KeepAlive和Connection:Close两种状态下的行为,并最终借助Wireshark找到了问题原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Building an HTTP client for some performance testing purposes. Multiple sockets, I/O multiplexing, two threads. One sender pushing pipelined requests and one receiver dragging all server responses

In order to simplify program logic I tried to shutdown the writer end after all requests has been sent

shutdown (s, SHUT_WR);

at the same time responses are being read from the other thread. I thought that since I used SHUT_WR, the receiver should be able to get data as nothing happened.

It didn't work. Data stops at half way.

I tried with HTTP/1.1 Connection: KeepAlive, Connection: Close. Neither worked out the trick. Down stream stops at ~60k every time.

After some sharp pointers from my old friend Bluntblade, Wireshark came into rescue.


When the shutdown call is triggered, client sends an FIN packet to server. Upon receiving this packet, server may stop serving further content.

D'm it!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值