Index: webrtc/p2p/base/port.cc |
diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc |
index b6173ebf45768be331c589631f81f9aee8ccbc80..93d7e351e29fe07366bcc93a8ec8499269410291 100644 |
--- a/webrtc/p2p/base/port.cc |
+++ b/webrtc/p2p/base/port.cc |
@@ -198,6 +198,7 @@ void Port::Construct() { |
network_->SignalTypeChanged.connect(this, &Port::OnNetworkTypeChanged); |
network_cost_ = network_->GetCost(); |
+ thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD); |
LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_; |
} |
@@ -644,13 +645,29 @@ void Port::SendBindingErrorResponse(StunMessage* request, |
<< " to " << addr.ToSensitiveString(); |
} |
+void Port::BecomeReady() { |
+ // If it is pruned, we won't bring it up again. |
pthatcher1
2016/07/28 19:35:05
We should probably RTC_DCHECK(state_ == State::INI
honghaiz3
2016/07/28 22:51:44
It may happen that it was pruned first then it bec
|
+ if (state_ == State::INIT) { |
+ state_ = State::READY; |
+ } |
+} |
+ |
+void Port::Prune() { |
+ state_ = State::PRUNED; |
+ thread_->Post(RTC_FROM_HERE, this, MSG_CHECK_DEAD); |
+} |
+ |
void Port::OnMessage(rtc::Message *pmsg) { |
- ASSERT(pmsg->message_id == MSG_DEAD); |
+ ASSERT(pmsg->message_id == MSG_CHECK_DEAD); |
if (dead()) { |
pthatcher1
2016/07/28 19:35:05
Since there is only one place calling dead() now,
honghaiz3
2016/07/28 22:51:44
Done.
|
Destroy(); |
} |
} |
+bool Port::dead() const { |
+ return state_ != State::READY && connections_.empty(); |
pthatcher1
2016/07/28 19:35:05
I think (state_ == INIT || state_ == PRUNED) && co
honghaiz3
2016/07/28 22:51:44
Done.
|
+} |
+ |
void Port::OnNetworkTypeChanged(const rtc::Network* network) { |
ASSERT(network == network_); |
@@ -699,12 +716,12 @@ void Port::OnConnectionDestroyed(Connection* conn) { |
connections_.erase(iter); |
HandleConnectionDestroyed(conn); |
- // On the controlled side, ports time out after all connections fail. |
+ // Ports time out after all connections fail if it is not ready. |
// Note: If a new connection is added after this message is posted, but it |
- // fails and is removed before kPortTimeoutDelay, then this message will |
+ // fails and is removed before timeout_delay_, then this message will |
// still cause the Port to be destroyed. |
- if (dead()) { |
- thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_DEAD); |
+ if (connections_.empty()) { |
+ thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD); |
} |
} |