I'm writing a driver that communicates with a userland application through a named pipe. The userland application creates the named pipe by calling CreateNamedPipe() and then passes the pipe name to the driver by invoking an IOCTL. The driver then opens the pipe by calling ZwCreateFile().
The userland application then hits a loop that reads requests from the pipe, processes the requests and writes back the result to the pipe i.e.:
while(1) {
ReadFromPipe
ProcessRequest
WriteToPipe
}
The driver basically writes requests to the pipe and then directly reads back the answer:
WriteRequestToPipe
ReadAnswerFromPipe
My problem is that if the ReadAnswerFromPipe happens in the driver before the WriteToPipe happens in the application, ReadAnswerFromPipe never returns. So basically doing
WriteRequestToPipe
Sleep(10 seconds)
ReadAnswerFromPipe
fixes the problem.
Why am I seeing this?
Clarification: I'm using two different unidirectional pipes and the ReadAnswerFromPipe call is never returning although the application eventually successfully calls WriteToPipe...