mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 12:12:32 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into hobbes
This commit is contained in:
commit
d7dd90f87e
1 changed files with 31 additions and 14 deletions
|
@ -150,6 +150,8 @@ void PacketList::preparePackets(MessageNumber messageNumber) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const qint64 PACKET_LIST_WRITE_ERROR = -1;
|
||||||
|
|
||||||
qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
auto sizeRemaining = maxSize;
|
auto sizeRemaining = maxSize;
|
||||||
|
|
||||||
|
@ -176,26 +178,41 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
||||||
// We need to try and pull the first part of the segment out to our new packet
|
// We need to try and pull the first part of the segment out to our new packet
|
||||||
|
|
||||||
// check now to see if this is an unsupported write
|
// check now to see if this is an unsupported write
|
||||||
int numBytesToEnd = _currentPacket->bytesAvailableForWrite();
|
int segmentSize = _currentPacket->pos() - _segmentStartIndex;
|
||||||
|
|
||||||
if ((newPacket->size() - numBytesToEnd) < sizeRemaining) {
|
if (segmentSize + sizeRemaining > newPacket->getPayloadCapacity()) {
|
||||||
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
||||||
// but the PacketList is not going to be sent ordered
|
// but the PacketList is not going to be sent ordered
|
||||||
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
|
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
|
||||||
<< "larger than the payload size.";
|
<< "larger than the payload size.";
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
|
|
||||||
|
// we won't be writing this new data to the packet
|
||||||
|
// go back before the current segment and return -1 to indicate error
|
||||||
|
_currentPacket->seek(_segmentStartIndex);
|
||||||
|
_currentPacket->setPayloadSize(_segmentStartIndex);
|
||||||
|
|
||||||
|
return PACKET_LIST_WRITE_ERROR;
|
||||||
|
} else {
|
||||||
|
// copy from currentPacket where the segment started to the beginning of the newPacket
|
||||||
|
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize);
|
||||||
|
|
||||||
|
// shrink the current payload to the actual size of the packet
|
||||||
|
_currentPacket->setPayloadSize(_segmentStartIndex);
|
||||||
|
|
||||||
|
// the current segment now starts at the beginning of the new packet
|
||||||
|
_segmentStartIndex = _extendedHeader.size();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
int segmentSize = _currentPacket->pos() - _segmentStartIndex;
|
|
||||||
|
if (sizeRemaining > newPacket->getPayloadCapacity()) {
|
||||||
// copy from currentPacket where the segment started to the beginning of the newPacket
|
// this is an unsupported case - attempting to write a block of data larger
|
||||||
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize);
|
// than the capacity of a new packet in an unordered PacketList
|
||||||
|
qDebug() << "Error in PacketList::writeData - attempted to write data to an unordered packet that is"
|
||||||
// the current segment now starts at the beginning of the new packet
|
<< "larger than the payload size.";
|
||||||
_segmentStartIndex = _extendedHeader.size();
|
Q_ASSERT(false);
|
||||||
|
|
||||||
// shrink the current payload to the actual size of the packet
|
return PACKET_LIST_WRITE_ERROR;
|
||||||
_currentPacket->setPayloadSize(_segmentStartIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the current packet to our list of packets
|
// move the current packet to our list of packets
|
||||||
|
|
Loading…
Reference in a new issue