Re: Problem in Interprocess Communication using anonymous pipes, when
On Mon, 30 Oct 2006 13:59:01 -0800, Vinayak
<Vinayak@discussions.microsoft.com> wrote:
When executed, WriteToPipe() works nicely, but in ReadFromPipe() the
processes get stuck, when the code reaches ReadFile() function. I guess it
happens due to scanf(). But I don't know how to solve it. Would anyone please
suggest me anything? I will be really grateful.
I don't have time at the moment to analyze the code, but two things to note
about anonymous pipes are:
1. ReadFile is a blocking call, and it won't return until there is input
available, or the write side of the pipe is closed.
2. ReadFile can return fewer than the requested number of bytes, and this
does not signify that you should stop reading from it. (One of your
comments claims otherwise.)
3. You shouldn't allow processes you start to inherit pipe handles they
don't need. For example, if your child process is to read from a pipe,
don't let it inherit the write handle for that pipe.
OK, so that's three things. Hopefully, one or more will help.
--
Doug Harrison
Visual C++ MVP