Add checks for Connection construction/destruction.
Make sure that instances are always created+deleted on the network thread. Bug: webrtc:11988 Change-Id: I4fb5dd5bd14768d89ca78b348988a797fcdd130a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249942 Reviewed-by: Niels Moller <nisse@webrtc.org> Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35842}
This commit is contained in:
parent
66c4036d1b
commit
cb01e5ecb2
@ -282,7 +282,8 @@ int ConnectionRequest::resend_delay() {
|
|||||||
Connection::Connection(Port* port,
|
Connection::Connection(Port* port,
|
||||||
size_t index,
|
size_t index,
|
||||||
const Candidate& remote_candidate)
|
const Candidate& remote_candidate)
|
||||||
: id_(rtc::CreateRandomId()),
|
: network_thread_(port->thread()),
|
||||||
|
id_(rtc::CreateRandomId()),
|
||||||
port_(port),
|
port_(port),
|
||||||
local_candidate_index_(index),
|
local_candidate_index_(index),
|
||||||
remote_candidate_(remote_candidate),
|
remote_candidate_(remote_candidate),
|
||||||
@ -304,6 +305,7 @@ Connection::Connection(Port* port,
|
|||||||
time_created_ms_(rtc::TimeMillis()),
|
time_created_ms_(rtc::TimeMillis()),
|
||||||
field_trials_(&kDefaultFieldTrials),
|
field_trials_(&kDefaultFieldTrials),
|
||||||
rtt_estimate_(DEFAULT_RTT_ESTIMATE_HALF_TIME_MS) {
|
rtt_estimate_(DEFAULT_RTT_ESTIMATE_HALF_TIME_MS) {
|
||||||
|
RTC_DCHECK_RUN_ON(network_thread());
|
||||||
// All of our connections start in WAITING state.
|
// All of our connections start in WAITING state.
|
||||||
// TODO(mallinath) - Start connections from STATE_FROZEN.
|
// TODO(mallinath) - Start connections from STATE_FROZEN.
|
||||||
// Wire up to send stun packets
|
// Wire up to send stun packets
|
||||||
@ -311,7 +313,13 @@ Connection::Connection(Port* port,
|
|||||||
RTC_LOG(LS_INFO) << ToString() << ": Connection created";
|
RTC_LOG(LS_INFO) << ToString() << ": Connection created";
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection::~Connection() {}
|
Connection::~Connection() {
|
||||||
|
RTC_DCHECK_RUN_ON(network_thread());
|
||||||
|
}
|
||||||
|
|
||||||
|
webrtc::TaskQueueBase* Connection::network_thread() const {
|
||||||
|
return network_thread_;
|
||||||
|
}
|
||||||
|
|
||||||
const Candidate& Connection::local_candidate() const {
|
const Candidate& Connection::local_candidate() const {
|
||||||
RTC_DCHECK(local_candidate_index_ < port_->Candidates().size());
|
RTC_DCHECK(local_candidate_index_ < port_->Candidates().size());
|
||||||
@ -750,6 +758,7 @@ void Connection::Destroy() {
|
|||||||
// tests, with a workaround in
|
// tests, with a workaround in
|
||||||
// AutoSocketServerThread::~AutoSocketServerThread.
|
// AutoSocketServerThread::~AutoSocketServerThread.
|
||||||
RTC_LOG(LS_VERBOSE) << ToString() << ": Connection destroyed";
|
RTC_LOG(LS_VERBOSE) << ToString() << ": Connection destroyed";
|
||||||
|
// TODO(bugs.webrtc.org/11988): Use PostTask.
|
||||||
port_->thread()->Post(RTC_FROM_HERE, this, MSG_DELETE);
|
port_->thread()->Post(RTC_FROM_HERE, this, MSG_DELETE);
|
||||||
LogCandidatePairConfig(webrtc::IceCandidatePairConfigType::kDestroyed);
|
LogCandidatePairConfig(webrtc::IceCandidatePairConfigType::kDestroyed);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,6 +88,8 @@ class Connection : public CandidatePairInterface,
|
|||||||
// A unique ID assigned when the connection is created.
|
// A unique ID assigned when the connection is created.
|
||||||
uint32_t id() const { return id_; }
|
uint32_t id() const { return id_; }
|
||||||
|
|
||||||
|
webrtc::TaskQueueBase* network_thread() const;
|
||||||
|
|
||||||
// Implementation of virtual methods in CandidatePairInterface.
|
// Implementation of virtual methods in CandidatePairInterface.
|
||||||
// Returns the description of the local port
|
// Returns the description of the local port
|
||||||
const Candidate& local_candidate() const override;
|
const Candidate& local_candidate() const override;
|
||||||
@ -369,8 +371,14 @@ class Connection : public CandidatePairInterface,
|
|||||||
Port* port() { return port_; }
|
Port* port() { return port_; }
|
||||||
const Port* port() const { return port_; }
|
const Port* port() const { return port_; }
|
||||||
|
|
||||||
uint32_t id_;
|
// NOTE: A pointer to the network thread is held by `port_` so in theory we
|
||||||
Port* port_;
|
// shouldn't need to hold on to this pointer here, but rather defer to
|
||||||
|
// port_->thread(). However, some tests delete the classes in the wrong order
|
||||||
|
// so `port_` may be deleted before an instance of this class is deleted.
|
||||||
|
// TODO(tommi): This ^^^ should be fixed.
|
||||||
|
webrtc::TaskQueueBase* const network_thread_;
|
||||||
|
const uint32_t id_;
|
||||||
|
Port* const port_;
|
||||||
size_t local_candidate_index_;
|
size_t local_candidate_index_;
|
||||||
Candidate remote_candidate_;
|
Candidate remote_candidate_;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user