From 2b17d89fc1cb15861e1ea7af00cf977505d5a914 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 1 Aug 2017 22:46:06 +0200 Subject: [PATCH] Revert "No need to use a QBuffer in DownloadJob" We need to wait for KF5 release, I didn't mean to commit it This reverts commit af778b71b166c5b1850d083a6bfa375f39d91467. --- core/backends/lan/downloadjob.cpp | 41 ++++++++++++------------------- core/backends/lan/downloadjob.h | 3 ++- core/filetransferjob.cpp | 4 --- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/core/backends/lan/downloadjob.cpp b/core/backends/lan/downloadjob.cpp index 7e573d219..8db5901fb 100644 --- a/core/backends/lan/downloadjob.cpp +++ b/core/backends/lan/downloadjob.cpp @@ -31,30 +31,17 @@ #include "lanlinkprovider.h" #include "core/core_debug.h" -class QQSslSocket : public QSslSocket -{ -private: - // Workaround Qt bug https://codereview.qt-project.org/#/c/195723/ - qint64 readData(char *data, qint64 maxSize) override { - qint64 res = QSslSocket::readData(data, maxSize); - if (res == 0 && encryptedBytesAvailable() == 0 && state() != ConnectedState) { - return maxSize ? qint64(-1) : qint64(0); - } else { - return res; - } - } -}; - DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap &transferInfo) : KJob() , mAddress(address) , mPort(transferInfo[QStringLiteral("port")].toInt()) - , mSocket(new QQSslSocket) + , 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::connected, this, &DownloadJob::socketConnected); +// connect(mSocket.data(), &QAbstractSocket::stateChanged, [](QAbstractSocket::SocketState state){ qDebug() << "statechange" << state; }); } DownloadJob::~DownloadJob() @@ -67,22 +54,26 @@ 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) { - qWarning() << "error..." << (error == QAbstractSocket::RemoteHostClosedError) << mSocket->errorString(); - setError(error + 1); - setErrorText(mSocket->errorString()); + 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); + } emitResult(); } QSharedPointer DownloadJob::getPayload() { - return mSocket.staticCast(); -} - -void DownloadJob::socketConnected() -{ - emitResult(); + return mBuffer.staticCast(); } diff --git a/core/backends/lan/downloadjob.h b/core/backends/lan/downloadjob.h index 3876e8c5e..daa898eb2 100644 --- a/core/backends/lan/downloadjob.h +++ b/core/backends/lan/downloadjob.h @@ -47,10 +47,11 @@ 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 6291844d5..0ace8655a 100644 --- a/core/filetransferjob.cpp +++ b/core/filetransferjob.cpp @@ -79,10 +79,6 @@ void FileTransferJob::doStart() void FileTransferJob::startTransfer() { - // Don't put each ready read - if (mTimer.isValid()) - return; - setProcessedAmount(Bytes, 0); description(this, i18n("Receiving file over KDE Connect"), { i18nc("File transfer origin", "From"), mFrom },