From beeea45d2e08233ead7eed5c41e4a6ba7fabd94a Mon Sep 17 00:00:00 2001 From: Grishka Date: Wed, 12 Dec 2018 03:28:11 +0300 Subject: [PATCH] I apparently still suck at C++ memory management --- VoIPController.cpp | 2 ++ VoIPController.h | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/VoIPController.cpp b/VoIPController.cpp index 9cd11ee..4df83f5 100755 --- a/VoIPController.cpp +++ b/VoIPController.cpp @@ -3431,6 +3431,8 @@ void VoIPController::UpdateQueuedPackets(){ } void VoIPController::SendNopPacket(){ + if(state!=STATE_ESTABLISHED) + return; SendOrEnqueuePacket(PendingOutgoingPacket{ /*.seq=*/(firstSentPing=GenerateOutSeq()), /*.type=*/PKT_NOP, diff --git a/VoIPController.h b/VoIPController.h index 354510d..4e9245f 100755 --- a/VoIPController.h +++ b/VoIPController.h @@ -403,13 +403,11 @@ namespace tgvoip{ double ackTime; }; struct PendingOutgoingPacket{ -#if defined(_MSC_VER) && _MSC_VER <= 1800 // VS2013 doesn't support auto-generating move constructors - //TGVOIP_DISALLOW_COPY_AND_ASSIGN(PendingOutgoingPacket); PendingOutgoingPacket(uint32_t seq, unsigned char type, size_t len, Buffer&& data, int64_t endpoint){ this->seq=seq; this->type=type; this->len=len; - this->data=data; + this->data=std::move(data); this->endpoint=endpoint; } PendingOutgoingPacket(PendingOutgoingPacket&& other){ @@ -419,7 +417,17 @@ namespace tgvoip{ data=std::move(other.data); endpoint=other.endpoint; } -#endif + PendingOutgoingPacket& operator=(PendingOutgoingPacket&& other){ + if(this!=&other){ + seq=other.seq; + type=other.type; + len=other.len; + data=std::move(other.data); + endpoint=other.endpoint; + } + return *this; + } + TGVOIP_DISALLOW_COPY_AND_ASSIGN(PendingOutgoingPacket); uint32_t seq; unsigned char type; size_t len;