From 5bbb05c72c8b8f2d33beae722a704a1c293a55ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81o=C5=9B?= Date: Mon, 16 Sep 2024 11:39:25 +0200 Subject: [PATCH] Enable compilation of qtbase with localserver off MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we will need to turn off this feature for certain platforms, code must compile with QT_FEATURE_localserver turned off, which now can't. Fix this by disabling parts of code requiring QT_FEATURE_localserver. Task-number: QTBUG-115777 Pick-to: 6.8 Change-Id: I6d78030db67ee679d6877b48a437db90a6e47a02 Reviewed-by: MÃ¥rten Nordheim --- src/network/access/qhttpnetworkconnection.cpp | 4 ++++ src/network/access/qhttpnetworkconnectionchannel.cpp | 12 ++++++++++++ src/network/access/qhttpnetworkconnectionchannel_p.h | 7 ++++++- src/network/access/qsocketabstraction_p.h | 12 +++++++++++- .../access/qnetworkreply_local/minihttpserver.h | 6 +++++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 3ef07c69939..71d18a64124 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -112,10 +112,12 @@ void QHttpNetworkConnectionPrivate::pauseConnection() else #endif QAbstractSocketPrivate::pauseSocketNotifiers(absSocket); +#if QT_CONFIG(localserver) } else if (qobject_cast(channels[i].socket)) { // @todo how would we do this? #if 0 // @todo Enable this when there is a debug category for this qDebug() << "Should pause socket but there is no way to do it for local sockets"; +#endif #endif } } @@ -137,9 +139,11 @@ void QHttpNetworkConnectionPrivate::resumeConnection() // Resume pending upload if needed if (channels[i].state == QHttpNetworkConnectionChannel::WritingState) QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection); +#if QT_CONFIG(localserver) } else if (qobject_cast(channels[i].socket)) { #if 0 // @todo Enable this when there is a debug category for this qDebug() << "Should resume socket but there is no way to do it for local sockets"; +#endif #endif } } diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 82d151c9b76..8e476772867 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -22,6 +22,8 @@ #include "private/qnetconmonitor_p.h" +#include + #include #include @@ -65,8 +67,10 @@ void QHttpNetworkConnectionChannel::init() #ifndef QT_NO_SSL if (connection->d_func()->encrypt) socket = new QSslSocket; +#if QT_CONFIG(localserver) else if (connection->d_func()->isLocalSocket) socket = new QLocalSocket; +#endif else socket = new QTcpSocket; #else @@ -108,6 +112,7 @@ void QHttpNetworkConnectionChannel::init() QObject::connect(socket, &QAbstractSocket::errorOccurred, this, &QHttpNetworkConnectionChannel::_q_error, Qt::DirectConnection); +#if QT_CONFIG(localserver) } else if constexpr (std::is_same_v) { auto convertAndForward = [this](QLocalSocket::LocalSocketError error) { _q_error(static_cast(error)); @@ -115,6 +120,7 @@ void QHttpNetworkConnectionChannel::init() QObject::connect(socket, &SocketType::errorOccurred, this, std::move(convertAndForward), Qt::DirectConnection); +#endif } }, socket); @@ -423,8 +429,10 @@ bool QHttpNetworkConnectionChannel::ensureConnection() networkLayerPreference); // For an Unbuffered QTcpSocket, the read buffer size has a special meaning. s->setReadBufferSize(1 * 1024); +#if QT_CONFIG(localserver) } else if (auto *s = qobject_cast(socket)) { s->connectToServer(connectHost); +#endif } #ifndef QT_NO_NETWORKPROXY } else { @@ -964,6 +972,7 @@ void QHttpNetworkConnectionChannel::_q_connected_abstract_socket(QAbstractSocket } } +#if QT_CONFIG(localserver) void QHttpNetworkConnectionChannel::_q_connected_local_socket(QLocalSocket *localSocket) { state = QHttpNetworkConnectionChannel::IdleState; @@ -972,13 +981,16 @@ void QHttpNetworkConnectionChannel::_q_connected_local_socket(QLocalSocket *loca if (reply) sendRequest(); } +#endif void QHttpNetworkConnectionChannel::_q_connected() { if (auto *s = qobject_cast(socket)) _q_connected_abstract_socket(s); +#if QT_CONFIG(localserver) else if (auto *s = qobject_cast(socket)) _q_connected_local_socket(s); +#endif } void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socketError) diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h index 9c79566d5b7..fdbde0ff551 100644 --- a/src/network/access/qhttpnetworkconnectionchannel_p.h +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -40,6 +39,10 @@ #else # include #endif +#if QT_CONFIG(localserver) +# include +#endif + #include #include @@ -164,7 +167,9 @@ class QHttpNetworkConnectionChannel : public QObject { void _q_readyRead(); // pending data to read void _q_disconnected(); // disconnected from host void _q_connected_abstract_socket(QAbstractSocket *socket); +#if QT_CONFIG(localserver) void _q_connected_local_socket(QLocalSocket *socket); +#endif void _q_connected(); // start sending request void _q_error(QAbstractSocket::SocketError); // error from socket #ifndef QT_NO_NETWORKPROXY diff --git a/src/network/access/qsocketabstraction_p.h b/src/network/access/qsocketabstraction_p.h index 2b40b802446..3decb0807ee 100644 --- a/src/network/access/qsocketabstraction_p.h +++ b/src/network/access/qsocketabstraction_p.h @@ -7,7 +7,9 @@ #include #include -#include +#if QT_CONFIG(localserver) +# include +#endif #include @@ -32,8 +34,10 @@ auto visit(Fn &&fn, QIODevice *socket, Args &&...args) { if (auto *s = qobject_cast(socket)) return std::forward(fn)(s, std::forward(args)...); +#if QT_CONFIG(localserver) if (auto *s = qobject_cast(socket)) return std::forward(fn)(s, std::forward(args)...); +#endif Q_UNREACHABLE(); } @@ -46,9 +50,11 @@ inline QAbstractSocket::SocketState socketState(QIODevice *device) using T = std::remove_pointer_t; if constexpr (std::is_same_v) { return s->state(); +#if QT_CONFIG(localserver) } else if constexpr (std::is_same_v) { QLocalSocket::LocalSocketState st = s->state(); return static_cast(st); +#endif } Q_UNREACHABLE(); }; @@ -62,9 +68,11 @@ inline QAbstractSocket::SocketError socketError(QIODevice *device) using T = std::remove_pointer_t; if constexpr (std::is_same_v) { return s->error(); +#if QT_CONFIG(localserver) } else if constexpr (std::is_same_v) { QLocalSocket::LocalSocketError st = s->error(); return static_cast(st); +#endif } Q_UNREACHABLE(); }; @@ -77,8 +85,10 @@ inline QString socketPeerName(QIODevice *device) using T = std::remove_pointer_t; if constexpr (std::is_same_v) { return s->peerName(); +#if QT_CONFIG(localserver) } else if constexpr (std::is_same_v) { return s->serverName(); +#endif } Q_UNREACHABLE(); }; diff --git a/tests/auto/network/access/qnetworkreply_local/minihttpserver.h b/tests/auto/network/access/qnetworkreply_local/minihttpserver.h index eb0697a6f84..daad88cdbcc 100644 --- a/tests/auto/network/access/qnetworkreply_local/minihttpserver.h +++ b/tests/auto/network/access/qnetworkreply_local/minihttpserver.h @@ -8,12 +8,12 @@ #include #include -#include #if QT_CONFIG(ssl) # include #endif #if QT_CONFIG(localserver) # include +# include #endif #include @@ -62,8 +62,10 @@ class MiniHttpServerV2 : public QObject for (auto [socket, _] : copy.asKeyValueRange()) { if (auto *tcpSocket = qobject_cast(socket)) tcpSocket->disconnectFromHost(); +#if QT_CONFIG(localserver) else if (auto *localSocket = qobject_cast(socket)) localSocket->disconnectFromServer(); +#endif else Q_UNREACHABLE_RETURN(); socket->deleteLater(); @@ -136,11 +138,13 @@ class MiniHttpServerV2 : public QObject if (auto *tcpSocket = qobject_cast(socket)) { connect(tcpSocket, &QAbstractSocket::errorOccurred, this, &MiniHttpServerV2::slotError); +#if QT_CONFIG(localserver) } else if (auto *localSocket = qobject_cast(socket)) { connect(localSocket, &QLocalSocket::errorOccurred, this, [this](QLocalSocket::LocalSocketError error) { slotError(QAbstractSocket::SocketError(error)); }); +#endif } else { Q_UNREACHABLE_RETURN(); }