repairs for domain-server PacketList sending

This commit is contained in:
Stephen Birarda 2015-07-14 21:01:26 -07:00
parent 0327a8d477
commit 89c44ded38
4 changed files with 21 additions and 7 deletions

View file

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

View file

@ -263,15 +263,20 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> 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<NLPacket>()), sockAddr);
}

View file

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

View file

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