Add logs and small change in BasicPortAllocator.

The added logs will be helpful for debugging.
If a session has stopped, terminate DoAllocate early.
Session::init always returns true, so there is no need to check the return value.

R=deadbeef@webrtc.org, skvlad@webrtc.org

Review URL: https://codereview.webrtc.org/2267163002 .

Cr-Commit-Position: refs/heads/master@{#13871}
This commit is contained in:
Honghai Zhang 2016-08-23 15:47:33 -07:00
parent f99a9de069
commit 5048f5777d
3 changed files with 14 additions and 12 deletions

View File

@ -461,6 +461,7 @@ void P2PTransportChannel::MaybeStartGathering() {
} else {
AddAllocatorSession(allocator_->CreateSession(
transport_name(), component(), ice_ufrag_, ice_pwd_));
LOG(LS_INFO) << "Start getting ports";
allocator_sessions_.back()->StartGettingPorts();
}
}

View File

@ -549,10 +549,14 @@ void BasicPortAllocatorSession::DoAllocate() {
bool done_signal_needed = false;
std::vector<rtc::Network*> networks = GetNetworks();
if (IsStopped()) {
return;
}
if (networks.empty()) {
LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated";
done_signal_needed = true;
} else {
LOG(LS_INFO) << "Allocate ports on "<< networks.size() << " networks";
PortConfiguration* config = configs_.empty() ? nullptr : configs_.back();
for (uint32_t i = 0; i < networks.size(); ++i) {
uint32_t sequence_flags = flags();
@ -585,17 +589,12 @@ void BasicPortAllocatorSession::DoAllocate() {
AllocationSequence* sequence =
new AllocationSequence(this, networks[i], config, sequence_flags);
if (!sequence->Init()) {
delete sequence;
continue;
}
done_signal_needed = true;
sequence->SignalPortAllocationComplete.connect(
this, &BasicPortAllocatorSession::OnPortAllocationComplete);
if (!IsStopped()) {
sequence->Start();
}
sequence->Init();
sequence->Start();
sequences_.push_back(sequence);
done_signal_needed = true;
}
}
if (done_signal_needed) {
@ -618,7 +617,10 @@ void BasicPortAllocatorSession::OnNetworksChanged() {
}
RemovePortsAndCandidates(failed_networks);
network_manager_started_ = true;
if (!network_manager_started_) {
LOG(LS_INFO) << "Network manager is started";
network_manager_started_ = true;
}
if (allocation_started_)
DoAllocate();
}
@ -986,7 +988,7 @@ AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
phase_(0) {
}
bool AllocationSequence::Init() {
void AllocationSequence::Init() {
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
udp_socket_.reset(session_->socket_factory()->CreateUdpSocket(
rtc::SocketAddress(ip_, 0), session_->allocator()->min_port(),
@ -998,7 +1000,6 @@ bool AllocationSequence::Init() {
// Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP
// are next available options to setup a communication channel.
}
return true;
}
void AllocationSequence::Clear() {

View File

@ -288,7 +288,7 @@ class AllocationSequence : public rtc::MessageHandler,
PortConfiguration* config,
uint32_t flags);
~AllocationSequence();
bool Init();
void Init();
void Clear();
void OnNetworkFailed();