mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 08:19:48 +02:00
Merge pull request #1189 from ZappoMan/bugfixes
make temp copy of NetworkPacket to protect against vector resizing
This commit is contained in:
commit
ef491be12d
3 changed files with 14 additions and 18 deletions
|
@ -20,7 +20,6 @@ NetworkPacket::NetworkPacket() {
|
|||
|
||||
NetworkPacket::~NetworkPacket() {
|
||||
// nothing to do
|
||||
printf("NetworkPacket::~NetworkPacket() this=%p this.getData()=%p\n", this, getData());
|
||||
}
|
||||
|
||||
void NetworkPacket::copyContents(const sockaddr& address, const unsigned char* packetData, ssize_t packetLength) {
|
||||
|
|
|
@ -91,23 +91,23 @@ bool PacketSender::process() {
|
|||
while (keepGoing) {
|
||||
uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond);
|
||||
|
||||
lock();
|
||||
NetworkPacket& packet = _packets.front();
|
||||
|
||||
NetworkPacket temporary = packet; // make a copy
|
||||
_packets.erase(_packets.begin());
|
||||
packetsLeft = _packets.size();
|
||||
unlock();
|
||||
|
||||
// send the packet through the NodeList...
|
||||
UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket();
|
||||
|
||||
nodeSocket->send(&packet.getAddress(), packet.getData(), packet.getLength());
|
||||
nodeSocket->send(&temporary.getAddress(), temporary.getData(), temporary.getLength());
|
||||
packetsThisCall++;
|
||||
|
||||
if (_notify) {
|
||||
_notify->packetSentNotification(packet.getLength());
|
||||
_notify->packetSentNotification(temporary.getLength());
|
||||
}
|
||||
|
||||
lock();
|
||||
_packets.erase(_packets.begin());
|
||||
unlock();
|
||||
|
||||
packetsLeft = _packets.size();
|
||||
|
||||
// in threaded mode, we go till we're empty
|
||||
if (isThreaded()) {
|
||||
|
|
|
@ -31,16 +31,13 @@ bool ReceivedPacketProcessor::process() {
|
|||
usleep(RECEIVED_THREAD_SLEEP_INTERVAL);
|
||||
}
|
||||
while (_packets.size() > 0) {
|
||||
NetworkPacket& packet = _packets.front();
|
||||
|
||||
printf("ReceivedPacketProcessor::process() calling processPacket() NetworkPacket=%p packet.getData()=%p packet.getLength()=%ld\n",
|
||||
&packet, packet.getData(), packet.getLength() );
|
||||
|
||||
processPacket(packet.getAddress(), packet.getData(), packet.getLength());
|
||||
|
||||
lock();
|
||||
_packets.erase(_packets.begin());
|
||||
unlock();
|
||||
lock(); // lock to make sure nothing changes on us
|
||||
NetworkPacket& packet = _packets.front(); // get the oldest packet
|
||||
NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
|
||||
_packets.erase(_packets.begin()); // remove the oldest packet
|
||||
unlock(); // let others add to the packets
|
||||
processPacket(temporary.getAddress(), temporary.getData(), temporary.getLength()); // process our temporary copy
|
||||
}
|
||||
return isStillRunning(); // keep running till they terminate us
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue