QGrpcHttp2Channel: Add QLocalSocket abstract namespace support

QLocalSocket supports abstract namespaces. Grpc also supports it. Simply
make it available through the 'unix-abstract' scheme.

Ref: https://grpc.github.io/grpc/core/md_doc_naming.html
Ref: https://doc.qt.io/qt-6/qlocalsocket.html#SocketOption-enum

[ChangeLog][GRPC][QGrpcHttp2Channel] Added abstract namespace support
for QLocalSocket communication through the "unix-abstract" scheme.

Fixes: QTBUG-134273
Change-Id: Iea2b608478e00504d7cdbdff735fcbfb618529d7
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Dennis Oberst 2025-03-03 21:00:07 +01:00
parent 65358c24f6
commit 6a9810ed7f
1 changed files with 6 additions and 2 deletions

View File

@ -117,6 +117,7 @@ using namespace QtGrpc;
namespace {
constexpr QLatin1String UnixScheme("unix");
constexpr QLatin1String UnixAbstractScheme("unix-abstract");
constexpr QLatin1String HttpScheme("http");
#if QT_CONFIG(ssl)
constexpr QLatin1String HttpsScheme("https");
@ -687,10 +688,13 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
}
bool nonDefaultPort = false;
const auto scheme = hostUri.scheme();
#if QT_CONFIG(localserver)
if (hostUri.scheme() == UnixScheme) {
if (scheme == UnixScheme || scheme == UnixAbstractScheme) {
hostUri.setScheme(HttpScheme);
auto *localSocket = initSocket<QLocalSocket>();
if (scheme == UnixAbstractScheme)
localSocket->setSocketOptions(QLocalSocket::AbstractNamespaceOption);
m_isLocalSocket = true;
QObject::connect(localSocket, &QLocalSocket::connected, this,
@ -709,7 +713,7 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
} else
#endif
#if QT_CONFIG(ssl)
if (hostUri.scheme() == HttpsScheme || channelOptions.sslConfiguration()) {
if (scheme == HttpsScheme || channelOptions.sslConfiguration()) {
ensureSchemeIsValid(HttpsScheme);
auto *sslSocket = initSocket<QSslSocket>();
if (hostUri.port() < 0) {