Fixed a bug in sf::UdpSocket::Receive(sf::Packet&) with non-blocking sockets (incorrect packets were sometimes returned)
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1583 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
5e73228b5e
commit
2cd966f566
|
@ -190,10 +190,10 @@ Socket::Status UdpSocket::Receive(Packet& packet, IpAddress& remoteAddress, unsi
|
||||||
|
|
||||||
// Receive datagrams
|
// Receive datagrams
|
||||||
std::size_t received = 0;
|
std::size_t received = 0;
|
||||||
|
std::size_t size = myPendingPacket.Data.size();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Make room in the data buffer for a new datagram
|
// Make room in the data buffer for a new datagram
|
||||||
std::size_t size = myPendingPacket.Data.size();
|
|
||||||
myPendingPacket.Data.resize(size + MaxDatagramSize);
|
myPendingPacket.Data.resize(size + MaxDatagramSize);
|
||||||
char* data = &myPendingPacket.Data[0] + size;
|
char* data = &myPendingPacket.Data[0] + size;
|
||||||
|
|
||||||
|
@ -202,12 +202,15 @@ Socket::Status UdpSocket::Receive(Packet& packet, IpAddress& remoteAddress, unsi
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (status != Done)
|
if (status != Done)
|
||||||
|
{
|
||||||
|
myPendingPacket.Data.resize(size + received);
|
||||||
return status;
|
return status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (received == MaxDatagramSize);
|
while (received == MaxDatagramSize);
|
||||||
|
|
||||||
// We have received all the packet data: we can copy it to the user packet
|
// We have received all the packet data: we can copy it to the user packet
|
||||||
std::size_t actualSize = myPendingPacket.Data.size() - MaxDatagramSize + received;
|
std::size_t actualSize = size + received;
|
||||||
if (actualSize > 0)
|
if (actualSize > 0)
|
||||||
packet.OnReceive(&myPendingPacket.Data[0], actualSize);
|
packet.OnReceive(&myPendingPacket.Data[0], actualSize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue