From 8e755c1ad2adfd12444e2cb72b080896ae1b783d Mon Sep 17 00:00:00 2001 From: "mallinath@webrtc.org" Date: Wed, 21 May 2014 23:00:46 +0000 Subject: [PATCH] Connect SignalDestroyed in AllocationSequence after TURN ports are destroyed when TURN ports are using shared socket with UDP port. This is required as AllocationSequence maintains a map of turn ports. If the ports are destroyed without the knowledge of AllocationSequence, sequence will try to deliver packets to the destoyed ports. R=jiayl@webrtc.org BUG=https://code.google.com/p/chromium/issues/detail?id=368877 Review URL: https://webrtc-codereview.appspot.com/14569007 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6219 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/p2p/client/basicportallocator.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/talk/p2p/client/basicportallocator.cc b/talk/p2p/client/basicportallocator.cc index b4ec2a117..762726fbb 100644 --- a/talk/p2p/client/basicportallocator.cc +++ b/talk/p2p/client/basicportallocator.cc @@ -102,6 +102,7 @@ class AllocationSequence : public talk_base::MessageHandler, uint32 flags); ~AllocationSequence(); bool Init(); + void Clear(); State state() const { return state_; } @@ -258,6 +259,12 @@ BasicPortAllocatorSession::~BasicPortAllocatorSession() { if (network_thread_ != NULL) network_thread_->Clear(this); + for (uint32 i = 0; i < sequences_.size(); ++i) { + // AllocationSequence should clear it's map entry for turn ports before + // ports are destroyed. + sequences_[i]->Clear(); + } + std::vector::iterator it; for (it = ports_.begin(); it != ports_.end(); it++) delete it->port(); @@ -727,6 +734,11 @@ bool AllocationSequence::Init() { return true; } +void AllocationSequence::Clear() { + udp_port_ = NULL; + turn_ports_.clear(); +} + AllocationSequence::~AllocationSequence() { session_->network_thread()->Clear(this); } @@ -1030,6 +1042,9 @@ void AllocationSequence::CreateTurnPort(const RelayServerConfig& config) { this, &AllocationSequence::OnResolvedTurnServerAddress); } turn_ports_[(*relay_port).address] = port; + // Listen to the port destroyed signal, to allow AllocationSequence to + // remove entrt from it's map. + port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); } else { port = TurnPort::Create(session_->network_thread(), session_->socket_factory(),