I'm working on a project (SourceForge, AMaMP) that involves using pipes for communication. Currently, the connection is checked to see if it's alive by taking a peek (PeekNamedPipe) at it. I was under the impression that if it wasn't connected, checking it should return 0 and GetLastError should return 109 (The pipe has been ended). If there's data in it, it seemed that it wouldn't return 0. So I drain the pipe by reading (ReadFile) all the data from it and then peeking at it again. The return value is not 0 all the time so for some reason, even though the program at the other end has ended, the code insists that the pipe is still valid.
In short, I want a method of verifying that the connection is still alive, perhaps some way of validating the handle to the pipe?