首页 技术 正文
技术 2022年11月22日
0 收藏 560 点赞 3,023 浏览 950 个字

阅读 skynet 代码 socket_server 部分,发现对 socket 的写操作流程是这样的:

1. 各个服务(各线程)将数据写到 sendctrl_fd,这是一个 pipe 的 写端

2. ctrl_cmd 函数从 recvctrl_fd 读出数据,然后写到真正的 socketfd

在第一步中,多个线程向 sendctrl_fd 写数据,但是代码中并没有给 sendctrl_fd 加锁。

 static void
send_request(struct socket_server *ss, struct request_package *request, char type, int len) {
request->header[] = (uint8_t)type;
request->header[] = (uint8_t)len;
for (;;) {
int n = write(ss->sendctrl_fd, &request->header[], len+);
if (n<) {
if (errno != EINTR) {
fprintf(stderr, "socket-server : send ctrl command error %s.\n", strerror(errno));
}
continue;
}
assert(n == len+);
return;
}
}

经过各种搜索得出结论:

写 pipe 的数据大小如果小于等于 PIPE_BUF(4k),那么这个写操作是 atomic 的。如果超过了这个 PIPE_BUF,那就不能保证咯。。

http://stackoverflow.com/questions/4624071/pipe-buffer-size-is-4k-or-64k

https://docs.oracle.com/cd/E19683-01/806-6546/pipe6-7/index.html

http://man7.org/linux/man-pages/man7/pipe.7.html

http://stackoverflow.com/questions/9701757/when-to-use-pipes-vs-when-to-use-shared-memory

http://beej.us/guide/bgipc/output/html/singlepage/bgipc.html#pipes

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859