Re: Socket Programming: How to terminate a thread "listening" for UDP packets?
- From: Lars Uffmann <aral@xxxxxxxxxxxxxx>
- Date: Thu, 17 Jan 2008 10:06:35 +0100
David Schwartz wrote:
3) Set a shutdown flag and then create the event the thread is waiting
for. That is, if the thread is waiting for a UDP packet on port 402,
send it one. Make sure it checks the shutdown flag as soon as its
blocking function finishes and discards the packet.
Sweet. That was an easy approach. Thanks a lot. Sending a packet on the port that I was trying to read from somehow didn't occur to me.
4) Set the socket non-blocking. Create a pipe. Use 'select' or 'poll'
to wait for both the socket and the pipe. Block in 'select' or 'poll'.
When you want to shutdown the thread, send a byte on the pipe. This
will cause the thread to unblock.
And I'll have a look into this - pipes, select and poll don't mean anything to me atm, but they will by the end of today :)
Yes, but that won't work. UDP in unreliable. By the time you call
'recvfrom', the packet could be dropped, and you could miss a
shutdown. (Precisely this type of bug caused an infamous Linux inetd
UDP denial of service attack.)
Okay, I can see that being a problem. Basically that brings me to my next question, which I will open a new thread for :)
Best Regards & Thanks again,
Lars
.
- References:
- Socket Programming: How to terminate a thread "listening" for UDP packets?
- From: Lars Uffmann
- Re: Socket Programming: How to terminate a thread "listening" for UDP packets?
- From: David Schwartz
- Socket Programming: How to terminate a thread "listening" for UDP packets?
- Prev by Date: Re: Does ever growing SZ from ps indicate memory leak?
- Next by Date: socket programming again: possible to *sniff* udp packets before buffer is emptied?
- Previous by thread: Re: Socket Programming: How to terminate a thread "listening" for UDP packets?
- Next by thread: Re: Socket Programming: How to terminate a thread "listening" for UDP packets?
- Index(es):
Relevant Pages
|