I have a named pipe server, similar to the MSDN sample, at http://msdn.microsoft.com/en-us/library/windows/desktop/aa365588(v=vs.85).aspx and would like to allow clients to send a message "exit" which causes the server to stop gracefully.
So, in "InstanceThread ()", if a special message is received, I would like to stop the server.
I tried to stop the ConnectNamedPipe () call in the main thread from a separate thread for "InstanceThread ()" by closing the channel handle, but this will not work.
I already tried different things, including closing the shared channel, exiting directly from the InstanceThread instance ... but none of them call ConnectNamedPipe () to stop.
I played with SetNamedPipeHandleState (), but it makes implementation very difficult, and using overlapped I / O seems redundant for this simple requirement.
So, is there an easier way to return ConnectNamedPipe () when the server process should be stopped and not wait endlessly for client connections?
source share