Skip to content

Commit

Permalink
SocketAPI: Remove listener immediately on lost connection
Browse files Browse the repository at this point in the history
To avoid situations where messages are attempted to be sent to dead
connections.
  • Loading branch information
ckamm committed Jan 17, 2019
1 parent d83485e commit 0bfe7ac
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gui/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ void SocketApi::onLostConnection()
{
qCInfo(lcSocketApi) << "Lost connection " << sender();
sender()->deleteLater();

auto socket = qobject_cast<QIODevice *>(sender());
ASSERT(socket);
_listeners.erase(std::remove_if(_listeners.begin(), _listeners.end(), ListenerHasSocketPred(socket)), _listeners.end());
}

void SocketApi::slotSocketDestroyed(QObject *obj)
Expand Down

0 comments on commit 0bfe7ac

Please sign in to comment.