Check on max pending connections before accepting a connection
authorKurt Pattyn <pattyn.kurt@gmail.com>
Sat, 4 Jan 2014 14:43:53 +0000 (15:43 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 4 Jan 2014 14:45:14 +0000 (15:45 +0100)
Change-Id: Ia94540e131ce424e6306886861598f7f24f7577f
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
src/websockets/qwebsocketserver_p.cpp

index e5e0f1e..4d5680f 100644 (file)
@@ -385,6 +385,13 @@ void QWebSocketServerPrivate::handshakeReceived()
 
         disconnect(pTcpSocket, SIGNAL(readyRead()), this, SLOT(handshakeReceived()));
 
+        if (m_pendingConnections.length() >= maxPendingConnections()) {
+            pTcpSocket->close();
+            qWarning() << tr("Too many pending connections: new websocket connection not accepted.");
+            setError(QWebSocketProtocol::CC_ABNORMAL_DISCONNECTION, tr("Too many pending connections."));
+            return;
+        }
+
         QWebSocketHandshakeRequest request(pTcpSocket->peerPort(), isSecure);
         QTextStream textStream(pTcpSocket);
         textStream >> request;