How should I stop a thread that is waiting on a
recvfrom. I used to send it a datagram on (via 127.0.0.1)
and then, as it was awake, gracefully close.
As of win XP sp2 this may not work (the firewall stops
my datagram).
Or is the secret not to call recvfrom unless you known
it will not block? if so what should I wait on?
many thanks in advance.
--
Roger
> Or is the secret not to call recvfrom unless you known
> it will not block? if so what should I wait on?
Why not select()? And put your socket in non-blocking
mode for it not to hang.
--gv
It's a thread with a single socket, so not much to select :)
but if I do that, how does the thread 'wait' for the next
time the select will work?
If I let the select block then I am back to the same
issue that I haf with recvfrom?
What am I missing?
--
Roger
When you want to end the thread that does the MSG_PEEK, kill the thread.
The call is TerminateThread(hThreadHandle, dwExitCode);
Call it from another portion of the program... you have to save the thread
handle so that you know what the value is
"BMG Support" <support (at) BusinessMailGateway.com> wrote in message
news:VA.000000a...@hostname.not.set.up...
Many thanks to both responders but I think we are all
missing the point. (TerminateThread will work but will
leak memory etc)
recvfrom
'blocking mode' exists to receive datagrams, which may at
any time stop arriving. So every app that ever does this
will have this as an architectural issue.
I suppose that the endless code snippets (examples) that
can be found everywhere that do this are ALL real unusable
but I find that conclusion a bit extreme.
So what am I missing - sob sob
--
Roger
"BMG Support" <support (at) BusinessMailGateway.com> wrote in message
news:VA.000000a...@hostname.not.set.up...
>
As I am using AFX it is AFX that reports an 8k leak of its bits that
created are in AfxCreateThread(). OK is it true that one could
call delete on the 'terminated' tread. BUT this screams
Danger, Will Robinson! Danger!
and as you so well point out TerminateThread is an inappropriate sledge
hammer to crack this nut. :)
But it is the only one I currently have :( :(
--
Roger
--
John Phillips
MVP - Windows SDK
"BMG Support" <support (at) BusinessMailGateway.com> wrote in message
news:VA.000000a...@hostname.not.set.up...
Peeking is also a pretty iffy solution. While the KB192599
(http://support.microsoft.com/default.aspx?scid=kb;en-us;192599) is
TCP-centric, some of the issues described apply to UDP as well.
--
John Phillips
MVP - Windows SDK
"PC" <u...@ipdaily.org> wrote in message
news:cgm46...@enews1.newsguy.com...
> Why not just use WSAEventSelect() (or WSAAsyncSelect())? Wait on a socket
> event handle, and another event handle which tells this thread to stop
> waiting for datagrams - wait with WaitForMultipleObjects().
I guess that my honest answer is because I had never heard of
"socket events".
{After a bit of reading}
I see that the missing bit in my head was the use of WSAEventSelect
to map, what I would call a 'socket state' to a waitable event.
Many thanks
--
Roger
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"BMG Support" <support (at) BusinessMailGateway.com> wrote in message
news:VA.000000a...@hostname.not.set.up...
>
> Well, calling closesocket from another thread is supposed
> to do the trick. Haven't you tried?
Well actually no! I had n't. I suppose as the documentation
does not say it can be called from any thread I assumed it
can't, almost nothing else can. [sigh]
Well we got there in the end.
Many thanks
--
Roger
> Well, calling closesocket from another thread is supposed
> to do the trick. Haven't you tried?
I does not work :( - I wrote to soon (a moment ago)
--
Roger
Did you call shutdown before closesocket?
Eric Thorniley
> >
> > It does not work :( - I wrote to soon (a moment ago)
> Did you call shutdown before closesocket?
>
I have tired that and it locks up the calling thread,
in this case its the main thread that created the others.
As (for me) this is only needed at app closedown time I am
going 'poison pill' (as before) and if that fails after
a second or so then using terminate thread and or leaving it
for the OS to clean up as I close.
Many thanks to all who contributed
--
Roger
"BMG Support" <support (at) BusinessMailGateway.com> wrote in message
news:VA.000000a...@hostname.not.set.up...