The function WaitNamedPipeallows a channel client application to synchronously wait for an available connection on a named channel server. Then you call CreateFileto open the channel as a client. Pseudocode:
// loop works around race condition with WaitNamedPipe and CreateFile
HANDLE hPipe;
while (true) {
if (WaitNamedPipe says connection is ready) {
hPipe = CreateFile(...);
if (hPipe ok or last error is NOT pipe busy) {
break; // hPipe is valid or last error is set
}
} else {
break; // WaitNamedPipe failed
}
}
The problem is that these are all blocking, synchronous calls. What is a good way to do this asynchronously? For example, I cannot find an API that uses overlapping I / O to do this. For example, for pipe servers, the function ConnectNamedPipeprovides options lpOverlappedthat allow asynchronous server wait for the client. The pipeline server can then call WaitForMultipleObjects and wait for the I / O operation or any other event to be sent to complete (for example, an event that signals a thread has been canceled, pending I / O and completion).
, , - WaitNamedPipe , . , CreateFile, , Sleep ( WaitNamedPipe). :
HANDLE hPipe;
while (true) {
hPipe = CreateFile(...);
if (hPipe not valid and pipe is busy) {
Sleep(100);
} else
break;
}
, . , - , , , .. , , Sleep , .
?