Check on max pending connections before accepting a connection
[contrib/qtwebsockets.git] / 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;