DisconnectEx调用要很久才返回

我喝多了 2020-09-18 10:25:08
DisconnectEx
同步调用 大约2分钟左右才返回, 这个就是传说中的TIME_WAIT吧
异步调用 GetQueuedCompletionStatus函数也是大约2分钟左右收到通知

效率好低, 有没有办法, 让DisconnectEx 立即就返回, 关闭套接字成功.

设置了
LINGER linger = { 1,0 };
::setsockopt(s, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));

但是不启作用. 还是要等待2分钟左右.

有大侠有办法么
...全文
139 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
an_bachelor 2020-09-19
  • 打赏
  • 举报
回复
Windows TCP reverts to a TIME_WAIT state subsequent to the closing of a connection. While in the TIME_WAIT state, a socket pair cannot be re-used. The TIME_WAIT period is configurable by modifying the following DWORD registry setting that represents the TIME_WAIT period in seconds.


HKEY_LOCAL_MACHINE\ System\ CurrentControlSet\ Services\ TCPIP\ Parameters\ TcpTimedWaitDelay

By default, the MSL is defined to be 120 seconds. The TcpTimedWaitDelay registry setting defaults to a value 240 seconds, which represents 2 times the maximum segment lifetime of 120 seconds or 4 minutes. However, you can use this entry to customize the interval. Reducing the value of this entry allows TCP to release closed connections faster, providing more resources for new connections. However, if the value is too low, TCP might release connection resources before the connection is complete, requiring the server to use additional resources to re-establish the connection. This registry setting can be set from 0 to 300 seconds.
我喝多了 2020-09-19
  • 打赏
  • 举报
回复
引用 2 楼 zgl7903 的回复:
直接 closesocket 不行?
closesocket 套接字不就是不能被重复利用了么, 网上都说不重用会降低性能
zgl7903 2020-09-19
  • 打赏
  • 举报
回复
直接 closesocket 不行?

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧