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 | |
15 | class QLocalServer; |
16 | class QLocalSocket; |
17 | |
18 | class QTcpServer; |
19 | |
20 | namespace KIO |
21 | { |
22 | struct Task { |
23 | int cmd = -1; |
24 | long len = 0; |
25 | QByteArray data{}; |
26 | }; |
27 | |
28 | class ConnectionBackend : public QObject |
29 | { |
30 | Q_OBJECT |
31 | |
32 | public: |
33 | enum { Idle, Listening, Connected } state; |
34 | QUrl address; |
35 | QString errorString; |
36 | |
37 | static const int = 10; |
38 | static const int StandardBufferSize = 32 * 1024; |
39 | |
40 | private: |
41 | QLocalSocket *socket; |
42 | QLocalServer *localServer; |
43 | std::optional<Task> pendingTask = std::nullopt; |
44 | bool signalEmitted; |
45 | |
46 | Q_SIGNALS: |
47 | void disconnected(); |
48 | void commandReceived(const KIO::Task &task); |
49 | void newConnection(); |
50 | |
51 | public: |
52 | explicit ConnectionBackend(QObject *parent = nullptr); |
53 | ~ConnectionBackend() override; |
54 | |
55 | void setSuspended(bool enable); |
56 | bool connectToRemote(const QUrl &url); |
57 | bool listenForRemote(); |
58 | bool waitForIncomingTask(int ms); |
59 | bool sendCommand(int command, const QByteArray &data) const; |
60 | ConnectionBackend *nextPendingConnection(); |
61 | |
62 | public Q_SLOTS: |
63 | void socketReadyRead(); |
64 | void socketDisconnected(); |
65 | }; |
66 | } |
67 | |
68 | #endif |
69 | |