PDA

View Full Version : Named Pipes in C++


code2K
10-17-2006, 02:21 PM
Hi, I need to close the server end of a Named Pipe gracefully when the server is waiting on ReadFile() in blocking mode. Have tried just doing a disconnect() and CloseHandle() but the pipe just stays open requiring a reboot to free it. Would be grateful for any advice.

donBerto
10-17-2006, 03:06 PM
In a blocking context, I'm not sure you can gracefully terminate a named pipe, other than sending the pipe a message which it can then use to shut itself down.

Alternatively, you can use a named pipe in a non-blocking manner and use polling to determine events. In the case where the named pipe is no longer needed, you can simply shut it down with no 'hang up' as it is non-blocking.

hope that helps.

code2K
10-17-2006, 09:27 PM
Thanks for the reply. Thats given me food for thought. I was hoping I might be able to shut it down while its waiting on a ReadFile() but perhaps not. I have to use the pipe in blocking mode and so this a tricky problem. Perhaps I can use WaitForMultipleObjects() and have the pipe and an event object waited-on and use the event object as the trigger to close the pipe?? Gonna try. Will update if succesful..