diff --git a/core/backends/lan/downloadjob.cpp b/core/backends/lan/downloadjob.cpp index 8db5901fb..acd821866 100644 --- a/core/backends/lan/downloadjob.cpp +++ b/core/backends/lan/downloadjob.cpp @@ -36,12 +36,14 @@ DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap &transfe , mAddress(address) , mPort(transferInfo[QStringLiteral("port")].toInt()) , mSocket(new QSslSocket) - , mBuffer(new QBuffer) { LanLinkProvider::configureSslSocket(mSocket.data(), transferInfo.value(QStringLiteral("deviceId")).toString(), true); connect(mSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError))); -// connect(mSocket.data(), &QAbstractSocket::stateChanged, [](QAbstractSocket::SocketState state){ qDebug() << "statechange" << state; }); + connect(mSocket.data(), &QAbstractSocket::connected, this, &DownloadJob::socketConnected); + // emit readChannelFinished when the socket gets disconnected. This seems to be a bug in upstream QSslSocket. + // Needs investigation and upstreaming of the fix. QTBUG-62257 + connect(mSocket.data(), &QAbstractSocket::disconnected, mSocket.data(), &QAbstractSocket::readChannelFinished); } DownloadJob::~DownloadJob() @@ -54,26 +56,22 @@ void DownloadJob::start() //TODO: Timeout? // Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite); - - bool b = mBuffer->open(QBuffer::ReadWrite); - Q_ASSERT(b); } void DownloadJob::socketFailed(QAbstractSocket::SocketError error) { - if (error != QAbstractSocket::RemoteHostClosedError) { //remote host closes when finishes - qWarning(KDECONNECT_CORE) << "error..." << mSocket->errorString(); - setError(error + 1); - setErrorText(mSocket->errorString()); - } else { - auto ba = mSocket->readAll(); - mBuffer->write(ba); - mBuffer->seek(0); - } + qWarning() << error << mSocket->errorString(); + setError(error + 1); + setErrorText(mSocket->errorString()); emitResult(); } QSharedPointer DownloadJob::getPayload() { - return mBuffer.staticCast(); + return mSocket.staticCast(); +} + +void DownloadJob::socketConnected() +{ + emitResult(); } diff --git a/core/backends/lan/downloadjob.h b/core/backends/lan/downloadjob.h index daa898eb2..3876e8c5e 100644 --- a/core/backends/lan/downloadjob.h +++ b/core/backends/lan/downloadjob.h @@ -47,11 +47,10 @@ private: QHostAddress mAddress; qint16 mPort; QSharedPointer mSocket; - QSharedPointer mBuffer; private Q_SLOTS: void socketFailed(QAbstractSocket::SocketError error); - + void socketConnected(); }; #endif // UPLOADJOB_H diff --git a/core/filetransferjob.cpp b/core/filetransferjob.cpp index 188e1ceab..7fed294ec 100644 --- a/core/filetransferjob.cpp +++ b/core/filetransferjob.cpp @@ -79,6 +79,10 @@ void FileTransferJob::doStart() void FileTransferJob::startTransfer() { + // Don't put each ready read + if (mReply) + return; + setProcessedAmount(Bytes, 0); description(this, i18n("Receiving file over KDE Connect"), { i18nc("File transfer origin", "From"), mFrom },