Made connection hash hold unique ptr

This commit is contained in:
Atlante45 2015-07-31 10:42:43 -07:00
parent da7a8f6e2f
commit b437f3bca9
4 changed files with 15 additions and 17 deletions

View file

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

View file

@ -39,7 +39,7 @@ public:
Connection(Socket* parentSocket, HifiSockAddr destination, std::unique_ptr<CongestionControl> congestionControl);
~Connection();
void sendReliablePacket(std::unique_ptr<Packet> packet);
void sync(); // rate control method, fired by Socket for all connections on SYN interval
@ -103,10 +103,8 @@ private:
std::unique_ptr<CongestionControl> _congestionControl;
std::unique_ptr<SendQueue> _sendQueue;
std::unique_ptr<SendQueue> _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;

View file

@ -95,7 +95,7 @@ qint64 Socket::writePacket(const Packet& packet, const HifiSockAddr& sockAddr) {
qint64 Socket::writePacket(std::unique_ptr<Packet> 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<Connection>(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);
}
}

View file

@ -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<HifiSockAddr, BasePacketHandler> _unfilteredHandlers;
std::unordered_map<HifiSockAddr, SequenceNumber> _unreliableSequenceNumbers;
std::unordered_map<HifiSockAddr, Connection*> _connectionsHash;
std::unordered_map<HifiSockAddr, std::unique_ptr<Connection>> _connectionsHash;
int32_t _synInterval = 10; // 10ms
QTimer _synTimer;