Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+;中实现管道缓冲读取的最佳方法是什么+;?_C++_Linux_Select_Pipe_Buffer - Fatal编程技术网

C++ 在C+;中实现管道缓冲读取的最佳方法是什么+;?

C++ 在C+;中实现管道缓冲读取的最佳方法是什么+;?,c++,linux,select,pipe,buffer,C++,Linux,Select,Pipe,Buffer,我正在监测选择循环中管道的读取端,并在数据可用时使用读取从中读取数据。我总是希望通过管道获得某种数据格式,该管道的类型为struct packet\u t。当select调用发出信号时,我的初始代码对文件描述符执行了以下操作: int read_packet(int fd) { struct packet_t pkt; int read_bytes = read(fd, &pkt, sizeof(pkt)); if (bytes_read <= 0)

我正在监测
选择
循环中管道的读取端,并在数据可用时使用
读取
从中读取数据。我总是希望通过管道获得某种数据格式,该管道的类型为
struct packet\u t
。当
select
调用发出信号时,我的初始代码对文件描述符执行了以下操作:

int
read_packet(int fd)
{
    struct packet_t pkt;

    int read_bytes = read(fd, &pkt, sizeof(pkt));
    if (bytes_read <= 0)
    {
        /* handle some sort of error */
        return -E_SOCK;
    }
    else if (bytes_read < sizeof(pkt))
    {
        /* return bad message format */
        return -E_BADMSG;
    }

    /* do something with the packet */
    return E_OK;
}
int
读取数据包(int fd)
{
结构数据包;
int read_bytes=read(fd,&pkt,sizeof(pkt));
如果(字节)被读取