Re: Socket Programming: How to terminate a thread "listening" for UDP packets?



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
.



Relevant Pages

  • Re: Help Interpreting data from Wireshark
    ... but later in the packet you see the dest as 84.160.95.226 ... response to a UDP packet that claims to have come from you, ... ICMP Destination unreachable (Port unreachable) ... TTL was set to maximum, ...
    (comp.os.linux.security)
  • PATCH: Remove file riowinif.h from rio driver (unused file)
    ... -/* The RUP (Remote Unit Port) structure relates to the Remote Terminal Adapters ... - CONFIG is sent from the driver to configure an already opened port. ... - Packet structure is same as OPEN. ... - of the specified port's RTA address space. ...
    (Linux-Kernel)
  • Re: General questions about Sockets
    ... > could I push it before I see the network slowing down and/or errors? ... Nagle/Delayed ACK interaction but you could confirm it with a packet ... > I can setup any port in my registry, but what would be the 'default' one I ... Google could confirm it. ...
    (microsoft.public.win32.programmer.networks)
  • RE: Strange replies on closed port
    ... port should be a RST - not dropping the packet. ... receiving an UDP datagram to a non 'listening' port. ... that message isn't generated by the end host, ... Connecting to a closed Port w/o Firewall: ...
    (Pen-Test)
  • Re: Please help me interpret a suspicious netstat SYN_SENT TCP port 1058 ?
    ... Your system initiated a connection. ... your computer sends a TCP packet with the SYN ... Process 912 on your system sent a packet from port 1058 ... hoping to connect to the web server running on port 80 ...
    (comp.security.firewalls)