diff options
author | Aleksey Lysenko <lysenkoalexmail@gmail.com> | 2016-12-06 09:50:30 +0200 |
---|---|---|
committer | Aleksey Lysenko <lysenkoalexmail@gmail.com> | 2016-12-13 15:22:52 +0000 |
commit | b2d610c0ea229e40910fc9aa1bc784d853cfeba8 (patch) | |
tree | a13ce870b7f77c76157757d9bac1b96aee91cd62 /src/websockets | |
parent | 9a4b09864461b95a3e6f18d6ea89b4bac674146c (diff) | |
download | qtwebsockets-b2d610c0ea229e40910fc9aa1bc784d853cfeba8.tar.gz |
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: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Liang Qi <liang.qi@qt.io>
Diffstat (limited to 'src/websockets')
-rw-r--r-- | src/websockets/qwebsocketserver_p.cpp | 6 | ||||
-rw-r--r-- | src/websockets/qwebsocketserver_p.h | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp index 91bfafc..3bf6d68 100644 --- a/src/websockets/qwebsocketserver_p.cpp +++ b/src/websockets/qwebsocketserver_p.cpp @@ -392,18 +392,20 @@ void QWebSocketServerPrivate::onNewConnection() QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead, this, &QWebSocketServerPrivate::handshakeReceived, Qt::QueuedConnection); + QObjectPrivate::connect(pTcpSocket, &QTcpSocket::disconnected, + this, &QWebSocketServerPrivate::onSocketDisconnected); } } /*! \internal */ -void QWebSocketServerPrivate::onCloseConnection() +void QWebSocketServerPrivate::onSocketDisconnected() { if (Q_LIKELY(currentSender)) { QTcpSocket *pTcpSocket = qobject_cast<QTcpSocket*>(currentSender->sender); if (Q_LIKELY(pTcpSocket)) - pTcpSocket->close(); + pTcpSocket->deleteLater(); } } diff --git a/src/websockets/qwebsocketserver_p.h b/src/websockets/qwebsocketserver_p.h index 46a2156..6aabebd 100644 --- a/src/websockets/qwebsocketserver_p.h +++ b/src/websockets/qwebsocketserver_p.h @@ -136,7 +136,7 @@ private: const QString &errorDescription); void onNewConnection(); - void onCloseConnection(); + void onSocketDisconnected(); void handshakeReceived(); }; |