1
Network / Re: Are the send and receive methods of sf::UdpSocket threadsafe?
« on: November 25, 2015, 01:47:43 am »
After some quick googling and looking at the implementation of the functions, I would say... it depends on how you call it.
To start, the actual data transfering is done by the standard function sendto() and recvfrom() which should be atomic.
The thing is the in receive remoteAddress and remotePort are called by reference so is remoteAddress in send.
Receive will also change the value of remoteAddress twice, clearing it at the beginning of the function and fill it at the end with the remoteAddress of the received datagram.
So if you use the same IpAddress instance for the remoteAddress of send and receive, you send could get the address changed when the thread is stopped and the value being changed then by receive. Besides these function arguments, everything in the two function appears to be self contained.
Atleast that is what I see at the first glance at almost 2am. Might dig into that a bit deeper tomorrow.
To start, the actual data transfering is done by the standard function sendto() and recvfrom() which should be atomic.
The thing is the in receive remoteAddress and remotePort are called by reference so is remoteAddress in send.
Receive will also change the value of remoteAddress twice, clearing it at the beginning of the function and fill it at the end with the remoteAddress of the received datagram.
So if you use the same IpAddress instance for the remoteAddress of send and receive, you send could get the address changed when the thread is stopped and the value being changed then by receive. Besides these function arguments, everything in the two function appears to be self contained.
Atleast that is what I see at the first glance at almost 2am. Might dig into that a bit deeper tomorrow.