From 7a160db8dd54df9e34e548afa040b1c2e2439139 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 13 Jul 2015 12:58:26 -0700 Subject: [PATCH] sendPacketList first implementation --- libraries/networking/src/LimitedNodeList.cpp | 33 +++++++++++--------- libraries/networking/src/LimitedNodeList.h | 5 ++- libraries/networking/src/NLPacketList.h | 2 ++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index b668e91590..8895f09675 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -255,9 +255,7 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& } // use the node's active socket as the destination socket - auto destinationSockAddr = destinationNode.getActiveSocket(); - - return sendUnreliablePacket(packet, *destinationSockAddr); + return sendUnreliablePacket(packet, *destinationNode.getActiveSocket()); } qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr) { @@ -271,9 +269,7 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& } // use the node's active socket as the destination socket - auto destinationSockAddr = destinationNode.getActiveSocket(); - - return sendPacket(std::move(packet), *destinationSockAddr); + return sendPacket(std::move(packet), *destinationNode.getActiveSocket()); } qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const HifiSockAddr& sockAddr) { @@ -285,19 +281,26 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& des // we don't have a socket to send to, return 0 return 0; } - - // use the node's active socket as the destination socket - auto destinationSockAddr = destinationNode.getActiveSocket(); - - return sendPacketList(packetList, *destinationSockAddr); + return sendPacketList(packetList, *destinationNode.getActiveSocket()); } qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr) { - // for (auto packet : packetList) { - // - // } + qint64 bytesSent{ 0 }; + auto& packets = packetList._packets; + while (!packets.empty()) { + bytesSent += sendPacket(std::move(packets.front()), sockAddr); + packets.pop_front(); + } - assert(false); return 0; + return bytesSent; +} + +qint64 LimitedNodeList::sendPacket(std::unique_ptr packet, const Node& destinationNode, + const HifiSockAddr& overridenSockAddr) { + // use the node's active socket as the destination socket if there is no overriden socket address + auto& destinationSockAddr = (overridenSockAddr.isNull()) ? *destinationNode.getActiveSocket() + : overridenSockAddr; + return sendPacket(std::move(packet), destinationSockAddr); } PacketSequenceNumber LimitedNodeList::getNextSequenceNumberForPacket(const QUuid& nodeUUID, PacketType::Value packetType) { diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 715eedc33b..33f9ac9fd3 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -270,9 +270,8 @@ protected: void sendPacketToIceServer(PacketType::Value packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerRequestID = QUuid()); - qint64 sendPacket(std::unique_ptr packet, const SharedNodePointer& destinationNode, - const HifiSockAddr& overridenSockAddr) - { assert(false); return 0; } + qint64 sendPacket(std::unique_ptr packet, const Node& destinationNode, + const HifiSockAddr& overridenSockAddr); QUuid _sessionUUID; diff --git a/libraries/networking/src/NLPacketList.h b/libraries/networking/src/NLPacketList.h index a0a6cdd5eb..3b8150730f 100644 --- a/libraries/networking/src/NLPacketList.h +++ b/libraries/networking/src/NLPacketList.h @@ -41,6 +41,8 @@ protected: virtual qint64 readData(char* data, qint64 maxSize) { return 0; } private: + friend class LimitedNodeList; + NLPacketList(const NLPacketList& other) = delete; NLPacketList& operator=(const NLPacketList& other) = delete;