PeekNamedPipe(
tmp_pipe, // __in HANDLE hNamedPipe,
NULL, // __out_opt LPVOID lpBuffer,
0, // __in DWORD nBufferSize,
NULL, // __out_opt LPDWORD lpBytesRead,
&totalBytesAvailable, // __out_opt LPDWORD lpTotalBytesAvail,
NULL // __out_opt LPDWORD lpBytesLeftThisMessage
);
我已将字节写入其他地方的管道,但 totalBytesAvailable 始终为 0
,为什么?
最佳答案
我发现在 Windows 中,如果您在调用 ReadFile
之前调用 PeekNamedPipe
,它将始终返回零字节,即使实际上有字节要读取也是如此。您必须调用 ReadFile
,然后调用 PeekNamedPipe
,并继续循环直到 PeekNamedPipe
返回零字节。
我注意到,即使在这些情况下,有时 PeekNamedPipe
也会返回零字节,即使还有字节要获取也是如此。一定是时间问题。发件人必须在每条消息前加上字节数。唉……
关于c - PeekNamedPipe 总是为 totalBytesAvailable 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3673190/