fix bytesAvailable, don't double seek in Packet

This commit is contained in:
Stephen Birarda 2015-07-14 20:47:16 -07:00
parent c210b0db1c
commit 0327a8d477
8 changed files with 11 additions and 14 deletions

View file

@ -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<const char*>(buffer), bytes);
_octreePacketWaiting = true;
}

View file

@ -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++; }

View file

@ -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());

View file

@ -796,7 +796,7 @@ std::unique_ptr<NLPacket> 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;
}

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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());