0

I have a Named pipe process that uses Async communication, it is created by calling CreateNamedPipe with FILE_FLAG_OVERLAPPED, on the client process the pipe is opened using CreateFile with the same flag and connected with ConnectNamedPipe.

My question is if I can use the same named pipe for synchronized communication too? I am not sure since the documentation states that :

If hNamedPipe was opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not be NULL. It must point to a valid OVERLAPPED structure. If hNamedPipe was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function can incorrectly report that the connect operation is complete.

Does this mean the pipe must only be used for Async actions?

Thanks.

joepol
  • 744
  • 6
  • 22
  • 1
    [`WaitForSingleObject`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject) turns an asynchronous operation into a synchronous one. – IInspectable May 18 '22 at 15:49
  • 1
    synchronous I/O- this is asynchronous I/O + wait in place after I/O, if it return pending status, until complete. you can do this, but for what in this case use `FILE_FLAG_OVERLAPPED` flag ? in ay way you of course need pass correct pointer to `OVERLAPPED` if you use asynchronous handle – RbMm May 18 '22 at 18:52
  • @RbMm because the pipe being used is also used for async operations. Is the proper way to implement it is to have 2 handles, one for async and the second for sync communication? – joepol May 22 '22 at 09:41
  • no, wrong way have 2 handles and you can not do this. correct way always use async I/O and not wait in place. but if very want -no problem and wait in place after some I/O until it completed – RbMm May 22 '22 at 16:56

0 Answers0