diff options
author | Aleksey Lysenko <lysenkoalexmail@gmail.com> | 2016-12-30 21:45:11 +0200 |
---|---|---|
committer | Lars Schmertmann <lars.schmertmann@governikus.de> | 2017-01-27 11:15:09 +0000 |
commit | 6ce818a10c5f6fd2314524f5d701e13752e4a662 (patch) | |
tree | 707bfbd9d4985dec30f3210a084f5d1330920d9d /src/websockets/qwebsocketserver_p.cpp | |
parent | dfc91928f15302fa4e6c41802c60caec2c124942 (diff) | |
download | qtwebsockets-6ce818a10c5f6fd2314524f5d701e13752e4a662.tar.gz |
Add a function to hand off a tcp socket to the websocket server
This method allows a listening port to process connections with
different protocols. It lets the websocket server handle a TCP
socket, upgrading it to a websocket
[ChangeLog][QWebSocketServer] Add support to handle external QTcpSocket
Done-with: André Klitzing <aklitzing@gmail.com>
Task-number: QTBUG-54276
Change-Id: Ia36b481dc87d6f3806e9f1e61e75e528640f1937
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/websockets/qwebsocketserver_p.cpp')
-rw-r--r-- | src/websockets/qwebsocketserver_p.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp index d675056..b7972b0 100644 --- a/src/websockets/qwebsocketserver_p.cpp +++ b/src/websockets/qwebsocketserver_p.cpp @@ -384,17 +384,8 @@ void QWebSocketServerPrivate::setError(QWebSocketProtocol::CloseCode code, const */ void QWebSocketServerPrivate::onNewConnection() { - while (m_pTcpServer->hasPendingConnections()) { - QTcpSocket *pTcpSocket = m_pTcpServer->nextPendingConnection(); - //use a queued connection because a QSslSocket - //needs the event loop to process incoming data - //if not queued, data is incomplete when handshakeReceived is called - QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead, - this, &QWebSocketServerPrivate::handshakeReceived, - Qt::QueuedConnection); - QObjectPrivate::connect(pTcpSocket, &QTcpSocket::disconnected, - this, &QWebSocketServerPrivate::onSocketDisconnected); - } + while (m_pTcpServer->hasPendingConnections()) + handleConnection(m_pTcpServer->nextPendingConnection()); } /*! @@ -491,4 +482,17 @@ void QWebSocketServerPrivate::handshakeReceived() } } +void QWebSocketServerPrivate::handleConnection(QTcpSocket *pTcpSocket) const +{ + if (Q_LIKELY(pTcpSocket)) { + // Use a queued connection because a QSslSocket needs the event loop to process incoming + // data. If not queued, data is incomplete when handshakeReceived is called. + QObjectPrivate::connect(pTcpSocket, &QTcpSocket::readyRead, + this, &QWebSocketServerPrivate::handshakeReceived, + Qt::QueuedConnection); + QObjectPrivate::connect(pTcpSocket, &QTcpSocket::disconnected, + this, &QWebSocketServerPrivate::onSocketDisconnected); + } +} + QT_END_NAMESPACE |