From 4333600357a8e985cb5808fa45dc156aba46ebf8 Mon Sep 17 00:00:00 2001 From: Jonas Oreland Date: Thu, 26 Mar 2020 20:59:03 +0100 Subject: [PATCH] Modify IceControllerInterface::SelectConnectionToPing - step 2 this is a NOP refactoring, that modify return type of IceControllerInterface::SelectConnectionToPing to a struct (rather than existing pair). The modification is done so that one can safely add new return values in the struct. Step 1) Create a typedef for return value. - merge downstream and change it to start using new type. Step 2) Change typedef to struct, adding constructors from old type to new type merge and change downstream to use "real" constructors Step 3) remove temporary constructors Step 4) Eat cake Each step requires a merge downstream, with corresponding changes there. Bug: chromium:1024965 Change-Id: I79df9528f842ea73ca8896cedd62ad3a5cf5b767 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/171807 Reviewed-by: Harald Alvestrand Commit-Queue: Jonas Oreland Cr-Commit-Position: refs/heads/master@{#30914} --- p2p/base/basic_ice_controller.cc | 4 ++-- p2p/base/ice_controller_interface.h | 19 ++++++++++++++++--- p2p/base/p2p_transport_channel.cc | 5 +++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/p2p/base/basic_ice_controller.cc b/p2p/base/basic_ice_controller.cc index 32febb5a33..aa20025b2c 100644 --- a/p2p/base/basic_ice_controller.cc +++ b/p2p/base/basic_ice_controller.cc @@ -110,8 +110,8 @@ IceControllerInterface::PingResult BasicIceController::SelectConnectionToPing( if (rtc::TimeMillis() >= last_ping_sent_ms + ping_interval) { conn = FindNextPingableConnection(); } - return std::make_pair(const_cast(conn), - std::min(ping_interval, check_receiving_interval())); + PingResult res(conn, std::min(ping_interval, check_receiving_interval())); + return res; } void BasicIceController::MarkConnectionPinged(const Connection* conn) { diff --git a/p2p/base/ice_controller_interface.h b/p2p/base/ice_controller_interface.h index ecfb0c845d..8bc6ba9010 100644 --- a/p2p/base/ice_controller_interface.h +++ b/p2p/base/ice_controller_interface.h @@ -73,9 +73,22 @@ class IceControllerInterface { absl::optional recheck_event; }; - // A temporary typedef, so that we can migrate downstream - // to a new return value for SelectConnectionToPing. - typedef std::pair PingResult; + // This represents the result of a call to SelectConnectionToPing. + struct PingResult { + PingResult(const Connection* conn, int _recheck_delay_ms) + : connection(conn), recheck_delay_ms(_recheck_delay_ms) {} + + // A temporary constructor while merging. + // Will be removed once downstream has been updated. + PingResult(const std::pair& pair) // NOLINT + : connection(pair.first), recheck_delay_ms(pair.second) {} + + // Connection that we should (optionally) ping. + const absl::optional connection; + + // The delay before calling SelectConnectionToPing() again. + const int recheck_delay_ms = 0; + }; virtual ~IceControllerInterface() = default; diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index fe6df2015f..6937b20304 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -1888,8 +1888,9 @@ void P2PTransportChannel::CheckAndPing() { UpdateConnectionStates(); auto result = ice_controller_->SelectConnectionToPing(last_ping_sent_ms_); - Connection* conn = const_cast(result.first); - int delay = result.second; + Connection* conn = + const_cast(result.connection.value_or(nullptr)); + int delay = result.recheck_delay_ms; if (conn) { PingConnection(conn);