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

后端 未结 7 735
广开言路
广开言路 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-30 23:59

    Try this before ReadFile :

    BOOL WINAPI PeekNamedPipe(
      __in       HANDLE hNamedPipe,
      __out_opt  LPVOID lpBuffer,
      __in       DWORD nBufferSize,
      __out_opt  LPDWORD lpBytesRead,
      __out_opt  LPDWORD lpTotalBytesAvail,
      __out_opt  LPDWORD lpBytesLeftThisMessage
    );
    
    if(TotalBytesAvail > 0)
      ReadFile(....);
    

    -AV-

提交回复
热议问题