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

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: fix a comment 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..a2dbb9cfa22ed1fe365ece2aa7e1911741f43394 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,28 @@ void Port::SendBindingErrorResponse(StunMessage* request,
<< " to " << addr.ToSensitiveString();
}
+void Port::StartBeingUsed() {
+ is_used_ = true;
+}
+
+void Port::StopBeingUsed() {
+ is_used_ = false;
+ 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()) {
Destroy();
}
}
+bool Port::dead() const {
+ return !is_used_ && connections_.empty() &&
+ rtc::TimeMillis() - last_time_all_connections_removed_ >=
+ timeout_delay_;
+}
+
void Port::OnNetworkTypeChanged(const rtc::Network* network) {
ASSERT(network == network_);
@@ -699,12 +715,14 @@ 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 used by any channel.
// Note: If a new connection is added after this message is posted, but it
- // fails and is removed before kPortTimeoutDelay, then this message will
- // still cause the Port to be destroyed.
- if (dead()) {
- thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_DEAD);
+ // fails and is removed before kPortTimeoutDelay, then the port will not be
+ // destroyed until kPortTimeoutDelay milliseconds after the new connection
+ // is removed.
+ if (connections_.empty()) {
+ last_time_all_connections_removed_ = rtc::TimeMillis();
+ thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD);
}
}

Powered by Google App Engine
This is Rietveld 408576698