我已经在其他地方将字节写入管道,但是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
发布评论