Skip to content

Commit

Permalink
Enable compilation of qtbase with localserver off
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Michał Łoś committed Sep 19, 2024
1 parent 0c7a89f commit 5bbb05c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/network/access/qhttpnetworkconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/network/access/qhttpnetworkconnectionchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "private/qnetconmonitor_p.h"

#include <QtNetwork/private/qtnetworkglobal_p.h>

#include <memory>
#include <utility>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -108,13 +112,15 @@ 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));
};
QObject::connect(socket, &SocketType::errorOccurred,
this, std::move(convertAndForward),
Qt::DirectConnection);
#endif
}
}, socket);

Expand Down Expand Up @@ -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<QLocalSocket *>(socket)) {
s->connectToServer(connectHost);
#endif
}
#ifndef QT_NO_NETWORKPROXY
} else {
Expand Down Expand Up @@ -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;
Expand All @@ -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<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)
Expand Down
7 changes: 6 additions & 1 deletion src/network/access/qhttpnetworkconnectionchannel_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/network/access/qsocketabstraction_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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();
}

Expand All @@ -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();
};
Expand All @@ -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();
};
Expand All @@ -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();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -62,8 +62,10 @@ class MiniHttpServerV2 : public QObject
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();
Expand Down Expand Up @@ -136,11 +138,13 @@ class MiniHttpServerV2 : public QObject

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();
}
Expand Down

0 comments on commit 5bbb05c

Please sign in to comment.