title | tags | notebook | |
---|---|---|---|
pipe 操作注意事项.md |
|
default |
关于tcp send 怎么直到对端收到多少字节,为什么不在协议层保证,而需要接收代码判断并返回ack。
这个解释:
- 收到和已经处理不同
- 传输层和应用层协议功能不同(具体传输层协议是否保证需要查书???)
恢复中有人吐槽云风的skynet库对 pipe.write 的返回值不做判断,云风回应的是write的buff是 PIPE_BUF 时,为元子操作。
http://man7.org/linux/man-pages/man7/pipe.7.html
都是管道用于多线程通信,fifo是命名管道,他们的建立方式不同,使用方式相同。
[http://man7.org/linux/man-pages/man2/pipe.2.html
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h> /* Obtain O_* constant definitions */
#include <unistd.h>
int pipe(int pipefd[2]);
int pipe2(int pipefd[2], int flags);
返回两个文件描述符,表写读
pipefd
- fdw = pipefd[0]
- fdr = pipefd[1]
flags
- flags = 0 时,二者相同
- flags = O_CLOEXEC,close-on-exec
- flags = O_DIRECT,performs I/O in "packet" mode
- flags = O_NONBLOCK,same as fcntl(2)
详情见man链接
由mkfifo(pathname) 生成,open()打开(with O_RDONLY,O_WRONLY flay),pathname不代表具体文件