【问题标题】:How to: Monitor progress of data in a pipe?如何:监控管道中数据的进度?
【发布时间】:2010-08-09 21:03:48
【问题描述】:

有一个 1MB 的管道:

if (0 == CreatePipe(&hRead,&hWrite,0,1024*1024))
{
printf("CreatePipe failed\n");
return success;
}   

一次发送 4000 个字节 (bytesReq = 4000)

while ((bytesReq = (FileSize - offset)) != 0)
{


//Send data to Decoder.cpp thread, converting to human readable CSV
        if ( (0 == WriteFile(hWrite,
                               readBuff,
                               bytesReq,
                               &bytesWritten,
                               0) ) || 
                               (bytesWritten != bytesReq) )
        {
             printf("WriteFile failed error = %d\n",GetLastError());
             break;
        } 

// Would like to update a status box with the amount of data in the pipe.
I would like to know if and how often it is getting full....



}  

4 个字节在管道另一端的另一个线程中读取。

【问题讨论】:

    标签: windows multithreading winapi visual-c++ pipe


    【解决方案1】:

    在读取 4 个字节之前,您可以使用 PeekNamedPipe 读取可用字节

    【讨论】:

    • 不确定这告诉我管道的当前容量:“如果缓冲区大小为零,则根据需要分配缓冲区”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 1970-01-01
    • 2022-08-02
    • 2021-06-23
    相关资源
    最近更新 更多