Remove dependency on AsyncInvoker in SctpTransport

Bug: webrtc:11988
Change-Id: I996aa220a00b61fb5080803bffe7a37c6b90aaec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/193866
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32645}
This commit is contained in:
Tomas Gunnarsson 2020-11-18 09:38:14 +01:00 committed by Commit Bot
parent 04fed3c7ea
commit bff717e4f9
5 changed files with 24 additions and 14 deletions

View File

@ -408,6 +408,8 @@ rtc_library("rtc_data") {
"../rtc_base",
"../rtc_base:rtc_base_approved",
"../rtc_base/synchronization:mutex",
"../rtc_base/task_utils:pending_task_safety_flag",
"../rtc_base/task_utils:to_queued_task",
"../rtc_base/third_party/sigslot",
"../system_wrappers",
]

View File

@ -46,6 +46,7 @@ constexpr int kSctpSuccessReturn = 1;
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_utils/to_queued_task.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
#include "rtc_base/trace_event.h"
@ -386,11 +387,12 @@ class SctpTransport::UsrSctpWrapper {
VerboseLogPacket(data, length, SCTP_DUMP_OUTBOUND);
// Note: We have to copy the data; the caller will delete it.
rtc::CopyOnWriteBuffer buf(reinterpret_cast<uint8_t*>(data), length);
// TODO(deadbeef): Why do we need an AsyncInvoke here? We're already on the
// right thread and don't need to unwind the stack.
transport->invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, transport->network_thread_,
rtc::Bind(&SctpTransport::OnPacketFromSctpToNetwork, transport, buf));
transport->network_thread_->PostTask(ToQueuedTask(
transport->task_safety_, [transport, buf = std::move(buf)]() {
transport->OnPacketFromSctpToNetwork(buf);
}));
return 0;
}
@ -497,6 +499,7 @@ SctpTransport::SctpTransport(rtc::Thread* network_thread,
}
SctpTransport::~SctpTransport() {
RTC_DCHECK_RUN_ON(network_thread_);
// Close abruptly; no reset procedure.
CloseSctpSocket();
// It's not strictly necessary to reset these fields to nullptr,
@ -1165,9 +1168,10 @@ int SctpTransport::OnDataOrNotificationFromSctp(void* data,
// Copy and dispatch asynchronously
rtc::CopyOnWriteBuffer notification(reinterpret_cast<uint8_t*>(data),
length);
invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, network_thread_,
rtc::Bind(&SctpTransport::OnNotificationFromSctp, this, notification));
network_thread_->PostTask(ToQueuedTask(
task_safety_, [this, notification = std::move(notification)]() {
OnNotificationFromSctp(notification);
}));
return kSctpSuccessReturn;
}
@ -1239,10 +1243,11 @@ int SctpTransport::OnDataOrNotificationFromSctp(void* data,
// Dispatch the complete message.
// The ownership of the packet transfers to |invoker_|. Using
// CopyOnWriteBuffer is the most convenient way to do this.
invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, network_thread_,
rtc::Bind(&SctpTransport::OnDataFromSctpToTransport, this, params,
partial_incoming_message_));
network_thread_->PostTask(webrtc::ToQueuedTask(
task_safety_, [this, params = std::move(params),
message = partial_incoming_message_]() {
OnDataFromSctpToTransport(params, message);
}));
// Reset the message buffer
partial_incoming_message_.Clear();

View File

@ -22,10 +22,10 @@
#include "absl/types/optional.h"
#include "api/transport/sctp_transport_factory_interface.h"
#include "rtc_base/async_invoker.h"
#include "rtc_base/buffer.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/task_utils/pending_task_safety_flag.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
// For SendDataParams/ReceiveDataParams.
@ -199,7 +199,7 @@ class SctpTransport : public SctpTransportInternal,
// outgoing data to the network interface.
rtc::Thread* network_thread_;
// Helps pass inbound/outbound packets asynchronously to the network thread.
rtc::AsyncInvoker invoker_;
webrtc::ScopedTaskSafety task_safety_;
// Underlying DTLS transport.
rtc::PacketTransportInternal* transport_ = nullptr;

View File

@ -14,6 +14,7 @@
#include <string>
#include "media/sctp/sctp_transport_internal.h"
#include "rtc_base/async_invoker.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"

View File

@ -13,6 +13,8 @@
#include <algorithm>
#include <utility>
#include "rtc_base/bind.h"
namespace webrtc {
SctpTransport::SctpTransport(