diff options
author | Niels Möller <nisse@webrtc.org> | 2021-03-22 11:42:56 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-22 12:56:26 +0000 |
commit | ffb7603b6025fbd6e79f360d293ab49092bded54 (patch) | |
tree | adf0bd30f9a449d9e405fbc91496439c4fda1f5a /p2p | |
parent | eb282985e9dd8b40417a6b8c03d2350104cf24bb (diff) | |
download | webrtc-ffb7603b6025fbd6e79f360d293ab49092bded54.tar.gz |
Delete TurnPort usage of AsyncInvoker
Bug: webrtc:12339
Change-Id: I098b5f4b58c3ac0c275157c0c9d5a280b1cbef97
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212440
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Taylor <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33524}
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/base/turn_port.cc | 13 | ||||
-rw-r--r-- | p2p/base/turn_port.h | 9 | ||||
-rw-r--r-- | p2p/base/turn_port_unittest.cc | 9 |
3 files changed, 17 insertions, 14 deletions
diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index 57de15e0b5..33925d43e7 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -28,6 +28,7 @@ #include "rtc_base/net_helpers.h" #include "rtc_base/socket_address.h" #include "rtc_base/strings/string_builder.h" +#include "rtc_base/task_utils/to_queued_task.h" #include "system_wrappers/include/field_trial.h" namespace cricket { @@ -1288,12 +1289,12 @@ void TurnPort::ScheduleEntryDestruction(TurnEntry* entry) { RTC_DCHECK(!entry->destruction_timestamp().has_value()); int64_t timestamp = rtc::TimeMillis(); entry->set_destruction_timestamp(timestamp); - invoker_.AsyncInvokeDelayed<void>( - RTC_FROM_HERE, thread(), - [this, entry, timestamp] { - DestroyEntryIfNotCancelled(entry, timestamp); - }, - TURN_PERMISSION_TIMEOUT); + thread()->PostDelayedTask(ToQueuedTask(task_safety_.flag(), + [this, entry, timestamp] { + DestroyEntryIfNotCancelled( + entry, timestamp); + }), + TURN_PERMISSION_TIMEOUT); } bool TurnPort::SetEntryChannelId(const rtc::SocketAddress& address, diff --git a/p2p/base/turn_port.h b/p2p/base/turn_port.h index 349190b4ae..55dbda5ece 100644 --- a/p2p/base/turn_port.h +++ b/p2p/base/turn_port.h @@ -23,10 +23,10 @@ #include "absl/memory/memory.h" #include "p2p/base/port.h" #include "p2p/client/basic_port_allocator.h" -#include "rtc_base/async_invoker.h" #include "rtc_base/async_packet_socket.h" #include "rtc_base/async_resolver_interface.h" #include "rtc_base/ssl_certificate.h" +#include "rtc_base/task_utils/pending_task_safety_flag.h" namespace webrtc { class TurnCustomizer; @@ -227,9 +227,6 @@ class TurnPort : public Port { rtc::AsyncPacketSocket* socket() const { return socket_; } - // For testing only. - rtc::AsyncInvoker* invoker() { return &invoker_; } - // Signal with resolved server address. // Parameters are port, server address and resolved server address. // This signal will be sent only if server address is resolved successfully. @@ -415,8 +412,6 @@ class TurnPort : public Port { // The number of retries made due to allocate mismatch error. size_t allocate_mismatch_retries_; - rtc::AsyncInvoker invoker_; - // Optional TurnCustomizer that can modify outgoing messages. Once set, this // must outlive the TurnPort's lifetime. webrtc::TurnCustomizer* turn_customizer_ = nullptr; @@ -429,6 +424,8 @@ class TurnPort : public Port { // to be more easy to work with. std::string turn_logging_id_; + webrtc::ScopedTaskSafety task_safety_; + friend class TurnEntry; friend class TurnAllocateRequest; friend class TurnRefreshRequest; diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index 5df9f67ef1..6d396ad520 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc @@ -634,6 +634,11 @@ class TurnPortTest : public ::testing::Test, Port::ORIGIN_MESSAGE); Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); + + // Increased to 10 minutes, to ensure that the TurnEntry times out before + // the TurnPort. + turn_port_->set_timeout_delay(10 * 60 * 1000); + ASSERT_TRUE(conn2 != NULL); ASSERT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kSimulatedRtt, fake_clock_); @@ -650,11 +655,11 @@ class TurnPortTest : public ::testing::Test, EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt, fake_clock_); - // Flush all requests in the invoker to destroy the TurnEntry. + // Wait for TurnEntry to expire. Timeout is 5 minutes. // Expect that it still processes an incoming ping and signals the // unknown address. turn_unknown_address_ = false; - turn_port_->invoker()->Flush(rtc::Thread::Current()); + fake_clock_.AdvanceTime(webrtc::TimeDelta::Seconds(5 * 60)); conn1->Ping(0); EXPECT_TRUE_SIMULATED_WAIT(turn_unknown_address_, kSimulatedRtt, fake_clock_); |