PeekNamedPipe始终为totalBytesAvailable返回0 [英] PeekNamedPipe always returns 0 for totalBytesAvailable

查看:129
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆