Commit be5236e8 authored by Mårten Nordheim's avatar Mårten Nordheim
Browse files

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 2e54dbe8



Change-Id: Icf2f2a3aebc2216defd0a3a569544c4270ddf05a
Reviewed-by: default avatarQt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: default avatarEdward Welbourne <edward.welbourne@qt.io>
Showing with 46 additions and 4 deletions
......@@ -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);
......
......@@ -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;
......
......@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment