From bf625f5af1f66bd5970204a4a9e16e1f3b339c33 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 7 Jul 2015 17:39:58 -0700 Subject: [PATCH] move JSON stats sending to a packet list --- libraries/networking/src/NodeList.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 21b3bdff96..68765489f9 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -93,40 +93,22 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned } qint64 NodeList::sendStats(const QJsonObject& statsObject, const HifiSockAddr& destination) { - QByteArray statsPacket(MAX_PACKET_SIZE, 0); - int numBytesForPacketHeader = populatePacketHeader(statsPacket, PacketTypeNodeJsonStats); + NLPacketList statsPacketList(PacketType::NodeJsonStats); // get a QStringList using JSONBreakableMarshal QStringList statsStringList = JSONBreakableMarshal::toStringList(statsObject, ""); int numBytesWritten = numBytesForPacketHeader; - // enumerate the resulting strings - pack them and send off packets once we hit MTU size + // enumerate the resulting strings - pack them and send off packets via NLPacketList foreach(const QString& statsItem, statsStringList) { QByteArray utf8String = statsItem.toUtf8(); utf8String.append('\0'); - if (numBytesWritten + utf8String.size() > MAX_PACKET_SIZE) { - // send off the current packet since the next string will make us too big - statsPacket.resize(numBytesWritten); - writeUnverifiedDatagram(statsPacket, destination); - - // reset the number of bytes written to the size of our packet header - numBytesWritten = numBytesForPacketHeader; - } - - // write this string into the stats packet - statsPacket.replace(numBytesWritten, utf8String.size(), utf8String); - - // keep track of the number of bytes we have written - numBytesWritten += utf8String.size(); + statsStringList->write(utfString); } - if (numBytesWritten > numBytesForPacketHeader) { - // always send the last packet, if it has data - statsPacket.resize(numBytesWritten); - writeUnverifiedDatagram(statsPacket, destination); - } + sendPacketList(statsStringList, destination); // enumerate the resulting strings, breaking them into MTU sized packets return 0;