Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Unified Diff: webrtc/p2p/base/port.cc

Issue 2171183002: Remove ports that are not used by any channel after timeout (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
}

Powered by Google App Engine
This is Rietveld 408576698