What is an overlapped I/O alternative to WaitNamedPipe? What is an overlapped I/O alternative to WaitNamedPipe? windows windows

What is an overlapped I/O alternative to WaitNamedPipe?


WaitNamedPipe is completely useless, and will just use all the cpu if you specify a timeout and there's no server waiting for it.

Just call CreateFile over and over with a Sleep like you're doing, and move it to other threads as you see appropriate. There is no API alternative.

The only "benefit" WaitNamedPipe provides is if you want to know if you can connect to a named pipe but you explicitly don't want to actually open a connection. It's junk.

If you really want to be thorough, your only options are

  • Ensure that whatever program is opening the named pipe is always calling CreateNamedPipe again immediately after it's named pipe is connected to.
  • Have your program actually check if that program is running.
  • If your intent is really not to have additional connections, still call CreateNamedPipe, and when someone connects, tell them to go away until they're waited a given amount of time, the close the pipe.


Why can't the server just create more pipes? The performance hit in the scenario you describe isn't a problem if it is rare.

I.e. if there are usually enough pipes to go round what does it matter if you use CreateFile/Sleep instead of WaitForMultipleObjects? The performance hit will not matter.

I also have to question the need for overlapped IO in a client. How many servers is it communicating with at a time? If the answer is less than, say, 10 you could reasonably create a thread per connection.

Basically I am saying I think the reason there is no overlapped WaitforNamedPipe is because there is no reasonable use-case which requires it.


You can open the pipe file system at \\.\pipe\ and then use DeviceIoControl to send FSCTL_PIPE_WAIT.