summaryrefslogtreecommitdiff
path: root/src/websockets
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2018-08-10 14:08:29 +0200
committerJesus Fernandez <Jesus.Fernandez@qt.io>2018-08-20 11:59:06 +0000
commit4321fd13ac58e5bebe4d564431e9c18b627598bc (patch)
tree62ce88e0043a5622c4e1edecad45a2e920e88e0a /src/websockets
parent790586e42920a4cbf10bb808aa1b716247628cc4 (diff)
downloadqtwebsockets-4321fd13ac58e5bebe4d564431e9c18b627598bc.tar.gz
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: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/websockets')
-rw-r--r--src/websockets/qwebsocketserver.cpp96
-rw-r--r--src/websockets/qwebsocketserver.h14
2 files changed, 107 insertions, 3 deletions
diff --git a/src/websockets/qwebsocketserver.cpp b/src/websockets/qwebsocketserver.cpp
index 7368596..7790250 100644
--- a/src/websockets/qwebsocketserver.cpp
+++ b/src/websockets/qwebsocketserver.cpp
@@ -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.
diff --git a/src/websockets/qwebsocketserver.h b/src/websockets/qwebsocketserver.h
index 890f2d6..17d5376 100644
--- a/src/websockets/qwebsocketserver.h
+++ b/src/websockets/qwebsocketserver.h
@@ -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();