mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
Replace bytesAvailable with bytesLefToRead
This commit is contained in:
parent
9018dedcd6
commit
44c99ef89a
9 changed files with 20 additions and 19 deletions
|
@ -136,18 +136,18 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
|
||||||
if (debugProcessPacket) {
|
if (debugProcessPacket) {
|
||||||
qDebug() << " atByte (in payload)=" << packet->pos();
|
qDebug() << " atByte (in payload)=" << packet->pos();
|
||||||
qDebug() << " payload size=" << packet->getSizeUsed();
|
qDebug() << " payload size=" << packet->getSizeUsed();
|
||||||
if (!packet->bytesAvailable()) {
|
if (!packet->bytesLeftToRead()) {
|
||||||
qDebug() << " ----- UNEXPECTED ---- got a packet without any edit details!!!! --------";
|
qDebug() << " ----- UNEXPECTED ---- got a packet without any edit details!!!! --------";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* editData = nullptr;
|
const unsigned char* editData = nullptr;
|
||||||
|
|
||||||
while (packet->bytesAvailable() > 0) {
|
while (packet->bytesLeftToRead() > 0) {
|
||||||
|
|
||||||
editData = reinterpret_cast<const unsigned char*>(packet->getPayload() + packet->pos());
|
editData = reinterpret_cast<const unsigned char*>(packet->getPayload() + packet->pos());
|
||||||
|
|
||||||
int maxSize = packet->bytesAvailable();
|
int maxSize = packet->bytesLeftToRead();
|
||||||
|
|
||||||
if (debugProcessPacket) {
|
if (debugProcessPacket) {
|
||||||
qDebug() << " --- inside while loop ---";
|
qDebug() << " --- inside while loop ---";
|
||||||
|
|
|
@ -2190,7 +2190,7 @@ void DomainServer::processPathQueryPacket(QSharedPointer<NLPacket> packet) {
|
||||||
quint16 numPathBytes;
|
quint16 numPathBytes;
|
||||||
packet->readPrimitive(&numPathBytes);
|
packet->readPrimitive(&numPathBytes);
|
||||||
|
|
||||||
if (numPathBytes <= packet->bytesAvailable()) {
|
if (numPathBytes <= packet->bytesLeftToRead()) {
|
||||||
// the number of path bytes makes sense for the sent packet - pull out the path
|
// the number of path bytes makes sense for the sent packet - pull out the path
|
||||||
QString pathQuery = QString::fromUtf8(packet->getPayload() + packet->pos(), numPathBytes);
|
QString pathQuery = QString::fromUtf8(packet->getPayload() + packet->pos(), numPathBytes);
|
||||||
|
|
||||||
|
@ -2223,7 +2223,7 @@ void DomainServer::processPathQueryPacket(QSharedPointer<NLPacket> packet) {
|
||||||
|
|
||||||
// are we going to be able to fit this response viewpoint in a packet?
|
// are we going to be able to fit this response viewpoint in a packet?
|
||||||
if (numPathBytes + numViewpointBytes + sizeof(numViewpointBytes) + sizeof(numPathBytes)
|
if (numPathBytes + numViewpointBytes + sizeof(numViewpointBytes) + sizeof(numPathBytes)
|
||||||
< (unsigned long) pathResponsePacket->bytesAvailable()) {
|
< (unsigned long) pathResponsePacket->bytesLeftToRead()) {
|
||||||
// append the number of bytes this path is
|
// append the number of bytes this path is
|
||||||
pathResponsePacket->writePrimitive(numPathBytes);
|
pathResponsePacket->writePrimitive(numPathBytes);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<NLPacket> packet, Sha
|
||||||
|
|
||||||
// enumerate over all of the avatars in this packet
|
// enumerate over all of the avatars in this packet
|
||||||
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
||||||
while (packet->bytesAvailable()) {
|
while (packet->bytesLeftToRead()) {
|
||||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||||
|
|
||||||
if (sessionUUID != _lastOwnerSessionUUID) {
|
if (sessionUUID != _lastOwnerSessionUUID) {
|
||||||
|
@ -121,7 +121,7 @@ void AvatarHashMap::processAvatarBillboardPacket(QSharedPointer<NLPacket> packet
|
||||||
avatar = addAvatar(sessionUUID, sendingNode);
|
avatar = addAvatar(sessionUUID, sendingNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray billboard = packet->read(packet->bytesAvailable());
|
QByteArray billboard = packet->read(packet->bytesLeftToRead());
|
||||||
if (avatar->getBillboard() != billboard) {
|
if (avatar->getBillboard() != billboard) {
|
||||||
avatar->setBillboard(billboard);
|
avatar->setBillboard(billboard);
|
||||||
}
|
}
|
||||||
|
|
|
@ -867,7 +867,7 @@ int EntityTree::processEraseMessage(NLPacket& packet, const SharedNodePointer& s
|
||||||
|
|
||||||
for (size_t i = 0; i < numberOfIDs; i++) {
|
for (size_t i = 0; i < numberOfIDs; i++) {
|
||||||
|
|
||||||
if (NUM_BYTES_RFC4122_UUID > packet.bytesAvailable()) {
|
if (NUM_BYTES_RFC4122_UUID > packet.bytesLeftToRead()) {
|
||||||
qCDebug(entities) << "EntityTree::processEraseMessage().... bailing because not enough bytes in buffer";
|
qCDebug(entities) << "EntityTree::processEraseMessage().... bailing because not enough bytes in buffer";
|
||||||
break; // bail to prevent buffer overflow
|
break; // bail to prevent buffer overflow
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ qint64 Packet::writeData(const char* data, qint64 maxSize) {
|
||||||
|
|
||||||
qint64 Packet::readData(char* dest, qint64 maxSize) {
|
qint64 Packet::readData(char* dest, qint64 maxSize) {
|
||||||
// we're either reading what is left from the current position or what was asked to be read
|
// we're either reading what is left from the current position or what was asked to be read
|
||||||
qint64 numBytesToRead = std::min(bytesAvailable(), maxSize);
|
qint64 numBytesToRead = std::min(bytesLeftToRead(), maxSize);
|
||||||
|
|
||||||
if (numBytesToRead > 0) {
|
if (numBytesToRead > 0) {
|
||||||
int currentPosition = pos();
|
int currentPosition = pos();
|
||||||
|
|
|
@ -53,7 +53,8 @@ public:
|
||||||
qint64 getSizeUsed() const { return _sizeUsed; }
|
qint64 getSizeUsed() const { return _sizeUsed; }
|
||||||
void setSizeUsed(qint64 sizeUsed) { _sizeUsed = sizeUsed; }
|
void setSizeUsed(qint64 sizeUsed) { _sizeUsed = sizeUsed; }
|
||||||
|
|
||||||
qint64 bytesAvailableForWrite() const { return _capacity - _sizeUsed; }
|
void bytesLeftToRead() const { return _capacity - pos(); }
|
||||||
|
qint64 bytesAvailableForWrite() const { return _capacity - pos(); }
|
||||||
|
|
||||||
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
|
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
|
||||||
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
|
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
|
||||||
|
|
|
@ -322,7 +322,7 @@ int JurisdictionMap::unpackFromPacket(NLPacket& packet) {
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
packet.readPrimitive(&bytes);
|
packet.readPrimitive(&bytes);
|
||||||
|
|
||||||
if (bytes > 0 && bytes <= packet.bytesAvailable()) {
|
if (bytes > 0 && bytes <= packet.bytesLeftToRead()) {
|
||||||
_rootOctalCode = new unsigned char[bytes];
|
_rootOctalCode = new unsigned char[bytes];
|
||||||
packet.read(reinterpret_cast<char*>(_rootOctalCode), bytes);
|
packet.read(reinterpret_cast<char*>(_rootOctalCode), bytes);
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ int JurisdictionMap::unpackFromPacket(NLPacket& packet) {
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
packet.readPrimitive(&bytes);
|
packet.readPrimitive(&bytes);
|
||||||
|
|
||||||
if (bytes <= packet.bytesAvailable()) {
|
if (bytes <= packet.bytesLeftToRead()) {
|
||||||
unsigned char* endNodeCode = new unsigned char[bytes];
|
unsigned char* endNodeCode = new unsigned char[bytes];
|
||||||
packet.read(reinterpret_cast<char*>(endNodeCode), bytes);
|
packet.read(reinterpret_cast<char*>(endNodeCode), bytes);
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
|
||||||
qCDebug(octree, "OctreeRenderer::processDatagram() ... Got Packet Section"
|
qCDebug(octree, "OctreeRenderer::processDatagram() ... Got Packet Section"
|
||||||
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld",
|
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld",
|
||||||
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
|
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
|
||||||
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesAvailable());
|
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesLeftToRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
_packetsInLastWindow++;
|
_packetsInLastWindow++;
|
||||||
|
@ -108,16 +108,16 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
|
||||||
|
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
while (packet.bytesAvailable() > 0 && !error) {
|
while (packet.bytesLeftToRead() > 0 && !error) {
|
||||||
if (packetIsCompressed) {
|
if (packetIsCompressed) {
|
||||||
if (packet.bytesAvailable() > (qint64) sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE)) {
|
if (packet.bytesLeftToRead() > (qint64) sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE)) {
|
||||||
packet.readPrimitive(§ionLength);
|
packet.readPrimitive(§ionLength);
|
||||||
} else {
|
} else {
|
||||||
sectionLength = 0;
|
sectionLength = 0;
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sectionLength = packet.bytesAvailable();
|
sectionLength = packet.bytesLeftToRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sectionLength) {
|
if (sectionLength) {
|
||||||
|
@ -139,7 +139,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
|
||||||
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld"
|
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld"
|
||||||
" subsection:%d sectionLength:%d uncompressed:%d",
|
" subsection:%d sectionLength:%d uncompressed:%d",
|
||||||
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
|
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
|
||||||
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesAvailable(), subsection, sectionLength,
|
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesLeftToRead(), subsection, sectionLength,
|
||||||
packetData.getUncompressedSize());
|
packetData.getUncompressedSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,9 +205,9 @@ int Environment::processPacket(NLPacket& packet) {
|
||||||
|
|
||||||
EnvironmentData newData;
|
EnvironmentData newData;
|
||||||
|
|
||||||
while (packet.bytesAvailable() > 0) {
|
while (packet.bytesLeftToRead() > 0) {
|
||||||
int dataLength = newData.parseData(reinterpret_cast<const unsigned char*>(packet.getPayload() + packet.pos()),
|
int dataLength = newData.parseData(reinterpret_cast<const unsigned char*>(packet.getPayload() + packet.pos()),
|
||||||
packet.bytesAvailable());
|
packet.bytesLeftToRead());
|
||||||
packet.seek(packet.pos() + dataLength);
|
packet.seek(packet.pos() + dataLength);
|
||||||
|
|
||||||
// update the mapping by address/ID
|
// update the mapping by address/ID
|
||||||
|
|
Loading…
Reference in a new issue