当前位置:网站首页>How to skip time when closing a socket connection_ Wait status of wait
How to skip time when closing a socket connection_ Wait status of wait
2022-06-29 02:50:00 【Hello,C++!】
Cause analysis :
socket It will not be retracted immediately after closing , But to experience a TIME_WAIT The stage of .windows You can reach up to 4 minute . Rebinding this port at this time will cause an error .
Mode one :
Set up SO_REUSEADDR
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
return -1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
close(fd);
return -1;
}
Mode two :
stay closesocket When , Use setsockopt Set up SO_DONTLINGER.
int z; /* Status code*/
int s; /* Socket s */
struct linger so_linger;
...
so_linger.l_onoff = TRUE;
so_linger.l_linger = 30; // 30 Time out of seconds
z = setsockopt(s,
SOL_SOCKET,
SO_LINGER,
&so_linger,
sizeof so_linger);
if ( z )
perror("setsockopt(2)");
this l Two methods can be skipped TIME_WAIT The stage of , After the client restarts, it can connect quickly . This setting is usually used to enhance the robustness of network programs .
边栏推荐
猜你喜欢

Some tests on complementary wasm environment

LeetCode 每日一题——324. 摆动排序 II

PWN新手入门Level0
![[linear algebra] 1.1 second and third order determinants](/img/ea/70b59c64d3287a887e371a9181fe45.png)
[linear algebra] 1.1 second and third order determinants

對補wasm環境的一些測試

allegro对走好的线取消走线的方法
![[Shangshui Shuo series] the simplest subtitle configuration](/img/22/7e0bcb489d0f2d35c7fe3248ad3419.png)
[Shangshui Shuo series] the simplest subtitle configuration

Pvcreate ASM disk causes abnormal recovery of ASM disk group - sparing separation

LabVIEW generate application (exe) and installer

sql连续登录问题
随机推荐
PWN新手入门Level0
音响是如何把微弱声音放大呢
MySQL queries the data of today, yesterday, this week, last week, this month, last month, this quarter, last quarter, this year, last year
mark
allegro设置网络飞线以及网络颜色的方法
Today's sleep quality record 82 points
Ctfhub web SQL injection - integer injection
均贫富
双击事件与单击事件的那些事
Apache does not parse PHP files, but directly displays the source code
Use photoshop2022 to create a wonderful gradient effect for pictures
Centos7 installation php7.2
深入解析 Apache BookKeeper 系列:第三篇——读取原理
On the fact that lambda expressions cannot handle recursion
There's a mystery behind the little login
Ctfhub web password weak password
Relations EMC, EMI, EMS
Introduction to openresty
String attribute exercise
1110: 最近共同祖先(函数专题)