Commit b2d610c0 authored by Aleksey Lysenko's avatar Aleksey Lysenko
Browse files

Delete disconnected socket


Method onSocketDisconnected has never been called, so WebSocketServer did not
handle closed connection properly. Moreover, socket was not freed in time
and this led to increase in memory consumption

Task-number: QTBUG-56414
Change-Id: Ib57f5b88413ffeef4f296a260245ba0a8d25adb2
Reviewed-by: default avatarTimur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: default avatarLiang Qi <liang.qi@qt.io>
Showing with 5 additions and 3 deletions
...@@ -392,18 +392,20 @@ void QWebSocketServerPrivate::onNewConnection() ...@@ -392,18 +392,20 @@ void QWebSocketServerPrivate::onNewConnection()
QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead, QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead,
this, &QWebSocketServerPrivate::handshakeReceived, this, &QWebSocketServerPrivate::handshakeReceived,
Qt::QueuedConnection); Qt::QueuedConnection);
QObjectPrivate::connect(pTcpSocket, &QTcpSocket::disconnected,
this, &QWebSocketServerPrivate::onSocketDisconnected);
} }
} }
/*! /*!
\internal \internal
*/ */
void QWebSocketServerPrivate::onCloseConnection() void QWebSocketServerPrivate::onSocketDisconnected()
{ {
if (Q_LIKELY(currentSender)) { if (Q_LIKELY(currentSender)) {
QTcpSocket *pTcpSocket = qobject_cast<QTcpSocket*>(currentSender->sender); QTcpSocket *pTcpSocket = qobject_cast<QTcpSocket*>(currentSender->sender);
if (Q_LIKELY(pTcpSocket)) if (Q_LIKELY(pTcpSocket))
pTcpSocket->close(); pTcpSocket->deleteLater();
} }
} }
......
...@@ -136,7 +136,7 @@ private: ...@@ -136,7 +136,7 @@ private:
const QString &errorDescription); const QString &errorDescription);
void onNewConnection(); void onNewConnection();
void onCloseConnection(); void onSocketDisconnected();
void handshakeReceived(); void handshakeReceived();
}; };
......
Supports Markdown
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