1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2007 Thiago Macieira <thiago@kde.org>
4 SPDX-FileCopyrightText: 2024 Harald Sitter <sitter@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KIO_CONNECTIONBACKEND_P_H
10#define KIO_CONNECTIONBACKEND_P_H
11
12#include <QObject>
13#include <QUrl>
14
15class QLocalServer;
16class QLocalSocket;
17
18class QTcpServer;
19
20namespace KIO
21{
22struct Task {
23 int cmd = -1;
24 long len = 0;
25 QByteArray data{};
26};
27
28class ConnectionBackend : public QObject
29{
30 Q_OBJECT
31
32public:
33 enum {
34 Idle,
35 Listening,
36 Connected
37 } state;
38 QUrl address;
39 QString errorString;
40
41 static const int HeaderSize = 10;
42 static const int StandardBufferSize = 32 * 1024;
43
44private:
45 QLocalSocket *socket;
46 QLocalServer *localServer;
47 std::optional<Task> pendingTask = std::nullopt;
48 bool signalEmitted;
49
50Q_SIGNALS:
51 void disconnected();
52 void commandReceived(const KIO::Task &task);
53 void newConnection();
54
55public:
56 explicit ConnectionBackend(QObject *parent = nullptr);
57 ~ConnectionBackend() override;
58
59 struct ConnectionResult {
60 bool success = true;
61 QString error;
62 };
63
64 void setSuspended(bool enable);
65 bool connectToRemote(const QUrl &url);
66 ConnectionResult listenForRemote();
67 bool waitForIncomingTask(int ms);
68 bool sendCommand(int command, const QByteArray &data) const;
69 ConnectionBackend *nextPendingConnection();
70
71public Q_SLOTS:
72 void socketReadyRead();
73 void socketDisconnected();
74};
75}
76
77#endif
78

source code of kio/src/core/connectionbackend_p.h