Commit 4321fd13 authored by Jesus Fernandez's avatar Jesus Fernandez Committed by Jesus Fernandez
Browse files

Fix implicit conversion warning


Marks the old functions as deprecated and adds new safe versions.The
new functions give access to the native descriptor safely. It also
fixes the original functions in Qt 6.

warning: implicit conversion loses integer precision: 'qintptr' (aka 'long long') to 'int'

Change-Id: I59177905af0181912d2e7824ce68265cb8ee03d9
Reviewed-by: default avatarTimur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: default avatarMårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: default avatarEdward Welbourne <edward.welbourne@qt.io>
Showing with 120 additions and 3 deletions
......@@ -574,6 +574,7 @@ void QWebSocketServer::setMaxPendingConnections(int numConnections)
d->setMaxPendingConnections(numConnections);
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
/*!
Sets the socket descriptor this server should use when listening for incoming connections to
\a socketDescriptor.
......@@ -582,8 +583,9 @@ void QWebSocketServer::setMaxPendingConnections(int numConnections)
The socket is assumed to be in listening state.
\sa socketDescriptor(), isListening()
\since 5.3
*/
bool QWebSocketServer::setSocketDescriptor(int socketDescriptor)
bool QWebSocketServer::setSocketDescriptor(qintptr socketDescriptor)
{
Q_D(QWebSocketServer);
return d->setSocketDescriptor(socketDescriptor);
......@@ -596,12 +598,104 @@ bool QWebSocketServer::setSocketDescriptor(int socketDescriptor)
native socket functions.
\sa setSocketDescriptor(), isListening()
\since 5.3
*/
qintptr QWebSocketServer::socketDescriptor() const
{
Q_D(const QWebSocketServer);
return d->socketDescriptor();
}
/*!
\fn QWebSocketServer::nativeDescriptor
\deprecated
Returns the native socket descriptor the server uses to listen for incoming instructions,
or -1 if the server is not listening.
If the server is using QNetworkProxy, the returned descriptor may not be usable with
native socket functions.
\sa socketDescriptor(), setSocketDescriptor(), setNativeDescriptor(), isListening()
\since 5.12
*/
/*!
\fn QWebSocketServer::setNativeDescriptor
\deprecated
Sets the socket descriptor this server should use when listening for incoming connections to
\a socketDescriptor.
Returns true if the socket is set successfully; otherwise returns false.
The socket is assumed to be in listening state.
\sa socketDescriptor(), setSocketDescriptor(), nativeDescriptor(), isListening()
\since 5.12
*/
#else // ### Qt 6: Remove leftovers
/*!
\deprecated
Sets the socket descriptor this server should use when listening for incoming connections to
\a socketDescriptor.
Returns true if the socket is set successfully; otherwise returns false.
The socket is assumed to be in listening state.
\sa socketDescriptor(), setSocketDescriptor(), nativeDescriptor(), isListening()
\since 5.3
*/
bool QWebSocketServer::setSocketDescriptor(int socketDescriptor)
{
return setNativeDescriptor(socketDescriptor);
}
/*!
\deprecated
Returns the native socket descriptor the server uses to listen for incoming instructions,
or -1 if the server is not listening.
If the server is using QNetworkProxy, the returned descriptor may not be usable with
native socket functions.
\sa nativeDescriptor(), setNativeDescriptor(), setSocketDescriptor(), isListening()
\since 5.3
*/
int QWebSocketServer::socketDescriptor() const
{
return int(nativeDescriptor());
}
/*!
Sets the socket descriptor this server should use when listening for incoming connections to
\a socketDescriptor.
Returns true if the socket is set successfully; otherwise returns false.
The socket is assumed to be in listening state.
\sa nativeDescriptor(), isListening()
\since 5.12
*/
bool QWebSocketServer::setNativeDescriptor(qintptr socketDescriptor)
{
Q_D(QWebSocketServer);
return d->setSocketDescriptor(socketDescriptor);
}
/*!
Returns the native socket descriptor the server uses to listen for incoming instructions,
or -1 if the server is not listening.
If the server is using QNetworkProxy, the returned descriptor may not be usable with
native socket functions.
\sa setNativeDescriptor(), isListening()
\since 5.12
*/
qintptr QWebSocketServer::nativeDescriptor() const
{
Q_D(const QWebSocketServer);
return d->socketDescriptor();
}
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
/*!
Returns a list of WebSocket versions that this server is supporting.
......
......@@ -92,8 +92,18 @@ public:
SslMode secureMode() const;
bool setSocketDescriptor(int socketDescriptor);
int socketDescriptor() const;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
bool setSocketDescriptor(qintptr socketDescriptor);
qintptr socketDescriptor() const;
bool setNativeDescriptor(qintptr descriptor) { return setSocketDescriptor(descriptor); }
qintptr nativeDescriptor() const { return socketDescriptor(); }
#else // ### Qt 6: Remove leftovers
Q_DECL_DEPRECATED_X("Use setNativeDescriptor") bool setSocketDescriptor(int socketDescriptor);
Q_DECL_DEPRECATED_X("Use nativeDescriptor") int socketDescriptor() const;
bool setNativeDescriptor(qintptr descriptor);
qintptr nativeDescriptor() const;
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
bool hasPendingConnections() const;
virtual QWebSocket *nextPendingConnection();
......
......@@ -191,7 +191,11 @@ void tst_QWebSocketServer::tst_initialisation()
QCOMPARE(server.maxPendingConnections(), 30);
QCOMPARE(server.serverPort(), quint16(0));
QCOMPARE(server.serverAddress(), QHostAddress());
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QCOMPARE(server.socketDescriptor(), -1);
#else // ### Qt 6: Remove leftovers
QCOMPARE(server.nativeDescriptor(), -1);
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVERIFY(!server.hasPendingConnections());
QVERIFY(!server.nextPendingConnection());
QCOMPARE(server.error(), QWebSocketProtocol::CloseCodeNormal);
......@@ -216,7 +220,11 @@ void tst_QWebSocketServer::tst_initialisation()
QCOMPARE(server.maxPendingConnections(), 30);
QCOMPARE(server.serverPort(), quint16(0));
QCOMPARE(server.serverAddress(), QHostAddress());
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QCOMPARE(server.socketDescriptor(), -1);
#else // ### Qt 6: Remove leftovers
QCOMPARE(server.nativeDescriptor(), -1);
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVERIFY(!server.hasPendingConnections());
QVERIFY(!server.nextPendingConnection());
QCOMPARE(server.error(), QWebSocketProtocol::CloseCodeNormal);
......@@ -252,8 +260,13 @@ void tst_QWebSocketServer::tst_settersAndGetters()
server.setMaxPendingConnections(INT_MAX);
QCOMPARE(server.maxPendingConnections(), INT_MAX);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVERIFY(!server.setSocketDescriptor(-2));
QCOMPARE(server.socketDescriptor(), -1);
#else // ### Qt 6: Remove leftovers
QVERIFY(!server.setNativeDescriptor(-2));
QCOMPARE(server.nativeDescriptor(), -1);
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
server.setServerName(QStringLiteral("Qt WebSocketServer"));
QCOMPARE(server.serverName(), QStringLiteral("Qt WebSocketServer"));
......
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