From 89c44ded38a2bce88bdf9dcc127ee09f0d713f04 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jul 2015 21:01:26 -0700 Subject: [PATCH] repairs for domain-server PacketList sending --- domain-server/src/DomainServer.cpp | 3 +++ libraries/networking/src/LimitedNodeList.cpp | 11 ++++++++--- libraries/networking/src/udt/PacketList.cpp | 12 +++++++++--- libraries/networking/src/udt/PacketList.h | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index b493684f45..4023fbcd1f 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1007,6 +1007,9 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif }); } } + + // send an empty list to the node, in case there were no other nodes + domainListPackets.closeCurrentPacket(true); // write the PacketList to this node limitedNodeList->sendPacketList(domainListPackets, *node); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index fe4efb3de1..33139e66e8 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -263,15 +263,20 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const HifiS } qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) { - if (!destinationNode.getActiveSocket()) { + const HifiSockAddr* activeSocket = destinationNode.getActiveSocket(); + if (!activeSocket) { // we don't have a socket to send to, return 0 return 0; } - return sendPacketList(packetList, *destinationNode.getActiveSocket()); + return sendPacketList(packetList, *activeSocket); } qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) { - qint64 bytesSent{ 0 }; + qint64 bytesSent { 0 }; + + // close the last packet in the list + packetList.closeCurrentPacket(); + while (!packetList._packets.empty()) { bytesSent += sendPacket(std::move(packetList.takeFront()), sockAddr); } diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index 2c41f61d0f..675645abc2 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -120,7 +120,13 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { } } -void PacketList::closeCurrentPacket() { - // move the current packet to our list of packets - _packets.push_back(std::move(_currentPacket)); +void PacketList::closeCurrentPacket(bool shouldSendEmpty) { + if (shouldSendEmpty && !_currentPacket) { + _currentPacket = createPacketWithExtendedHeader(); + } + + if (_currentPacket) { + // move the current packet to our list of packets + _packets.push_back(std::move(_currentPacket)); + } } diff --git a/libraries/networking/src/udt/PacketList.h b/libraries/networking/src/udt/PacketList.h index 173e8c75fb..f4b542155a 100644 --- a/libraries/networking/src/udt/PacketList.h +++ b/libraries/networking/src/udt/PacketList.h @@ -31,7 +31,7 @@ public: PacketType::Value getType() const { return _packetType; } int getNumPackets() const { return _packets.size() + (_currentPacket ? 1 : 0); } - void closeCurrentPacket(); + void closeCurrentPacket(bool shouldSendEmpty = false); void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }