From 921ba9a9d673752f49617f36553396c7ff290ae1 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 11 Aug 2014 19:32:07 -0400 Subject: [PATCH] limit max number of resends --- Streaming.cpp | 12 +++++++++++- Streaming.h | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Streaming.cpp b/Streaming.cpp index ad448820..f597014c 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -176,6 +176,7 @@ namespace stream SendQuickAck (); // send ack for close explicitly? m_IsOpen = false; m_ReceiveTimer.cancel (); + m_ResendTimer.cancel (); } } @@ -427,7 +428,16 @@ namespace stream if (ecode != boost::asio::error::operation_aborted) { for (auto it : m_SentPackets) - SendPacket (it->GetBuffer (), it->GetLength ()); + { + it->numResendAttempts++; + if (it->numResendAttempts <= MAX_NUM_RESEND_ATTEMPTS) + SendPacket (it->GetBuffer (), it->GetLength ()); + else + { + Close (); + return; + } + } ScheduleResend (); } } diff --git a/Streaming.h b/Streaming.h index 42df5278..b561fc5a 100644 --- a/Streaming.h +++ b/Streaming.h @@ -37,13 +37,15 @@ namespace stream const size_t MAX_PACKET_SIZE = 4096; const size_t COMPRESSION_THRESHOLD_SIZE = 66; const int RESEND_TIMEOUT = 10; // in seconds + const int MAX_NUM_RESEND_ATTEMPTS = 5; struct Packet { uint8_t buf[MAX_PACKET_SIZE]; size_t len, offset; - - Packet (): len (0), offset (0) {}; + int numResendAttempts; + + Packet (): len (0), offset (0), numResendAttempts (0) {}; uint8_t * GetBuffer () { return buf + offset; }; size_t GetLength () const { return len - offset; };