Skip to content

Instantly share code, notes, and snippets.

@pk13610
Last active August 29, 2015 14:06
Show Gist options
  • Save pk13610/25978b75ac0541df46eb to your computer and use it in GitHub Desktop.
Save pk13610/25978b75ac0541df46eb to your computer and use it in GitHub Desktop.
pipe 操作注意事项
title tags notebook
pipe 操作注意事项.md
Code
default

引入:

微博上的一个吐槽

关于tcp send 怎么直到对端收到多少字节,为什么不在协议层保证,而需要接收代码判断并返回ack。

这个解释:

  • 收到和已经处理不同
  • 传输层和应用层协议功能不同(具体传输层协议是否保证需要查书???)

恢复中有人吐槽云风的skynet库对 pipe.write 的返回值不做判断,云风回应的是write的buff是 PIPE_BUF 时,为元子操作。

以下是云风提供的pipe的man页面的说明的理解:

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

pipe和fifo

都是管道用于多线程通信,fifo是命名管道,他们的建立方式不同,使用方式相同。

pipe

[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链接

fifo

由mkfifo(pathname) 生成,open()打开(with O_RDONLY,O_WRONLY flay),pathname不代表具体文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment