Synchronizing reading and writing with synchronous NamedPipes
- by Mike Trader
A Named Pipe Server is created with
hPipe = CreateNamedPipe( zPipePath,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_WAIT | PIPE_READMODE_BYTE,
PIPE_UNLIMITED_INSTANCES,
8192, 8192, NMPWAIT_USE_DEFAULT_WAIT, NULL)
Then we immediately call:
ConnectNamedPipe( hPipe, BYVAL %NULL )
Which blocks until the client connects.
Then we proceed directly to ReadFile( hPipe, ...
The problem is that it takes the Client takes a finite amount of time to prepare and write all the fcgi request parameters. This has usually not completed before the Pipe Server performs its ReadFile(). The Read file operation thus finds no data in the pipe and the process fails.
Is there a mechanism to tell when a Write() has occurred/finished after a client has connected to a NamedPipe?
If I had control of the Client process, I could use a common Mutex, but I don't, and I really do not want to get into I/O completion ports just to solve this problem!
I can of course use a simple timer to wait 60m/s or so which is usually plenty of time for the wrote to complete, but that is a horrible hack.