如何在 Windows 中重复读取 NamedPipe?
How is it possible to repeatedly read from a NamedPipe in Windows?
如何在 Windows 中重复读取 NamedPipe?如果我在另一个 ReadFile() 函数之后有一个 ReadFile() 函数,我收到一个 109 错误,说它无法打开管道。
当然这是可能的,需要在你的管道连接后直到断开。 109 这是 ERROR_BROKEN_PIPE
- 当另一端通过调用 CloseHandle
关闭管道句柄时,您在 ReadFile
中遇到了这个错误。在这种情况下,您需要调用 DisconnectNamedPipe
and then wait for new client by call ConnectNamedPipe
. after connection is complete - you need just call ReadFile
, in read completion again call ReadFile
and so on until disconnect - some error returned. if you got error ERROR_PIPE_NOT_CONNECTED
in ReadFile
(just or in completion) this mean that remote end call DisconnectNamedPipe
- your pipe already disconnected, so you can skip call to DisconnectNamedPipe
and just call ConnectNamedPipe
。
如何在 Windows 中重复读取 NamedPipe?如果我在另一个 ReadFile() 函数之后有一个 ReadFile() 函数,我收到一个 109 错误,说它无法打开管道。
当然这是可能的,需要在你的管道连接后直到断开。 109 这是 ERROR_BROKEN_PIPE
- 当另一端通过调用 CloseHandle
关闭管道句柄时,您在 ReadFile
中遇到了这个错误。在这种情况下,您需要调用 DisconnectNamedPipe
and then wait for new client by call ConnectNamedPipe
. after connection is complete - you need just call ReadFile
, in read completion again call ReadFile
and so on until disconnect - some error returned. if you got error ERROR_PIPE_NOT_CONNECTED
in ReadFile
(just or in completion) this mean that remote end call DisconnectNamedPipe
- your pipe already disconnected, so you can skip call to DisconnectNamedPipe
and just call ConnectNamedPipe
。