From be5236e86e3d188f8adf1f65fd24b2060c0369e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 2 Oct 2019 11:54:29 +0200 Subject: Add support for chrono versions of handshakeTimeout functions And rename the int-version of the getter to enable the scenario where someone does not have chrono. From the 5.14 API change review. Amends 2e54dbe86eac61e87782a138dbcc158cb6b10cd9 Change-Id: Icf2f2a3aebc2216defd0a3a569544c4270ddf05a Reviewed-by: Qt CI Bot Reviewed-by: Edward Welbourne --- src/websockets/qwebsocketserver.cpp | 22 +++++++++++++++++++--- src/websockets/qwebsocketserver.h | 16 +++++++++++++++- .../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 #endif +#if QT_HAS_INCLUDE() +#include +#endif + QT_BEGIN_NAMESPACE class QTcpSocket; @@ -86,8 +90,18 @@ public: void setMaxPendingConnections(int numConnections); int maxPendingConnections() const; +#if QT_HAS_INCLUDE() || 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() + 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() -- cgit v1.2.1