diff options
-rw-r--r-- | src/websockets/qwebsocketserver.cpp | 22 | ||||
-rw-r--r-- | src/websockets/qwebsocketserver.h | 16 | ||||
-rw-r--r-- | tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp | 12 |
3 files changed, 46 insertions, 4 deletions
diff --git a/src/websockets/qwebsocketserver.cpp b/src/websockets/qwebsocketserver.cpp index ecd9da8..eafe3fd 100644 --- a/src/websockets/qwebsocketserver.cpp +++ b/src/websockets/qwebsocketserver.cpp @@ -353,15 +353,26 @@ int QWebSocketServer::maxPendingConnections() const } /*! + \fn std::chrono::milliseconds QWebSocketServer::handshakeTimeout() const Returns the handshake timeout for new connections in milliseconds. The default is 10 seconds. If a peer uses more time to complete the handshake their connection is closed. - \sa setHandshakeTimeout() + \sa setHandshakeTimeout(), handshakeTimeoutMS() \since 5.14 */ -int QWebSocketServer::handshakeTimeout() const + +/*! + Returns the handshake timeout for new connections in milliseconds. + + The default is 10 seconds. If a peer uses more time to complete the + handshake their connection is closed. + + \sa setHandshakeTimeout(), handshakeTimeout() + \since 5.14 + */ +int QWebSocketServer::handshakeTimeoutMS() const { Q_D(const QWebSocketServer); return d->handshakeTimeout(); @@ -593,15 +604,20 @@ void QWebSocketServer::setMaxPendingConnections(int numConnections) } /*! + \fn void QWebSocketServer::setHandshakeTimeout(std::chrono::milliseconds msec) Sets the handshake timeout for new connections to \a msec milliseconds. By default this is set to 10 seconds. If a peer uses more time to complete the handshake, their connection is closed. You can pass a negative value (e.g. -1) to disable the timeout. - \sa handshakeTimeout() + \sa handshakeTimeout(), handshakeTimeoutMS() \since 5.14 */ + +/*! + \overload +*/ void QWebSocketServer::setHandshakeTimeout(int msec) { Q_D(QWebSocketServer); diff --git a/src/websockets/qwebsocketserver.h b/src/websockets/qwebsocketserver.h index dd06448..ceb9106 100644 --- a/src/websockets/qwebsocketserver.h +++ b/src/websockets/qwebsocketserver.h @@ -52,6 +52,10 @@ #include <QtNetwork/QSslError> #endif +#if QT_HAS_INCLUDE(<chrono>) +#include <chrono> +#endif + QT_BEGIN_NAMESPACE class QTcpSocket; @@ -86,8 +90,18 @@ public: void setMaxPendingConnections(int numConnections); int maxPendingConnections() const; +#if QT_HAS_INCLUDE(<chrono>) || defined(Q_CLANG_QDOC) + void setHandshakeTimeout(std::chrono::milliseconds msec) + { + setHandshakeTimeout(int(msec.count())); + } + std::chrono::milliseconds handshakeTimeout() const + { + return std::chrono::milliseconds(handshakeTimeoutMS()); + } +#endif void setHandshakeTimeout(int msec); - int handshakeTimeout() const; + int handshakeTimeoutMS() const; quint16 serverPort() const; QHostAddress serverAddress() const; diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp index 20d7060..c40bb01 100644 --- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp @@ -294,6 +294,18 @@ void tst_QWebSocketServer::tst_settersAndGetters() QCOMPARE(sslServer.sslConfiguration(), sslConfiguration); QVERIFY(sslServer.sslConfiguration() != QSslConfiguration::defaultConfiguration()); #endif + + server.setHandshakeTimeout(64); + QCOMPARE(server.handshakeTimeoutMS(), 64); +#if QT_HAS_INCLUDE(<chrono>) + auto expected = std::chrono::milliseconds(64); + QCOMPARE(server.handshakeTimeout(), expected); + + expected = std::chrono::milliseconds(242); + server.setHandshakeTimeout(expected); + QCOMPARE(server.handshakeTimeoutMS(), 242); + QCOMPARE(server.handshakeTimeout(), expected); +#endif } void tst_QWebSocketServer::tst_listening() |