C++ Windows Asynch IO Named Pipe first message not received

前端 未结 1 800
半阙折子戏
半阙折子戏 2021-01-17 05:02

Modified code from Named Pipe Server Using Overlapped I/O https://msdn.microsoft.com/en-us/library/windows/desktop/aa365603(v=vs.85).aspx

The server code is as follo

相关标签:
1条回答
  • 2021-01-17 05:41

    In the server's read loop, you are discarding any data that arrives asynchronously.

    After GetOverlappedResult() has reported that the pending I/O operation is complete, the buffer contains the data from that operation. You're ignoring that data and issuing a new read operation into the same buffer.

    The only reason you get any of the messages is that (on most runs) all four messages will be written into the pipe's internal buffer at the same time. The first message arrives asynchronously, so you miss it, but the remaining three messages are already in the pipe so those reads can complete immediately.

    0 讨论(0)
提交回复
热议问题