Enable compilation of qtbase with localserver off

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
Change-Id: I6d78030db67ee679d6877b48a437db90a6e47a02
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 5bbb05c72c8b8f2d33beae722a704a1c293a55ea)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Michał Łoś 2024-09-16 11:39:25 +02:00 committed by Qt Cherry-pick Bot
parent 6a2035d970
commit 0c4f0b557e
5 changed files with 38 additions and 3 deletions

View File

@ -112,10 +112,12 @@ void QHttpNetworkConnectionPrivate::pauseConnection()
else
#endif
QAbstractSocketPrivate::pauseSocketNotifiers(absSocket);
#if QT_CONFIG(localserver)
} else if (qobject_cast<QLocalSocket *>(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<QLocalSocket *>(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
}
}

View File

@ -22,6 +22,8 @@
#include "private/qnetconmonitor_p.h"
#include <QtNetwork/private/qtnetworkglobal_p.h>
#include <memory>
#include <utility>
@ -79,8 +81,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
@ -122,6 +126,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<SocketType, QLocalSocket>) {
auto convertAndForward = [this](QLocalSocket::LocalSocketError error) {
_q_error(static_cast<QAbstractSocket::SocketError>(error));
@ -129,6 +134,7 @@ void QHttpNetworkConnectionChannel::init()
QObject::connect(socket, &SocketType::errorOccurred,
this, std::move(convertAndForward),
Qt::DirectConnection);
#endif
}
}, socket);
@ -437,8 +443,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<QLocalSocket *>(socket)) {
s->connectToServer(connectHost);
#endif
}
#ifndef QT_NO_NETWORKPROXY
} else {
@ -984,6 +992,7 @@ void QHttpNetworkConnectionChannel::_q_connected_abstract_socket(QAbstractSocket
}
}
#if QT_CONFIG(localserver)
void QHttpNetworkConnectionChannel::_q_connected_local_socket(QLocalSocket *localSocket)
{
state = QHttpNetworkConnectionChannel::IdleState;
@ -992,13 +1001,16 @@ void QHttpNetworkConnectionChannel::_q_connected_local_socket(QLocalSocket *loca
if (reply)
sendRequest();
}
#endif
void QHttpNetworkConnectionChannel::_q_connected()
{
if (auto *s = qobject_cast<QAbstractSocket *>(socket))
_q_connected_abstract_socket(s);
#if QT_CONFIG(localserver)
else if (auto *s = qobject_cast<QLocalSocket *>(socket))
_q_connected_local_socket(s);
#endif
}
void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socketError)

View File

@ -19,7 +19,6 @@
#include <QtNetwork/qnetworkrequest.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qabstractsocket.h>
#include <QtNetwork/qlocalsocket.h>
#include <private/qobject_p.h>
#include <qauthenticator.h>
@ -40,6 +39,10 @@
#else
# include <QtNetwork/qtcpsocket.h>
#endif
#if QT_CONFIG(localserver)
# include <QtNetwork/qlocalsocket.h>
#endif
#include <QtCore/qpointer.h>
#include <QtCore/qscopedpointer.h>
@ -164,7 +167,9 @@ public:
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

View File

@ -7,7 +7,9 @@
#include <private/qtnetworkglobal_p.h>
#include <QtNetwork/qabstractsocket.h>
#include <QtNetwork/qlocalsocket.h>
#if QT_CONFIG(localserver)
# include <QtNetwork/qlocalsocket.h>
#endif
#include <QtCore/qxpfunctional.h>
@ -32,8 +34,10 @@ auto visit(Fn &&fn, QIODevice *socket, Args &&...args)
{
if (auto *s = qobject_cast<QAbstractSocket *>(socket))
return std::forward<Fn>(fn)(s, std::forward<Args>(args)...);
#if QT_CONFIG(localserver)
if (auto *s = qobject_cast<QLocalSocket *>(socket))
return std::forward<Fn>(fn)(s, std::forward<Args>(args)...);
#endif
Q_UNREACHABLE();
}
@ -46,9 +50,11 @@ inline QAbstractSocket::SocketState socketState(QIODevice *device)
using T = std::remove_pointer_t<decltype(s)>;
if constexpr (std::is_same_v<T, QAbstractSocket>) {
return s->state();
#if QT_CONFIG(localserver)
} else if constexpr (std::is_same_v<T, QLocalSocket>) {
QLocalSocket::LocalSocketState st = s->state();
return static_cast<QAbstractSocket::SocketState>(st);
#endif
}
Q_UNREACHABLE();
};
@ -62,9 +68,11 @@ inline QAbstractSocket::SocketError socketError(QIODevice *device)
using T = std::remove_pointer_t<decltype(s)>;
if constexpr (std::is_same_v<T, QAbstractSocket>) {
return s->error();
#if QT_CONFIG(localserver)
} else if constexpr (std::is_same_v<T, QLocalSocket>) {
QLocalSocket::LocalSocketError st = s->error();
return static_cast<QAbstractSocket::SocketError>(st);
#endif
}
Q_UNREACHABLE();
};
@ -77,8 +85,10 @@ inline QString socketPeerName(QIODevice *device)
using T = std::remove_pointer_t<decltype(s)>;
if constexpr (std::is_same_v<T, QAbstractSocket>) {
return s->peerName();
#if QT_CONFIG(localserver)
} else if constexpr (std::is_same_v<T, QLocalSocket>) {
return s->serverName();
#endif
}
Q_UNREACHABLE();
};

View File

@ -8,12 +8,12 @@
#include <QtNetwork/qtcpserver.h>
#include <QtNetwork/qtcpsocket.h>
#include <QtNetwork/qlocalsocket.h>
#if QT_CONFIG(ssl)
# include <QtNetwork/qsslsocket.h>
#endif
#if QT_CONFIG(localserver)
# include <QtNetwork/qlocalserver.h>
# include <QtNetwork/qlocalsocket.h>
#endif
#include <QtCore/qpointer.h>
@ -62,8 +62,10 @@ public:
for (auto [socket, _] : copy.asKeyValueRange()) {
if (auto *tcpSocket = qobject_cast<QTcpSocket *>(socket))
tcpSocket->disconnectFromHost();
#if QT_CONFIG(localserver)
else if (auto *localSocket = qobject_cast<QLocalSocket *>(socket))
localSocket->disconnectFromServer();
#endif
else
Q_UNREACHABLE_RETURN();
socket->deleteLater();
@ -136,11 +138,13 @@ private:
if (auto *tcpSocket = qobject_cast<QTcpSocket *>(socket)) {
connect(tcpSocket, &QAbstractSocket::errorOccurred, this, &MiniHttpServerV2::slotError);
#if QT_CONFIG(localserver)
} else if (auto *localSocket = qobject_cast<QLocalSocket *>(socket)) {
connect(localSocket, &QLocalSocket::errorOccurred, this,
[this](QLocalSocket::LocalSocketError error) {
slotError(QAbstractSocket::SocketError(error));
});
#endif
} else {
Q_UNREACHABLE_RETURN();
}