当前位置:网站首页>Socket [5] - struct linker usage
Socket [5] - struct linker usage
2022-06-11 07:49:00 【A small snail in a big city】
List of articles
Preface
Linux Next tcp Call when the link is broken close() function , There are two ways of graceful disconnection and forced disconnection .
One 、 How to set the way to disconnect
By setting socket A descriptor linger Structure properties linger The structure data structure is as follows :
#include <arpa/inet.h>
struct linger{
int l_onoff;
int l_linger;
};
Two 、 Three disconnection modes
l_onoff=0;l_lingerIgnorecloseReturn immediately , The bottom layer will release resources after sending the unsent data , namelyExit gracefully.l_onoff !=0;l_linger = 0close()Go back to , But it will not send unfinished data , But throughRESTThe package is forced to closesocketThe descriptor , namelyForced exitl_onoff !=0;l_linger > 0closeNot immediately back , The kernel will delay for some time , This time is determined byl_lingerThe value of . If the time-out period expires , Sending unsent data ( IncludeFINpackage ) And get confirmation from the other end ,close()Will return correct ,socketThe descriptorElegancesign out . otherwise ,close()The error value will be returned directly , Unsent data loss ,socketDescriptor is forced to exit . It should be noted that , If socket Descriptor is not set to non blocking , beclose()Will directly return the value .
3、 ... and 、 The specific use
struct linger ling = {
0, 0};
setsockopt(socketfd, SOL_SOCKET, SO_LINGER, (void*)&ling, sizeof(ling));

Network programming 4-socket Communication three handshakes and four waves
边栏推荐
- The solution of "no startup device" after running Bochs
- 【AtCoder1998】Stamp Rally(整体二分+并查集)
- Implementation of stack (C language)
- [codeforces1019e] raining season
- 【NOIP2016 D1T3】换教室(期望DP+Floyd)(究极思维陷阱!)
- Image processing operation record
- forEach 中 return 和 for 中 break
- About static keyword
- 2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]
- Matrix tree theorem
猜你喜欢

Tutoriel de démarrage bladed (vidéo)
![[codeforces1019e] raining season](/img/8e/4a96954ee7dae5f81eaae05b5a075b.png)
[codeforces1019e] raining season

The solution of "no startup device" after running Bochs
![20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] &](/img/90/99356e679a52890a0b88068d082bbe.jpg)
20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track

Collation of basic knowledge of intermediate development of Andrews (for interview)

Flask页面的分页

C language - growth diary-04- preliminary exploration of local variables (local variables)
![2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]](/img/4d/a67a63d2c4eb80c98315c3057b01b9.jpg)
2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]

Bladed入門教程(視頻)

空间几何
随机推荐
Bladed入门教程(视频)
C# 微信上传Form-data
[poj3691] DNA repair (AC automata +dp)
You got 8K in the 3-year function test, but you were actually pretending to work hard
Zero foundation self-study SQL course | union joint query
Implementation of queue (C language)
Long dialogue in June 2017
C language - Growth Diary -03- function definition and function prototype declaration
Semiconductor memory classification
134. 加油站
放大镜子效果图
【案例解读】医疗单据OCR识别助力健康险智能理赔
Matrix tree theorem
【AtCoder1983】BBQ Hard (组合数+巧妙模型转化)
Wc2020 course selection
Rabin Miller prime test
Flask页面的分页
Modular linear equations (Chinese remainder theorem + general solution)
[untitled] Weng_ C lesson 1
二本畢業,銀行外包測試工作 4 個月有餘。聊聊一些真實感受 ...