safe close tcp connection
https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable
http://stackoverflow.com/questions/8874021/close-socket-directly-after-send-unsafe
发送端代码
sock = socket(AF_INET, SOCK_STREAM, 0);
connect(sock, &remote, sizeof(remote));
write(sock, buffer, 1000000); // returns 1000000
shutdown(sock, SHUT_WR);
// 最后这一步要加个超时,防止接收端恶意发送数据
for(;;) {
res=read(sock, buffer, 4000);
if(res < 0) {
perror("reading");
exit(1);
}
if(!res)
break;
}
close(sock);
这么做的原因是
1. send 成功只是把数据放到了内核的发送缓冲区
2. 当调用 close 时,如果 TCP 的接收缓冲区内有数据,会导致发送 RST(而不是 FIN),并清空发送缓冲区。
最好接收端在应用层返回 ack 给发送端。TCP 并不是绝对可靠的
safe close tcp connection的更多相关文章
- TCP connection status
A TCP connection progresses through a series of states during its lifetime. The following diagram il ...
- linux上TCP connection timeout的原因查找
linux上TCP connection timeout的原因查找 好久没有写文章了, 今天解决了一个网络连接超时的问题, 记录以备查看. 最近在线上nginx经常出现输出connection tim ...
- TCP Connection Establishment and Termination
Three-Way Handshake The following scenario occurs when a TCP connection is established: The server m ...
- RT:How HTTP use TCP connection
In HTTP/0.9 (not used anymore), each request uses a separate TCP connection, and the end of a respon ...
- RabbitMQ问题解决:TCP connection succeeded but Erlang distribution failed
说明 本来是要先把Hystrix 仪表盘更完的,但是出现了Turbine.Dashboard.RabbitMQ整合实现监控. 所以先在学RabbitMq的基本操作,在安装过程中出现了 E:\Rabbi ...
- tcp connection
三次握手与四次挥手的原因 https://yq.aliyun.com/articles/7435?spm=5176.8091938.0.0.N4v33a linux里的backlog详解 tcp co ...
- Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
在Eclipse 调试 springside showcase项目中,tomcat报异常 Exception in thread "RMI TCP Connection(idle)" ...
- the age of the TCP connection TCP Slow Start
w防止网络过载和拥塞 HTTP The Definitive Guide The performance of TCP data transfer also depends on the age of ...
- A TCP connection is distinguished by four values
4个值唯一地定义一条TCP连接. HTTP The Definitive Guide A computer might have several TCP connections open at any ...
随机推荐
- 2018.11.01 NOIP训练 cost数(搜索+容斥原理)
传送门 唉考试的时候忘记剪倍数的枝了666666分滚粗. 其实就是一直取lcmlcmlcm搜索,然后容斥原理统计就行了. 代码
- Java 学习之集合类(Collections)
Collection(集合类) 我们是使用数组来保存数据,但是他的长度一旦创建,就已经确定了,当我们要动态传入穿值,数组就有些局限了,集合类就孕育而生:所谓集合,就是来保存,盛装数据,也可称为容器类: ...
- MES制造执行系统
mes : Manufacturing Execution System 制造执行系统 起因:ERP系统和底层设备之间出现了断层. 包括资源管理,生产调度,单元分配,生产跟踪,性能分析,文档管理,人 ...
- c# 得到list符合某条件的索引值,排序
请教,在List集合中怎么得到元素的索引值,参考:http://www.myexception.cn/c-sharp/385022.html 这个可以用来读取窗口的多个textbox控件中内容: -- ...
- vue的cli中引入css文件
在public文件中创建一个文件夹css,放进reset.css 在main.js中引入即可 import '../public/css/reset.css'就可以啦
- CodeForces 946D Timetable (DP)
题意:给定 n,m,K,表示某个人一个周有 n 天,每天有 m 节课,但是他可以跳过 K 节课,然后下面每行一个长度为 m 个01字符串,0 表示该人在这一小时没有课,1 表示该人在这一个小时有课,每 ...
- 【慕课网实战】Spark Streaming实时流处理项目实战笔记六之铭文升级版
铭文一级: 整合Flume和Kafka的综合使用 avro-memory-kafka.conf avro-memory-kafka.sources = avro-sourceavro-memory-k ...
- HTML5表单新属性
HTML5表单新属性 autofocus 自动聚焦 <input type="text" autofocus> placeholder占位文本 tel ...
- 【python-selenium】python-selenium安装配置
selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: * 免费,也不用再为破解QTP而大伤脑筋 * 小巧,对于不同的语 ...
- java基础-day28
第05天 MySQL 今日内容介绍 u 数据库的概述 u MySQL和SQLyog的安装和使用 u SQL语句 第1章 数据库的概述 1.1 数据库的概述 1.1.1 概述 l 什么是数据库 ...