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

Side by Side Diff: webrtc/p2p/base/port.cc

Issue 2184013003: Delay destroying a port if new connections are created and destroyed. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // Send the response message. 638 // Send the response message.
639 rtc::ByteBufferWriter buf; 639 rtc::ByteBufferWriter buf;
640 response.Write(&buf); 640 response.Write(&buf);
641 rtc::PacketOptions options(DefaultDscpValue()); 641 rtc::PacketOptions options(DefaultDscpValue());
642 SendTo(buf.Data(), buf.Length(), addr, options, false); 642 SendTo(buf.Data(), buf.Length(), addr, options, false);
643 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason 643 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason
644 << " to " << addr.ToSensitiveString(); 644 << " to " << addr.ToSensitiveString();
645 } 645 }
646 646
647 void Port::OnMessage(rtc::Message *pmsg) { 647 void Port::OnMessage(rtc::Message *pmsg) {
648 ASSERT(pmsg->message_id == MSG_DEAD); 648 ASSERT(pmsg->message_id == MSG_CHECK_DEAD);
649 if (dead()) { 649 if (dead()) {
650 Destroy(); 650 Destroy();
651 } 651 }
652 } 652 }
653 653
654 void Port::OnNetworkTypeChanged(const rtc::Network* network) { 654 void Port::OnNetworkTypeChanged(const rtc::Network* network) {
655 ASSERT(network == network_); 655 ASSERT(network == network_);
656 656
657 UpdateNetworkCost(); 657 UpdateNetworkCost();
658 } 658 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 void Port::OnConnectionDestroyed(Connection* conn) { 695 void Port::OnConnectionDestroyed(Connection* conn) {
696 AddressMap::iterator iter = 696 AddressMap::iterator iter =
697 connections_.find(conn->remote_candidate().address()); 697 connections_.find(conn->remote_candidate().address());
698 ASSERT(iter != connections_.end()); 698 ASSERT(iter != connections_.end());
699 connections_.erase(iter); 699 connections_.erase(iter);
700 HandleConnectionDestroyed(conn); 700 HandleConnectionDestroyed(conn);
701 701
702 // On the controlled side, ports time out after all connections fail. 702 // On the controlled side, ports time out after all connections fail.
703 // Note: If a new connection is added after this message is posted, but it 703 // Note: If a new connection is added after this message is posted, but it
704 // fails and is removed before kPortTimeoutDelay, then this message will 704 // fails and is removed before kPortTimeoutDelay, then this message will
705 // still cause the Port to be destroyed. 705 // not cause the Port to be destroyed.
706 if (dead()) { 706 if (ice_role_ == ICEROLE_CONTROLLED && connections_.empty()) {
707 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_DEAD); 707 last_time_all_connections_removed_ = rtc::TimeMillis();
708 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, MSG_CHECK_DEAD);
708 } 709 }
709 } 710 }
710 711
712 bool Port::dead() const {
713 return ice_role_ == ICEROLE_CONTROLLED && connections_.empty() &&
714 rtc::TimeMillis() - last_time_all_connections_removed_ >=
715 timeout_delay_;
716 }
717
711 void Port::Destroy() { 718 void Port::Destroy() {
712 ASSERT(connections_.empty()); 719 ASSERT(connections_.empty());
713 LOG_J(LS_INFO, this) << "Port deleted"; 720 LOG_J(LS_INFO, this) << "Port deleted";
714 SignalDestroyed(this); 721 SignalDestroyed(this);
715 delete this; 722 delete this;
716 } 723 }
717 724
718 const std::string Port::username_fragment() const { 725 const std::string Port::username_fragment() const {
719 return ice_username_fragment_; 726 return ice_username_fragment_;
720 } 727 }
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 ASSERT(sent < 0); 1537 ASSERT(sent < 0);
1531 error_ = port_->GetError(); 1538 error_ = port_->GetError();
1532 stats_.sent_discarded_packets++; 1539 stats_.sent_discarded_packets++;
1533 } else { 1540 } else {
1534 send_rate_tracker_.AddSamples(sent); 1541 send_rate_tracker_.AddSamples(sent);
1535 } 1542 }
1536 return sent; 1543 return sent;
1537 } 1544 }
1538 1545
1539 } // namespace cricket 1546 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698