Breaking ReadFile() blocking - Named Pipe (Windows API)

后端 未结 7 691
广开言路
广开言路 2020-12-30 23:43

To simplify, this is a situation where a NamedPipe SERVER is waiting for a NamedPipe CLIENT to write to the pipe (using WriteFile())

The Windows API that is blocking

相关标签:
7条回答
  • 2020-12-31 00:06

    Just use SetNamedPipeHandleState function https://docs.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-setnamedpipehandlestate

    Use the PIPE_NOWAIT flag when calling this function.

    hNamedPipe should be the handle that returned from CreateFile function.

    After that, the call to ReadFile will not block the thread when no data available.

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