From f5ec458a5eb0cae74d78b78df5d5fca64a710149 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 17 Nov 2015 15:38:03 -0800 Subject: [PATCH] make activeSocket checks more consistent --- libraries/networking/src/LimitedNodeList.cpp | 42 ++++++++++---------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 0b9a04f039..333cdb99f0 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -300,15 +300,16 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiS qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& destinationNode) { Q_ASSERT(!packet->isPartOfMessage()); auto activeSocket = destinationNode.getActiveSocket(); - if (!activeSocket) { + + if (activeSocket) { + emit dataSent(destinationNode.getType(), packet->getDataSize()); + destinationNode.recordBytesSent(packet->getDataSize()); + + return sendPacket(std::move(packet), *activeSocket, destinationNode.getConnectionSecret()); + } else { qDebug() << "LimitedNodeList::sendPacket called without active socket for node" << destinationNode << "- not sending"; return 0; } - - emit dataSent(destinationNode.getType(), packet->getDataSize()); - destinationNode.recordBytesSent(packet->getDataSize()); - - return sendPacket(std::move(packet), *activeSocket, destinationNode.getConnectionSecret()); } qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const HifiSockAddr& sockAddr, @@ -329,24 +330,25 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const HifiS qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) { auto activeSocket = destinationNode.getActiveSocket(); - if (!activeSocket) { + + if (activeSocket) { + qint64 bytesSent = 0; + auto connectionSecret = destinationNode.getConnectionSecret(); + + // close the last packet in the list + packetList.closeCurrentPacket(); + + while (!packetList._packets.empty()) { + bytesSent += sendPacket(packetList.takeFront(), *activeSocket, connectionSecret); + } + + emit dataSent(destinationNode.getType(), bytesSent); + return bytesSent; + } else { qDebug() << "LimitedNodeList::sendPacketList called without active socket for node" << destinationNode << " - not sending."; return 0; } - - qint64 bytesSent = 0; - auto connectionSecret = destinationNode.getConnectionSecret(); - - // close the last packet in the list - packetList.closeCurrentPacket(); - - while (!packetList._packets.empty()) { - bytesSent += sendPacket(packetList.takeFront(), *activeSocket, connectionSecret); - } - - emit dataSent(destinationNode.getType(), bytesSent); - return bytesSent; } qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,