Posted on 2010-09-04 11:14
tiger 阅读(1705)
评论(0) 编辑 收藏 引用
int fd[2];
int nPipeReadFlag = 0;
fd[0] = -1;
fd[2] = -1;
if ((-1 == pipe(fd)) || (-1 == fd[0]) || (-1 == fd[1]))
{
SK_ERROR(("Create pipe failed!"));
return;
}
//以下代码设置读管道为非阻塞。设置写管道等类似,其他读写代码等一样
nPipeReadFlag = fcntl(fd[0], F_GETFL, 0);
nPipeReadFlag |= O_NONBLOCK;
if (fcntl(fd[0], F_SETFL, nPipeReadFlag) < 0)
{
SK_ERROR(("set read pipe flaf failed!"));
return;
}