From 66336ccbd764357dd23101222e8b082a26a02a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 17 Sep 2020 15:10:26 -0400 Subject: [PATCH] ice: stop send if destroyed Change-Id: Icfe920a562f1b255a1371544775bae12dcb539c7 --- src/ice_transport.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ice_transport.cpp b/src/ice_transport.cpp index de5d42786f..d4ba46c1fc 100644 --- a/src/ice_transport.cpp +++ b/src/ice_transport.cpp @@ -196,6 +196,7 @@ public: pj_ssize_t lastSentLen_; std::condition_variable waitDataCv_ = {}; + std::atomic_bool destroying_ {false}; onShutdownCb scb; // Default remote adresses @@ -386,6 +387,8 @@ IceTransport::Impl::Impl(const char* name, icecb.on_destroy = [](pj_ice_strans* ice_st) { if (auto* tr = static_cast<Impl*>(pj_ice_strans_get_user_data(ice_st))) { + tr->destroying_ = true; + tr->waitDataCv_.notify_all(); if (tr->scb) tr->scb(); } else { @@ -1449,7 +1452,9 @@ IceTransport::send(int comp_id, const unsigned char* buf, size_t len) // NOTE; because we are in TCP, the sent size will count the header (2 // bytes length). std::unique_lock<std::mutex> lk(pimpl_->iceMutex_); - pimpl_->waitDataCv_.wait(lk, [&] { return pimpl_->lastSentLen_ >= len; }); + pimpl_->waitDataCv_.wait(lk, [&] { + return pimpl_->lastSentLen_ >= len or pimpl_->destroying_.load(); + }); pimpl_->lastSentLen_ = 0; } else if (status != PJ_SUCCESS && status != PJ_EPENDING) { if (status == PJ_EBUSY) { -- GitLab