Skip to content
Snippets Groups Projects
Commit efb32d59 authored by Adrien Béraud's avatar Adrien Béraud Committed by Adrien Béraud
Browse files

MultiplexedSocket: unlock during onChannelReady

Change-Id: I5c29a6f20ec6a338135f79126a85c0377222bb9b
parent 82d4e6b7
Branches
No related tags found
No related merge requests found
...@@ -284,19 +284,21 @@ MultiplexedSocket::Impl::eventLoop() ...@@ -284,19 +284,21 @@ MultiplexedSocket::Impl::eventLoop()
void void
MultiplexedSocket::Impl::onAccept(const std::string& name, uint16_t channel) MultiplexedSocket::Impl::onAccept(const std::string& name, uint16_t channel)
{ {
std::lock_guard lkSockets(socketsMutex); std::unique_lock lk(socketsMutex);
auto& socket = sockets[channel]; auto socket = sockets[channel];
if (!socket) { if (!socket) {
if (logger_) if (logger_)
logger_->error("Receiving an answer for a non existing channel. This is a bug."); logger_->error("Receiving an answer for a non existing channel. This is a bug.");
return; return;
} }
lk.unlock();
onChannelReady_(deviceId, socket); onChannelReady_(deviceId, socket);
socket->ready(true); socket->ready(true);
// Due to the callbacks that can take some time, onAccept can arrive after // Due to the callbacks that can take some time, onAccept can arrive after
// receiving all the data. In this case, the socket should be removed here // receiving all the data. In this case, the socket should be removed here
// as handle by onChannelReady_ // as handle by onChannelReady_
lk.lock();
if (socket->isRemovable()) if (socket->isRemovable())
sockets.erase(channel); sockets.erase(channel);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment