From 0327a8d4777e381f64565cfd7ec25c302bfb4804 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jul 2015 20:47:16 -0700 Subject: [PATCH] fix bytesAvailable, don't double seek in Packet --- assignment-client/src/octree/OctreeQueryNode.cpp | 2 +- assignment-client/src/octree/OctreeQueryNode.h | 2 +- assignment-client/src/octree/OctreeSendThread.cpp | 2 +- libraries/entities/src/EntityTree.cpp | 2 +- libraries/networking/src/NodeList.cpp | 4 ++-- libraries/networking/src/udt/Packet.cpp | 5 +---- libraries/networking/src/udt/PacketList.cpp | 6 +++--- libraries/octree/src/OctreeEditPacketSender.cpp | 2 +- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/assignment-client/src/octree/OctreeQueryNode.cpp b/assignment-client/src/octree/OctreeQueryNode.cpp index 2f1a554b8c..65ee0e26f8 100644 --- a/assignment-client/src/octree/OctreeQueryNode.cpp +++ b/assignment-client/src/octree/OctreeQueryNode.cpp @@ -218,7 +218,7 @@ void OctreeQueryNode::writeToPacket(const unsigned char* buffer, unsigned int by OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionSize = bytes; _octreePacket->writePrimitive(sectionSize); } - if (bytes <= _octreePacket->bytesAvailable()) { + if (bytes <= _octreePacket->bytesAvailableForWrite()) { _octreePacket->write(reinterpret_cast(buffer), bytes); _octreePacketWaiting = true; } diff --git a/assignment-client/src/octree/OctreeQueryNode.h b/assignment-client/src/octree/OctreeQueryNode.h index 6316cc5e86..d752b8d0e8 100644 --- a/assignment-client/src/octree/OctreeQueryNode.h +++ b/assignment-client/src/octree/OctreeQueryNode.h @@ -46,7 +46,7 @@ public: bool packetIsDuplicate() const; bool shouldSuppressDuplicatePacket(); - unsigned int getAvailable() const { return _octreePacket->bytesAvailable(); } + unsigned int getAvailable() const { return _octreePacket->bytesAvailableForWrite(); } int getMaxSearchLevel() const { return _maxSearchLevel; } void resetMaxSearchLevel() { _maxSearchLevel = 1; } void incrementMaxSearchLevel() { _maxSearchLevel++; } diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 6a5d76d4b9..7937604825 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -147,7 +147,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes NLPacket& statsPacket = nodeData->stats.getStatsMessage(); // If the size of the stats message and the octree message will fit in a packet, then piggyback them - if (nodeData->getPacket().getSizeWithHeader() <= statsPacket.bytesAvailable()) { + if (nodeData->getPacket().getSizeWithHeader() <= statsPacket.bytesAvailableForWrite()) { // copy octree message to back of stats message statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getSizeWithHeader()); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index a5c5d58936..cb4011c799 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -796,7 +796,7 @@ std::unique_ptr EntityTree::encodeEntitiesDeletedSince(OCTREE_PACKET_S ++numberOfIDs; // check to make sure we have room for one more ID - if (NUM_BYTES_RFC4122_UUID > deletesPacket->bytesAvailable()) { + if (NUM_BYTES_RFC4122_UUID > deletesPacket->bytesAvailableForWrite()) { hasFilledPacket = true; break; } diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 89013ece60..58720afe2c 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -284,7 +284,7 @@ void NodeList::sendDomainServerCheckIn() { flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendDSCheckIn); - if (!isUsingDTLS) { + if (!isUsingDTLS) { sendPacket(std::move(domainPacket), _domainHandler.getSockAddr()); } @@ -336,7 +336,7 @@ void NodeList::sendDSPathQuery(const QString& newPath) { // get the size of the UTF8 representation of the desired path qint64 numPathBytes = pathQueryUTF8.size(); - if (numPathBytes + ((qint64) sizeof(numPathBytes)) < pathQueryPacket->bytesAvailable()) { + if (numPathBytes + ((qint64) sizeof(numPathBytes)) < pathQueryPacket->bytesAvailableForWrite()) { // append the size of the path to the query packet pathQueryPacket->writePrimitive(numPathBytes); diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index 1b53756f5e..975c137f27 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -70,7 +70,7 @@ Packet::Packet(PacketType::Value type, qint64 size) : } _packetSize = localHeaderSize(type) + size; - _packet.reset(new char(_packetSize)); + _packet.reset(new char[_packetSize]); _capacity = size; _payloadStart = _packet.get() + (_packetSize - _capacity); @@ -222,9 +222,6 @@ qint64 Packet::readData(char* dest, qint64 maxSize) { // read out the data memcpy(dest, _payloadStart + currentPosition, numBytesToRead); - - // seek to the end of the read - seek(currentPosition + numBytesToRead); } return numBytesToRead; diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index e48ffa0f69..2c41f61d0f 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -56,7 +56,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { } // check if this block of data can fit into the currentPacket - if (maxSize <= _currentPacket->bytesAvailable()) { + if (maxSize <= _currentPacket->bytesAvailableForWrite()) { // it fits, just write it to the current packet _currentPacket->write(data, maxSize); @@ -73,7 +73,7 @@ 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 // check now to see if this is an unsupported write - int numBytesToEnd = _currentPacket->bytesAvailable(); + int numBytesToEnd = _currentPacket->bytesAvailableForWrite(); if ((newPacket->size() - numBytesToEnd) < maxSize) { // this is an unsupported case - the segment is bigger than the size of an individual packet @@ -108,7 +108,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { // we're an ordered PacketList - let's fit what we can into the current packet and then put the leftover // into a new packet - int numBytesToEnd = _currentPacket->bytesAvailable(); + int numBytesToEnd = _currentPacket->bytesAvailableForWrite(); _currentPacket->write(data, numBytesToEnd); // move the current packet to our list of packets diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 6bbfdc5024..6f2780d871 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -255,7 +255,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, QByt } else { // If we're switching type, then we send the last one and start over if ((type != bufferedPacket->getType() && bufferedPacket->getSizeUsed() > 0) || - (editMessage.size() >= bufferedPacket->bytesAvailable())) { + (editMessage.size() >= bufferedPacket->bytesAvailableForWrite())) { // create the new packet and swap it with the packet in _pendingEditPackets auto packetToRelease = initializePacket(type, node->getClockSkewUsec());