Commit a7ad5bbf authored by Adrien Béraud's avatar Adrien Béraud Committed by Guillaume Roguez

daemon: receive ICE packets without blocking the ICE mutex

This was causing deadlock.
We now pool ice packets in the main loop.

Refs #63250

Change-Id: I001987955e1a927ed259291d9b0f0af0043ec84e
parent 5e57f44a
......@@ -165,10 +165,10 @@ SipIceTransport::~SipIceTransport()
}
void
SipIceTransport::start()
SipIceTransport::loop()
{
using namespace std::placeholders;
ice_->setOnRecv(comp_id_, std::bind(&SipIceTransport::onRecv, this, _1, _2));
while (ice_->getNextPacketSize(comp_id_) > 0)
onRecv();
}
IpAddr
......@@ -215,11 +215,11 @@ SipIceTransport::send(pjsip_tx_data *tdata, const pj_sockaddr_t *rem_addr,
}
ssize_t
SipIceTransport::onRecv(uint8_t* buf, size_t len)
SipIceTransport::onRecv()
{
auto max_size = std::min<size_t>(sizeof(rdata.pkt_info.packet) - rdata.pkt_info.len, len);
std::copy_n(buf, max_size, (uint8_t*)rdata.pkt_info.packet + rdata.pkt_info.len);
rdata.pkt_info.len += max_size;
rdata.pkt_info.len += ice_->recv(comp_id_,
(uint8_t*)rdata.pkt_info.packet+rdata.pkt_info.len,
sizeof(rdata.pkt_info.packet)-rdata.pkt_info.len);
rdata.pkt_info.zero = 0;
pj_gettimeofday(&rdata.pkt_info.timestamp);
......
......@@ -49,9 +49,9 @@ struct SipIceTransport
~SipIceTransport();
/**
* To be called once to start receiving packets
* To be called on a regular basis to receive packets
*/
void start();
void loop();
IpAddr getLocalAddress() const;
......@@ -76,7 +76,7 @@ struct SipIceTransport
int addr_len, void *token,
pjsip_transport_callback callback);
ssize_t onRecv(uint8_t* buf, size_t len);
ssize_t onRecv();
pj_status_t shutdown();
......
......@@ -160,11 +160,14 @@ cp_(cp), pool_(pool), endpt_(endpt)
#if HAVE_DHT
pjsip_transport_register_type(PJSIP_TRANSPORT_DATAGRAM, "ICE", pjsip_transport_get_default_port_for_type(PJSIP_TRANSPORT_UDP), &ice_pj_transport_type_);
#endif
Manager::instance().registerEventHandler((uintptr_t)this, [this]{ handleEvents(); });
}
SipTransportBroker::~SipTransportBroker()
{
SFL_DBG("Destroying SipTransportBroker");
Manager::instance().unregisterEventHandler((uintptr_t)this);
{
std::lock_guard<std::mutex> lock(transportMapMutex_);
......@@ -239,6 +242,14 @@ SipTransportBroker::transportStateChanged(pjsip_transport* tp, pjsip_transport_s
}
}
void
SipTransportBroker::handleEvents()
{
std::unique_lock<std::mutex> lock(iceMutex_);
for (auto& t : iceTransports_)
t.loop();
}
std::shared_ptr<SipTransport>
SipTransportBroker::findTransport(pjsip_transport* t)
{
......@@ -432,7 +443,6 @@ SipTransportBroker::getIceTransport(const std::shared_ptr<sfl::IceTransport> ice
std::unique_lock<std::mutex> lock(transportMapMutex_);
transports_[ret->get()] = ret;
}
sip_ice_tr.start();
return ret;
}
#endif
......
......@@ -213,6 +213,8 @@ private:
void transportStateChanged(pjsip_transport*, pjsip_transport_state, const pjsip_transport_state_info*);
void handleEvents();
/**
* List of transports so we can bubble the events up.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment