Fix DownloadJob not finishing

We stop using a buffer so it's less memory intensive and allows for larger files to be sent.

With current KIO has CPU usage issues, there's a patch in review that fixes them.

BUGS: 378488
This commit is contained in:
Albert Astals Cid 2017-08-02 00:35:24 +02:00
parent 36c2e15fc7
commit d1d84bc464
3 changed files with 18 additions and 17 deletions

View file

@ -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();
qWarning() << error << mSocket->errorString();
setError(error + 1);
setErrorText(mSocket->errorString());
} else {
auto ba = mSocket->readAll();
mBuffer->write(ba);
mBuffer->seek(0);
}
emitResult();
}
QSharedPointer<QIODevice> DownloadJob::getPayload()
{
return mBuffer.staticCast<QIODevice>();
return mSocket.staticCast<QIODevice>();
}
void DownloadJob::socketConnected()
{
emitResult();
}

View file

@ -47,11 +47,10 @@ private:
QHostAddress mAddress;
qint16 mPort;
QSharedPointer<QSslSocket> mSocket;
QSharedPointer<QBuffer> mBuffer;
private Q_SLOTS:
void socketFailed(QAbstractSocket::SocketError error);
void socketConnected();
};
#endif // UPLOADJOB_H

View file

@ -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 },