Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Blocking UDP::Receive and threads  (Read 4308 times)

0 Members and 1 Guest are viewing this topic.

Zoomulator

  • Newbie
  • *
  • Posts: 10
    • View Profile
Blocking UDP::Receive and threads
« on: August 29, 2010, 07:59:17 pm »
Maybe I designed my UDP listener thread the wrong way, but here goes.
I've made a thread for the client side that listens for incoming data from the server. Quite logical. It occured to me that the UDP socket must be set to blocking, or it misses a ton of packets. It's fine leaving the socket as blocking in the dedicated thread for as long as it's running, but when I need to close the thread while the socket is blocking I don't really know any way of unblocking it while the SocketUDP::Receive method is running.
I'm using a bool for a loop in the Run method of the thread to shut it down safely. Am I forced to kill the thread with Terminate()?

It seems like the TCP socket can be in a non-blocking state and still receive all packets. Is this true?[/b]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blocking UDP::Receive and threads
« Reply #1 on: August 29, 2010, 08:21:39 pm »
Quote
It occured to me that the UDP socket must be set to blocking, or it misses a ton of packets

This is not supposed to happen. Can you provide a complete and minimal example that reproduces this behaviour?
Laurent Gomila - SFML developer

Zoomulator

  • Newbie
  • *
  • Posts: 10
    • View Profile
Blocking UDP::Receive and threads
« Reply #2 on: August 29, 2010, 08:52:53 pm »
I'll try to reproduce it in a minimal example.

I've changed my code to use a selector, even though I'm only using one socket for the client. But you're saying a UDP socket bound to a port without a selector should receive all packets through the Receive mehod even though it's not blocking?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Blocking UDP::Receive and threads
« Reply #3 on: August 29, 2010, 10:24:48 pm »
Quote
But you're saying a UDP socket bound to a port without a selector should receive all packets through the Receive mehod even though it's not blocking?

Sure. Why would it ignore some packets?
Laurent Gomila - SFML developer

 

anything