diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index ff10994e27..50bccc1ab3 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -287,7 +287,6 @@ bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber) { // increment the counters for data packets received ++_packetsSinceACK; - ++_totalReceivedDataPackets; // check if we need to send an ACK, according to CC params if (_congestionControl->_ackInterval > 0 && _packetsSinceACK >= _congestionControl->_ackInterval) { diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index 2cacdf9fe9..c8313ed2fd 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -39,7 +39,7 @@ public: Connection(Socket* parentSocket, HifiSockAddr destination, std::unique_ptr congestionControl); ~Connection(); - + void sendReliablePacket(std::unique_ptr packet); void sync(); // rate control method, fired by Socket for all connections on SYN interval @@ -103,10 +103,8 @@ private: std::unique_ptr _congestionControl; - std::unique_ptr _sendQueue; + std::unique_ptr _sendQueue; - // Data packet stat collection - int _totalReceivedDataPackets { 0 }; int _packetsSinceACK { 0 }; // The number of packets that have been received during the current ACK interval ConnectionStats _stats; diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 99cdb06b29..04fa835f2c 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -95,7 +95,7 @@ qint64 Socket::writePacket(const Packet& packet, const HifiSockAddr& sockAddr) { qint64 Socket::writePacket(std::unique_ptr packet, const HifiSockAddr& sockAddr) { if (packet->isReliable()) { - findOrCreateConnection(sockAddr)->sendReliablePacket(move(packet)); + findOrCreateConnection(sockAddr).sendReliablePacket(move(packet)); return 0; } @@ -117,14 +117,15 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc return bytesWritten; } -Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) { +Connection& Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) { auto it = _connectionsHash.find(sockAddr); if (it == _connectionsHash.end()) { - it = _connectionsHash.insert(it, std::make_pair(sockAddr, new Connection(this, sockAddr, _ccFactory->create()))); + it = _connectionsHash.insert(it, std::make_pair(sockAddr, + std::unique_ptr(new Connection(this, sockAddr, _ccFactory->create())))); } - return it->second; + return *it->second; } void Socket::readPendingDatagrams() { @@ -160,8 +161,8 @@ void Socket::readPendingDatagrams() { auto controlPacket = ControlPacket::fromReceivedPacket(std::move(buffer), packetSizeWithHeader, senderSockAddr); // move this control packet to the matching connection - auto connection = findOrCreateConnection(senderSockAddr); - connection->processControl(move(controlPacket)); + auto& connection = findOrCreateConnection(senderSockAddr); + connection.processControl(move(controlPacket)); } else { // setup a Packet from the data we just read @@ -172,8 +173,8 @@ void Socket::readPendingDatagrams() { if (packet->isReliable()) { // if this was a reliable packet then signal the matching connection with the sequence number - auto connection = findOrCreateConnection(senderSockAddr); - connection->processReceivedSequenceNumber(packet->getSequenceNumber()); + auto& connection = findOrCreateConnection(senderSockAddr); + connection.processReceivedSequenceNumber(packet->getSequenceNumber()); } if (_packetHandler) { @@ -188,7 +189,7 @@ void Socket::readPendingDatagrams() { void Socket::connectToSendSignal(const HifiSockAddr& destinationAddr, QObject* receiver, const char* slot) { auto it = _connectionsHash.find(destinationAddr); if (it != _connectionsHash.end()) { - connect(it->second, SIGNAL(packetSent()), receiver, slot); + connect(it->second.get(), SIGNAL(packetSent()), receiver, slot); } } diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 4f947e4043..a8ff255b8d 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -23,11 +23,11 @@ #include "../HifiSockAddr.h" #include "CongestionControl.h" +#include "Connection.h" namespace udt { class BasePacket; -class Connection; class ControlSender; class Packet; class SequenceNumber; @@ -70,7 +70,7 @@ private slots: private: void setSystemBufferSizes(); - Connection* findOrCreateConnection(const HifiSockAddr& sockAddr); + Connection& findOrCreateConnection(const HifiSockAddr& sockAddr); QUdpSocket _udpSocket { this }; PacketFilterOperator _packetFilterOperator; @@ -78,7 +78,7 @@ private: std::unordered_map _unfilteredHandlers; std::unordered_map _unreliableSequenceNumbers; - std::unordered_map _connectionsHash; + std::unordered_map> _connectionsHash; int32_t _synInterval = 10; // 10ms QTimer _synTimer;