PeekNamedPipe始终为totalBytesAvailable返回0

编程入门 行业动态 更新时间:2024-10-28 16:27:27
本文介绍了PeekNamedPipe始终为totalBytesAvailable返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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,为什么?

I have written bytes to the pipe somewhere else,but totalBytesAvailable is always 0,why?

推荐答案

我发现在Windows中,如果在调用ReadFile之前先调用PeekNamedPipe,即使实际上有字节,它也将始终返回零字节.待阅读.您必须先调用ReadFile,然后调用PeekNamedPipe,并继续循环直到PeekNamedPipe返回零字节.

I have found that in Windows, if you call PeekNamedPipe before calling ReadFile, it will always return zero bytes, even if there are in fact bytes to be read. You have to call ReadFile, followed by PeekNamedPipe, and keep looping until PeekNamedPipe returns zero bytes.

我已经注意到,即使在这种情况下,即使还有字节要获取,有时PeekNamedPipe也会返回零字节.必须是时机.发送者将必须在每个消息的开头加上字节数. igh ...

I have noticed that even under these circumstances, sometimes PeekNamedPipe returns zero bytes even though there are bytes left to be gotten. Must be a timing thing. The sender is going to have to preface each message with a byte count. Sigh...

更多推荐

PeekNamedPipe始终为totalBytesAvailable返回0

本文发布于:2023-10-28 02:32:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PeekNamedPipe   totalBytesAvailable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!