Fix a warning and improve debug print when a client times out

Old code would implicitly delete the client by the call to abort()
as well as scheduling a deleteLater() which caused a unexpeted
null receiver warning.
improve-client-timeout
Michael Zanetti 2022-11-23 17:36:59 +01:00
parent fe76cb2d4b
commit c6d5364300
1 changed files with 2 additions and 3 deletions

View File

@ -231,10 +231,9 @@ void MqttServerPrivate::onClientConnected(MqttServerClient *client)
// Start a 10 second timer to clean up the connection if we don't get data until then.
QTimer *timeoutTimer = new QTimer(this);
connect(timeoutTimer, &QTimer::timeout, client, [this, client]() {
qCWarning(dbgServer) << "A client connected but did not send data in 10 seconds. Dropping connection.";
client->abort();
qCWarning(dbgServer) << "A client connected but did not send data in 10 seconds. Dropping connection from" << client->peerAddress();
pendingConnections.take(client)->deleteLater();
client->deleteLater();
client->abort();
});
timeoutTimer->start(10000);
clientServerMap.insert(client, transport);