diff --git a/src/ringdht/sips_transport_ice.cpp b/src/ringdht/sips_transport_ice.cpp index 3f993d9cfbc79f9c0edc6ce214655b278eadb529..3356efed446e57446653baf251128aedf9901cbd 100644 --- a/src/ringdht/sips_transport_ice.cpp +++ b/src/ringdht/sips_transport_ice.cpp @@ -249,8 +249,6 @@ SipsIceTransport::SipsIceTransport(pjsip_endpoint* endpt, if (pjsip_transport_register(base.tpmgr, &base) != PJ_SUCCESS) throw std::runtime_error("Can't register PJSIP transport."); - - Manager::instance().registerEventHandler((uintptr_t)this, [this]{ handleEvents(); }); } SipsIceTransport::~SipsIceTransport() @@ -266,7 +264,6 @@ SipsIceTransport::~SipsIceTransport() } auto base = getTransportBase(); - Manager::instance().unregisterEventHandler((uintptr_t)this); // Stop low-level transport first tls_.reset(); @@ -394,6 +391,7 @@ SipsIceTransport::pushChangeStateEvent(ChangeStateEventData&& ev) { std::lock_guard<std::mutex> lk{stateChangeEventsMutex_}; stateChangeEvents_.emplace_back(std::move(ev)); + scheduler_.run([this]{ handleEvents(); }); } // - DO NOT BLOCK - (Called in TlsSession thread) @@ -412,6 +410,7 @@ SipsIceTransport::onRxData(std::vector<uint8_t>&& buf) { std::lock_guard<std::mutex> l(rxMtx_); rxPending_.emplace_back(std::move(buf)); + scheduler_.run([this]{ handleEvents(); }); } /* Update local & remote certificates info. This function should be @@ -698,6 +697,7 @@ SipsIceTransport::send(pjsip_tx_data* tdata, const pj_sockaddr_t* rem_addr, tdata->op_key.token = token; tdata->op_key.callback = callback; txQueue_.push_back(tdata); + scheduler_.run([this]{ handleEvents(); }); return PJ_EPENDING; } diff --git a/src/ringdht/sips_transport_ice.h b/src/ringdht/sips_transport_ice.h index bcbb368db7faf98248cb6d882491974728517364..74e9283e4a71ff251dffc6d461f5486031af59c1 100644 --- a/src/ringdht/sips_transport_ice.h +++ b/src/ringdht/sips_transport_ice.h @@ -24,6 +24,7 @@ #include "security/tls_session.h" #include "ip_utils.h" #include "noncopyable.h" +#include "scheduled_executor.h" #include <pjsip.h> #include <pj/pool.h> @@ -124,6 +125,8 @@ private: std::mutex rxMtx_; std::list<std::vector<uint8_t>> rxPending_; + ScheduledExecutor scheduler_; + pj_status_t send(pjsip_tx_data*, const pj_sockaddr_t*, int, void*, pjsip_transport_callback); void handleEvents(); void pushChangeStateEvent(ChangeStateEventData&&);