rename Packet methods for clarity

This commit is contained in:
Stephen Birarda 2015-07-15 10:40:40 -07:00
parent 7d313c4a2b
commit e127c5c06d
26 changed files with 99 additions and 78 deletions

View file

@ -65,9 +65,9 @@ void Agent::handleOctreePacket(QSharedPointer<NLPacket> packet, SharedNodePointe
if (packetType == PacketType::OctreeStats) {
int statsMessageLength = OctreeHeadlessViewer::parseOctreeStats(packet, senderNode);
if (packet->getSizeUsed() > statsMessageLength) {
if (packet->getPayloadSize() > statsMessageLength) {
// pull out the piggybacked packet and create a new QSharedPointer<NLPacket> for it
int piggyBackedSizeWithHeader = packet->getSizeUsed() - statsMessageLength;
int piggyBackedSizeWithHeader = packet->getPayloadSize() - statsMessageLength;
std::unique_ptr<char> buffer = std::unique_ptr<char>(new char[piggyBackedSizeWithHeader]);
memcpy(buffer.get(), packet->getPayload() + statsMessageLength, piggyBackedSizeWithHeader);

View file

@ -552,9 +552,9 @@ void AudioMixer::handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet, Sh
auto nodeList = DependencyManager::get<NodeList>();
if (sendingNode->getCanAdjustLocks()) {
auto newPacket = NLPacket::create(PacketType::MuteEnvironment, packet->getSizeUsed());
auto newPacket = NLPacket::create(PacketType::MuteEnvironment, packet->getPayloadSize());
// Copy payload
newPacket->write(packet->getPayload(), packet->getSizeUsed());
newPacket->write(packet->getPayload(), packet->getPayloadSize());
nodeList->eachNode([&](const SharedNodePointer& node){
if (node->getType() == NodeType::Agent && node->getActiveSocket() &&

View file

@ -15,7 +15,7 @@
int AvatarMixerClientData::parseData(NLPacket& packet) {
// compute the offset to the data payload
return _avatar.parseDataFromBuffer(QByteArray::fromRawData(packet.getPayload(), packet.getSizeUsed()));
return _avatar.parseDataFromBuffer(QByteArray::fromRawData(packet.getPayload(), packet.getPayloadSize()));
}
bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {

View file

@ -108,7 +108,7 @@ int EntityServer::sendSpecialPackets(const SharedNodePointer& node, OctreeQueryN
queryNode->packetSent(*specialPacket);
totalBytes += specialPacket->getSizeWithHeader();
totalBytes += specialPacket->getDataSize();
packetsSent++;
DependencyManager::get<NodeList>()->sendPacket(std::move(specialPacket), *node);

View file

@ -85,7 +85,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug("OctreeInboundPacketProcessor::processPacket() payload=%p payloadLength=%lld",
packet->getPayload(),
packet->getSizeUsed());
packet->getPayloadSize());
}
// Ask our tree subclass if it can handle the incoming packet...
@ -117,7 +117,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket || _myServer->wantsDebugReceiving()) {
qDebug() << "PROCESSING THREAD: got '" << packetType << "' packet - " << _receivedPacketCount << " command from client";
qDebug() << " receivedBytes=" << packet->getSizeWithHeader();
qDebug() << " receivedBytes=" << packet->getDataSize();
qDebug() << " sequence=" << sequence;
qDebug() << " sentAt=" << sentAt << " usecs";
qDebug() << " arrivedAt=" << arrivedAt << " usecs";
@ -135,7 +135,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug() << " atByte (in payload)=" << packet->pos();
qDebug() << " payload size=" << packet->getSizeUsed();
qDebug() << " payload size=" << packet->getPayloadSize();
if (!packet->bytesAvailable()) {
qDebug() << " ----- UNEXPECTED ---- got a packet without any edit details!!!! --------";
}
@ -154,7 +154,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
qDebug() << " maxSize=" << maxSize;
qDebug("OctreeInboundPacketProcessor::processPacket() %c "
"payload=%p payloadLength=%lld editData=%p payloadPosition=%lld maxSize=%d",
packetType, packet->getPayload(), packet->getSizeUsed(), editData,
packetType, packet->getPayload(), packet->getPayloadSize(), editData,
packet->pos(), maxSize);
}
@ -184,7 +184,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug() << " editDataBytesRead=" << editDataBytesRead;
qDebug() << " AFTER processEditPacketData payload position=" << packet->pos();
qDebug() << " AFTER processEditPacketData payload size=" << packet->getSizeUsed();
qDebug() << " AFTER processEditPacketData payload size=" << packet->getPayloadSize();
}
}
@ -192,7 +192,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug("OctreeInboundPacketProcessor::processPacket() DONE LOOPING FOR %c "
"payload=%p payloadLength=%lld editData=%p payloadPosition=%lld",
packetType, packet->getPayload(), packet->getSizeUsed(), editData, packet->pos());
packetType, packet->getPayload(), packet->getPayloadSize(), editData, packet->pos());
}
// Make sure our Node and NodeList knows we've heard from this node.

View file

@ -108,10 +108,10 @@ bool OctreeQueryNode::packetIsDuplicate() const {
// since our packets now include header information, like sequence number, and createTime, we can't just do a memcmp
// of the entire packet, we need to compare only the packet content...
if (_lastOctreePacketLength == _octreePacket->getSizeUsed()) {
if (_lastOctreePacketLength == _octreePacket->getPayloadSize()) {
if (memcmp(_lastOctreePayload + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getPayload() + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getSizeUsed() - OCTREE_PACKET_EXTRA_HEADERS_SIZE) == 0) {
_octreePacket->getPayloadSize() - OCTREE_PACKET_EXTRA_HEADERS_SIZE) == 0) {
return true;
}
}
@ -176,7 +176,7 @@ void OctreeQueryNode::resetOctreePacket() {
// changed since we last reset it. Since we know that no two packets can ever be identical without being the same
// scene information, (e.g. the root node packet of a static scene), we can use this as a strategy for reducing
// packet send rate.
_lastOctreePacketLength = _octreePacket->getSizeUsed();
_lastOctreePacketLength = _octreePacket->getPayloadSize();
memcpy(_lastOctreePayload, _octreePacket->getPayload(), _lastOctreePacketLength);
// If we're moving, and the client asked for low res, then we force monochrome, otherwise, use

View file

@ -147,16 +147,16 @@ 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.bytesAvailableForWrite()) {
if (nodeData->getPacket().getDataSize() <= statsPacket.bytesAvailableForWrite()) {
// copy octree message to back of stats message
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getSizeWithHeader());
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getDataSize());
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since
// there was nothing else to send.
int thisWastedBytes = 0;
_totalWastedBytes += thisWastedBytes;
_totalBytes += statsPacket.getSizeWithHeader();
_totalBytes += statsPacket.getDataSize();
_totalPackets++;
if (debug) {
@ -172,8 +172,8 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
qDebug() << "Adding stats to packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" statsMessageLength: " << statsPacket.getSizeWithHeader() <<
" original size: " << nodeData->getPacket().getSizeWithHeader() << " [" << _totalBytes <<
" statsMessageLength: " << statsPacket.getDataSize() <<
" original size: " << nodeData->getPacket().getDataSize() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
@ -190,7 +190,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
// there was nothing else to send.
int thisWastedBytes = 0;
_totalWastedBytes += thisWastedBytes;
_totalBytes += statsPacket.getSizeWithHeader();
_totalBytes += statsPacket.getDataSize();
_totalPackets++;
if (debug) {
@ -206,11 +206,11 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
qDebug() << "Sending separate stats packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" size: " << statsPacket.getSizeWithHeader() << " [" << _totalBytes <<
" size: " << statsPacket.getDataSize() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
trueBytesSent += statsPacket.getSizeWithHeader();
trueBytesSent += statsPacket.getDataSize();
truePacketsSent++;
packetsSent++;
@ -218,10 +218,10 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *_node);
packetSent = true;
int packetSizeWithHeader = nodeData->getPacket().getSizeWithHeader();
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes;
_totalBytes += nodeData->getPacket().getSizeWithHeader();
_totalBytes += nodeData->getPacket().getDataSize();
_totalPackets++;
if (debug) {
@ -237,7 +237,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" size: " << nodeData->getPacket().getSizeWithHeader() << " [" << _totalBytes <<
" size: " << nodeData->getPacket().getDataSize() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
}
@ -250,7 +250,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *_node);
packetSent = true;
int packetSizeWithHeader = nodeData->getPacket().getSizeWithHeader();
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
int thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes;
_totalBytes += packetSizeWithHeader;
@ -277,8 +277,8 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
// remember to track our stats
if (packetSent) {
nodeData->stats.packetSent(nodeData->getPacket().getSizeUsed());
trueBytesSent += nodeData->getPacket().getSizeUsed();
nodeData->stats.packetSent(nodeData->getPacket().getPayloadSize());
trueBytesSent += nodeData->getPacket().getPayloadSize();
truePacketsSent++;
packetsSent++;
nodeData->octreePacketSent();
@ -596,9 +596,9 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
truePacketsSent++;
packetsSentThisInterval++;
_totalBytes += packet->getSizeWithHeader();
_totalBytes += packet->getDataSize();
_totalPackets++;
_totalWastedBytes += MAX_PACKET_SIZE - packet->getSizeWithHeader();
_totalWastedBytes += MAX_PACKET_SIZE - packet->getDataSize();
}
}

View file

@ -579,7 +579,7 @@ void DomainServer::processConnectRequestPacket(QSharedPointer<NLPacket> packet)
NodeType_t nodeType;
HifiSockAddr publicSockAddr, localSockAddr;
if (packet->getSizeUsed() == 0) {
if (packet->getPayloadSize() == 0) {
// TODO: We know what size the connect packet should be (minimally) - check for that here
return;
}

View file

@ -134,7 +134,7 @@ void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSoc
peerPacket->write(peer.toByteArray());
// write the current packet
_serverSocket.writeDatagram(peerPacket->getData(), peerPacket->getSizeWithHeader(),
_serverSocket.writeDatagram(peerPacket->getData(), peerPacket->getDataSize(),
destinationSockAddr->getAddress(), destinationSockAddr->getPort());
}

View file

@ -2899,7 +2899,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
// encode the query data
int packetSize = _octreeQuery.getBroadcastData(reinterpret_cast<unsigned char*>(queryPacket->getPayload()));
queryPacket->setSizeUsed(packetSize);
queryPacket->setPayloadSize(packetSize);
// make sure we still have an active socket
nodeList->sendUnreliablePacket(*queryPacket, *node);

View file

@ -57,7 +57,7 @@ void OctreePacketProcessor::processPacket(QSharedPointer<NLPacket> packet, Share
int statsMessageLength = app->processOctreeStats(*packet, sendingNode);
wasStatsPacket = true;
int piggybackBytes = packet->getSizeUsed() - statsMessageLength;
int piggybackBytes = packet->getPayloadSize() - statsMessageLength;
if (piggybackBytes) {
// construct a new packet from the piggybacked one

View file

@ -937,7 +937,7 @@ void AudioClient::handleAudioInput() {
if (_audioPacket->getType() != PacketType::SilentAudioFrame) {
// audio samples have already been packed (written to networkAudioSamples)
_audioPacket->setSizeUsed(_audioPacket->getSizeUsed() + numNetworkBytes);
_audioPacket->setPayloadSize(_audioPacket->getPayloadSize() + numNetworkBytes);
}
_stats.sentPacket();

View file

@ -232,7 +232,7 @@ void AudioInjector::injectToMixer() {
audioPacket->write(_audioData.data() + _currentSendPosition, bytesToCopy);
// set the correct size used for this packet
audioPacket->setSizeUsed(audioPacket->pos());
audioPacket->setPayloadSize(audioPacket->pos());
// grab our audio mixer from the NodeList, if it exists
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);

View file

@ -24,7 +24,7 @@ EntityEditPacketSender::EntityEditPacketSender() {
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet) {
if (_shouldNack) {
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getDataSize()));
}
}

View file

@ -907,7 +907,7 @@ bool EntityItemProperties::decodeEntityEditPacket(NLPacket& packet, int& process
const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.getPayload());
const unsigned char* dataAt = data;
int bytesToRead = packet.getSizeUsed();
int bytesToRead = packet.getPayloadSize();
processedBytes = 0;
// the first part of the data is an octcode, this is a required element of the edit packet format, but we don't

View file

@ -215,7 +215,7 @@ bool LimitedNodeList::packetSourceAndHashMatch(const NLPacket& packet, SharedNod
}
qint64 LimitedNodeList::writeDatagram(const NLPacket& packet, const HifiSockAddr& destinationSockAddr) {
return writeDatagram({packet.getData(), static_cast<int>(packet.getSizeWithHeader())}, destinationSockAddr);
return writeDatagram({packet.getData(), static_cast<int>(packet.getDataSize())}, destinationSockAddr);
}
qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr) {
@ -598,7 +598,7 @@ bool LimitedNodeList::processSTUNResponse(QSharedPointer<NLPacket> packet) {
sizeof(RFC_5389_MAGIC_COOKIE_NETWORK_ORDER)) == 0) {
// enumerate the attributes to find XOR_MAPPED_ADDRESS_TYPE
while (attributeStartIndex < packet->getSizeWithHeader()) {
while (attributeStartIndex < packet->getDataSize()) {
if (memcmp(packet->getData() + attributeStartIndex, &XOR_MAPPED_ADDRESS_TYPE, sizeof(XOR_MAPPED_ADDRESS_TYPE)) == 0) {
const int NUM_BYTES_STUN_ATTR_TYPE_AND_LENGTH = 4;
const int NUM_BYTES_FAMILY_ALIGN = 1;

View file

@ -80,7 +80,7 @@ NLPacket::NLPacket(PacketType::Value type, qint64 size) :
qint64 headerSize = localHeaderSize(type);
_payloadStart += headerSize;
_capacity -= headerSize;
_payloadCapacity -= headerSize;
}
NLPacket::NLPacket(PacketType::Value type) :
@ -88,7 +88,7 @@ NLPacket::NLPacket(PacketType::Value type) :
{
qint64 headerSize = localHeaderSize(type);
_payloadStart += headerSize;
_capacity -= headerSize;
_payloadCapacity -= headerSize;
}
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
@ -137,7 +137,7 @@ QByteArray NLPacket::payloadHashWithConnectionUUID(const QUuid& connectionUUID)
QCryptographicHash hash(QCryptographicHash::Md5);
// add the packet payload and the connection UUID
hash.addData(_payloadStart, _sizeUsed);
hash.addData(_payloadStart, _payloadSize);
hash.addData(connectionUUID.toRfc4122());
// return the hash

View file

@ -475,7 +475,7 @@ void NodeList::processDomainServerList(QSharedPointer<NLPacket> packet) {
setThisNodeCanRez((bool) thisNodeCanRez);
// pull each node in the packet
while (packetStream.device()->pos() < packet->getSizeUsed()) {
while (packetStream.device()->pos() < packet->getPayloadSize()) {
parseNodeFromPacketStream(packetStream);
}
}

View file

@ -236,7 +236,7 @@ void PacketReceiver::processDatagrams() {
matchingNode->setLastSequenceNumberForPacketType(packet->readSequenceNumber(), packet->getType());
}
emit dataReceived(matchingNode->getType(), packet->getSizeWithHeader());
emit dataReceived(matchingNode->getType(), packet->getDataSize());
QMetaMethod metaMethod = listener.second;
static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer<Node>");
@ -257,7 +257,7 @@ void PacketReceiver::processDatagrams() {
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())));
}
} else {
emit dataReceived(NodeType::Unassigned, packet->getSizeWithHeader());
emit dataReceived(NodeType::Unassigned, packet->getDataSize());
success = listener.second.invoke(listener.first,
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())));

View file

@ -54,7 +54,7 @@ void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNod
unlock();
_totalPacketsQueued++;
_totalBytesQueued += packet->getSizeWithHeader();
_totalBytesQueued += packet->getDataSize();
// Make sure to wake our actual processing thread because we now have packets for it to process.
_hasPackets.wakeAll();
@ -278,7 +278,7 @@ bool PacketSender::nonThreadedProcess() {
_packetsOverCheckInterval++;
_totalPacketsSent++;
int packetSize = packetPair.second->getSizeWithHeader();
int packetSize = packetPair.second->getDataSize();
_totalBytesSent += packetSize;
emit packetSent(packetSize);

View file

@ -71,8 +71,8 @@ Packet::Packet(PacketType::Value type, qint64 size) :
_packetSize = localHeaderSize(type) + size;
_packet.reset(new char[_packetSize]);
_capacity = size;
_payloadStart = _packet.get() + (_packetSize - _capacity);
_payloadCapacity = size;
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
// Sanity check
Q_ASSERT(size >= 0 || size < maxPayload);
@ -93,9 +93,9 @@ Packet::Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& send
{
_type = readType();
_version = readVersion();
_capacity = _packetSize - localHeaderSize(_type);
_sizeUsed = _capacity;
_payloadStart = _packet.get() + (_packetSize - _capacity);
_payloadCapacity = _packetSize - localHeaderSize(_type);
_payloadSize = _payloadCapacity;
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
}
Packet::Packet(const Packet& other) {
@ -110,9 +110,9 @@ Packet& Packet::operator=(const Packet& other) {
memcpy(_packet.get(), other._packet.get(), _packetSize);
_payloadStart = _packet.get() + (other._payloadStart - other._packet.get());
_capacity = other._capacity;
_payloadCapacity = other._payloadCapacity;
_sizeUsed = other._sizeUsed;
_payloadSize = other._payloadSize;
return *this;
}
@ -128,13 +128,31 @@ Packet& Packet::operator=(Packet&& other) {
_packet = std::move(other._packet);
_payloadStart = other._payloadStart;
_capacity = other._capacity;
_payloadCapacity = other._payloadCapacity;
_sizeUsed = other._sizeUsed;
_payloadSize = other._payloadSize;
return *this;
}
void Packet::setPayloadSize(qint64 payloadSize) {
if (isWritable()) {
Q_ASSERT(payloadSize > _payloadCapacity);
_payloadSize = std::max(payloadSize, _payloadCapacity);
} else {
qDebug() << "You can not call setPayloadSize for a non-writeable Packet.";
Q_ASSERT(false);
}
}
bool Packet::reset() {
if (isWritable()) {
setPayloadSize(0);
}
return QIODevice::reset();
}
void Packet::setType(PacketType::Value type) {
auto currentHeaderSize = totalHeadersSize();
_type = type;
@ -197,13 +215,13 @@ qint64 Packet::writeData(const char* data, qint64 maxSize) {
if (maxSize <= bytesAvailableForWrite()) {
qint64 currentPos = pos();
Q_ASSERT(currentPos < _capacity);
Q_ASSERT(currentPos < _payloadCapacity);
// good to go - write the data
memcpy(_payloadStart + currentPos, data, maxSize);
// keep track of _sizeUsed so we can just write the actual data when packet is about to be sent
_sizeUsed = std::max(currentPos + maxSize, _sizeUsed);
// keep track of _payloadSize so we can just write the actual data when packet is about to be sent
_payloadSize = std::max(currentPos + maxSize, _payloadSize);
// return the number of bytes written
return maxSize;

View file

@ -49,11 +49,14 @@ public:
PacketVersion getVersion() const { return _version; }
qint64 getSizeWithHeader() const { return totalHeadersSize() + getSizeUsed(); }
qint64 getSizeUsed() const { return _sizeUsed; }
void setSizeUsed(qint64 sizeUsed) { _sizeUsed = sizeUsed; }
qint64 getDataSize() const { return totalHeadersSize() + getPayloadSize(); }
qint64 getPayloadSize() const { return _payloadSize; }
void setPayloadSize(qint64 payloadSize);
qint64 bytesAvailableForWrite() const { return _capacity - _sizeUsed; }
qint64 getPayloadCapacity() const { return _payloadCapacity; }
qint64 bytesAvailableForWrite() const { return _payloadCapacity - _payloadSize; }
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
@ -64,8 +67,8 @@ public:
// QIODevice virtual functions
// WARNING: Those methods all refer to the payload ONLY and NOT the entire packet
virtual bool isSequential() const { return false; }
virtual bool reset() { setSizeUsed(0); return QIODevice::reset(); }
virtual qint64 size() const { return _capacity; }
virtual bool reset();
virtual qint64 size() const { return _payloadCapacity; }
template<typename T> qint64 peekPrimitive(T* data);
template<typename T> qint64 readPrimitive(T* data);
@ -98,9 +101,9 @@ protected:
std::unique_ptr<char> _packet; // Allocated memory
char* _payloadStart = nullptr; // Start of the payload
qint64 _capacity = 0; // Total capacity of the payload
qint64 _payloadCapacity = 0; // Total capacity of the payload
qint64 _sizeUsed = 0; // How much of the payload is actually used
qint64 _payloadSize = 0; // How much of the payload is actually used
HifiSockAddr _senderSockAddr; // sender address for packet (only used on receiving end)
};

View file

@ -90,7 +90,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
_segmentStartIndex = 0;
// shrink the current payload to the actual size of the packet
_currentPacket->setSizeUsed(_segmentStartIndex);
_currentPacket->setPayloadSize(_segmentStartIndex);
}
// move the current packet to our list of packets

View file

@ -103,7 +103,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu
quint64 transitTime = queuedAt - createdAt;
qCDebug(octree) << "OctreeEditPacketSender::queuePacketToNode() queued " << packet->getType()
<< " - command to node bytes=" << packet->getSizeWithHeader()
<< " - command to node bytes=" << packet->getDataSize()
<< " sequence=" << sequence << " transitTimeSoFar=" << transitTime << " usecs";
}
@ -254,7 +254,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, QByt
bufferedPacket = NLPacket::create(type);
} else {
// If we're switching type, then we send the last one and start over
if ((type != bufferedPacket->getType() && bufferedPacket->getSizeUsed() > 0) ||
if ((type != bufferedPacket->getType() && bufferedPacket->getPayloadSize() > 0) ||
(editMessage.size() >= bufferedPacket->bytesAvailableForWrite())) {
// create the new packet and swap it with the packet in _pendingEditPackets
@ -307,7 +307,7 @@ void OctreeEditPacketSender::releaseQueuedMessages() {
void OctreeEditPacketSender::releaseQueuedPacket(const QUuid& nodeID, std::unique_ptr<NLPacket> packet) {
_releaseQueuedPacketMutex.lock();
if (packet->getSizeUsed() > 0 && packet->getType() != PacketType::Unknown) {
if (packet->getPayloadSize() > 0 && packet->getType() != PacketType::Unknown) {
queuePacketToNode(nodeID, std::move(packet));
}
_releaseQueuedPacketMutex.unlock();

View file

@ -90,7 +90,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
qCDebug(octree, "OctreeRenderer::processDatagram() ... Got Packet Section"
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld",
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesAvailable());
sequence, flightTime, packet.getDataSize(), packet.bytesAvailable());
}
_packetsInLastWindow++;
@ -139,7 +139,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld"
" subsection:%d sectionLength:%d uncompressed:%d",
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesAvailable(), subsection, sectionLength,
sequence, flightTime, packet.getDataSize(), packet.bytesAvailable(), subsection, sectionLength,
packetData.getUncompressedSize());
}

View file

@ -439,7 +439,7 @@ int OctreeSceneStats::packIntoPacket() {
_statsPacket->writePrimitive(bytes);
}
return _statsPacket->getSizeUsed();
return _statsPacket->getPayloadSize();
}
int OctreeSceneStats::unpackFromPacket(NLPacket& packet) {
@ -789,8 +789,8 @@ void OctreeSceneStats::trackIncomingOctreePacket(NLPacket& packet, bool wasStats
// track packets here...
_incomingPacket++;
_incomingBytes += packet.getSizeWithHeader();
_incomingBytes += packet.getDataSize();
if (!wasStatsPacket) {
_incomingWastedBytes += (MAX_PACKET_SIZE - packet.getSizeWithHeader());
_incomingWastedBytes += (MAX_PACKET_SIZE - packet.getDataSize());
}
}