expire the connection if it is 16 timeouts since data

This commit is contained in:
Stephen Birarda 2015-08-28 15:07:07 -07:00
parent d6310da8c8
commit abffc0317b
2 changed files with 21 additions and 1 deletions

View file

@ -138,6 +138,21 @@ void Connection::queueReceivedMessagePacket(std::unique_ptr<Packet> packet) {
void Connection::sync() {
if (_hasReceivedFirstPacket) {
// check if it's time for us to consider this connection inactive
// we are inactive if it has been 16 * the estimated timeout since our last receive
static const int NUM_TIMEOUTS_FOR_EXPIRY = 16;
auto sinceLastReceive = duration_cast<microseconds>(high_resolution_clock::now() - _lastReceiveTime);
if (sinceLastReceive.count() >= NUM_TIMEOUTS_FOR_EXPIRY * estimatedTimeout()) {
// connection inactive - emit a signal so we will be cleaned up
emit connectionInactive(_destination);
// return to abort before regular processing
return;
}
// reset the number of light ACKs or non SYN ACKs during this sync interval
_lightACKsDuringSYN = 1;
_acksDuringSYN = 1;
@ -347,6 +362,9 @@ bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, in
_hasReceivedFirstPacket = true;
// mark our last receive time as now (to push the potential expiry farther)
_lastReceiveTime = high_resolution_clock::now();
// check if this is a packet pair we should estimate bandwidth from, or just a regular packet
if (((uint32_t) sequenceNumber & 0xF) == 0) {
_receiveWindow.onProbePair1Arrival();

View file

@ -73,7 +73,7 @@ public:
signals:
void packetSent();
void connectionInactive(HifiSockAddr sockAdrr);
void connectionInactive(const HifiSockAddr& sockAddr);
private slots:
void recordSentPackets(int payload, int total);
@ -118,6 +118,8 @@ private:
bool _hasReceivedHandshake { false }; // flag for receipt of handshake from server
bool _hasReceivedHandshakeACK { false }; // flag for receipt of handshake ACK from client
std::chrono::high_resolution_clock::time_point _lastReceiveTime; // holds the last time we received anything from sender
LossList _lossList; // List of all missing packets
SequenceNumber _lastReceivedSequenceNumber; // The largest sequence number received from the peer
SequenceNumber _lastReceivedACK; // The last ACK received