Changeset View
Changeset View
Standalone View
Standalone View
core/backends/lan/landevicelink.cpp
Show All 20 Lines | |||||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | 22 | | |||
23 | #include "landevicelink.h" | 23 | #include "landevicelink.h" | ||
24 | #include "core_debug.h" | 24 | #include "core_debug.h" | ||
25 | #include "kdeconnectconfig.h" | 25 | #include "kdeconnectconfig.h" | ||
26 | #include "backends/linkprovider.h" | 26 | #include "backends/linkprovider.h" | ||
27 | #include "socketlinereader.h" | 27 | #include "socketlinereader.h" | ||
28 | #include "lanlinkprovider.h" | 28 | #include "lanlinkprovider.h" | ||
29 | #include <kio/global.h> | 29 | #include "plugins/share/shareplugin.h" | ||
30 | #include <KJobTrackerInterface> | | |||
31 | #include <plugins/share/shareplugin.h> | | |||
32 | 30 | | |||
33 | LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource) | 31 | LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource) | ||
34 | : DeviceLink(deviceId, parent) | 32 | : DeviceLink(deviceId, parent) | ||
35 | , m_socketLineReader(nullptr) | 33 | , m_socketLineReader(nullptr) | ||
36 | { | 34 | { | ||
37 | reset(socket, connectionSource); | 35 | reset(socket, connectionSource); | ||
38 | } | 36 | } | ||
39 | 37 | | |||
Show All 40 Lines | |||||
80 | 78 | | |||
81 | QString LanDeviceLink::name() | 79 | QString LanDeviceLink::name() | ||
82 | { | 80 | { | ||
83 | return QStringLiteral("LanLink"); // Should be same in both android and kde version | 81 | return QStringLiteral("LanLink"); // Should be same in both android and kde version | ||
84 | } | 82 | } | ||
85 | 83 | | |||
86 | bool LanDeviceLink::sendPacket(NetworkPacket& np) | 84 | bool LanDeviceLink::sendPacket(NetworkPacket& np) | ||
87 | { | 85 | { | ||
88 | if (np.hasPayload()) { | 86 | if (np.payload()) { | ||
89 | np.setPayloadTransferInfo(sendPayload(np)->transferInfo()); | 87 | if (np.type() == PACKET_TYPE_SHARE_REQUEST && np.payloadSize() >= 0) { | ||
88 | if (!m_compositeUploadJob || !m_compositeUploadJob->isRunning()) { | ||||
89 | m_compositeUploadJob = new CompositeUploadJob(deviceId(), true); | ||||
90 | } | ||||
91 | | ||||
92 | m_compositeUploadJob->addSubjob(new UploadJob(np)); | ||||
93 | | ||||
94 | if (!m_compositeUploadJob->isRunning()) { | ||||
95 | m_compositeUploadJob->start(); | ||||
96 | } | ||||
97 | } else { //Infinite stream | ||||
98 | CompositeUploadJob* fireAndForgetJob = new CompositeUploadJob(deviceId(), false); | ||||
99 | fireAndForgetJob->addSubjob(new UploadJob(np)); | ||||
100 | fireAndForgetJob->start(); | ||||
90 | } | 101 | } | ||
91 | 102 | | |||
103 | return true; | ||||
104 | } else { | ||||
92 | int written = m_socketLineReader->write(np.serialize()); | 105 | int written = m_socketLineReader->write(np.serialize()); | ||
93 | 106 | | |||
94 | //Actually we can't detect if a packet is received or not. We keep TCP | 107 | //Actually we can't detect if a packet is received or not. We keep TCP | ||
95 | //"ESTABLISHED" connections that look legit (return true when we use them), | 108 | //"ESTABLISHED" connections that look legit (return true when we use them), | ||
96 | //but that are actually broken (until keepalive detects that they are down). | 109 | //but that are actually broken (until keepalive detects that they are down). | ||
97 | return (written != -1); | 110 | return (written != -1); | ||
98 | } | 111 | } | ||
99 | | ||||
100 | UploadJob* LanDeviceLink::sendPayload(const NetworkPacket& np) | | |||
101 | { | | |||
102 | UploadJob* job = new UploadJob(np.payload(), deviceId()); | | |||
103 | if (np.type() == PACKET_TYPE_SHARE_REQUEST && np.payloadSize() >= 0) { | | |||
104 | KIO::getJobTracker()->registerJob(job); | | |||
105 | } | | |||
106 | job->start(); | | |||
107 | return job; | | |||
108 | } | 112 | } | ||
109 | 113 | | |||
110 | void LanDeviceLink::dataReceived() | 114 | void LanDeviceLink::dataReceived() | ||
111 | { | 115 | { | ||
112 | if (m_socketLineReader->bytesAvailable() == 0) return; | 116 | if (m_socketLineReader->bytesAvailable() == 0) return; | ||
113 | 117 | | |||
114 | const QByteArray serializedPacket = m_socketLineReader->readLine(); | 118 | const QByteArray serializedPacket = m_socketLineReader->readLine(); | ||
115 | NetworkPacket packet(QString::null); | 119 | NetworkPacket packet(QString::null); | ||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |