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 af778b71b1
.
This commit is contained in:
parent
d61d52ac1f
commit
2b17d89fc1
3 changed files with 18 additions and 30 deletions
|
@ -31,30 +31,17 @@
|
||||||
#include "lanlinkprovider.h"
|
#include "lanlinkprovider.h"
|
||||||
#include "core/core_debug.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)
|
DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap &transferInfo)
|
||||||
: KJob()
|
: KJob()
|
||||||
, mAddress(address)
|
, mAddress(address)
|
||||||
, mPort(transferInfo[QStringLiteral("port")].toInt())
|
, mPort(transferInfo[QStringLiteral("port")].toInt())
|
||||||
, mSocket(new QQSslSocket)
|
, mSocket(new QSslSocket)
|
||||||
|
, mBuffer(new QBuffer)
|
||||||
{
|
{
|
||||||
LanLinkProvider::configureSslSocket(mSocket.data(), transferInfo.value(QStringLiteral("deviceId")).toString(), true);
|
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(), 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()
|
DownloadJob::~DownloadJob()
|
||||||
|
@ -67,22 +54,26 @@ void DownloadJob::start()
|
||||||
//TODO: Timeout?
|
//TODO: Timeout?
|
||||||
// Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection
|
// Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection
|
||||||
mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite);
|
mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite);
|
||||||
|
|
||||||
|
bool b = mBuffer->open(QBuffer::ReadWrite);
|
||||||
|
Q_ASSERT(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadJob::socketFailed(QAbstractSocket::SocketError error)
|
void DownloadJob::socketFailed(QAbstractSocket::SocketError error)
|
||||||
{
|
{
|
||||||
qWarning() << "error..." << (error == QAbstractSocket::RemoteHostClosedError) << mSocket->errorString();
|
if (error != QAbstractSocket::RemoteHostClosedError) { //remote host closes when finishes
|
||||||
|
qWarning(KDECONNECT_CORE) << "error..." << mSocket->errorString();
|
||||||
setError(error + 1);
|
setError(error + 1);
|
||||||
setErrorText(mSocket->errorString());
|
setErrorText(mSocket->errorString());
|
||||||
|
} else {
|
||||||
|
auto ba = mSocket->readAll();
|
||||||
|
mBuffer->write(ba);
|
||||||
|
mBuffer->seek(0);
|
||||||
|
}
|
||||||
emitResult();
|
emitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<QIODevice> DownloadJob::getPayload()
|
QSharedPointer<QIODevice> DownloadJob::getPayload()
|
||||||
{
|
{
|
||||||
return mSocket.staticCast<QIODevice>();
|
return mBuffer.staticCast<QIODevice>();
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadJob::socketConnected()
|
|
||||||
{
|
|
||||||
emitResult();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,11 @@ private:
|
||||||
QHostAddress mAddress;
|
QHostAddress mAddress;
|
||||||
qint16 mPort;
|
qint16 mPort;
|
||||||
QSharedPointer<QSslSocket> mSocket;
|
QSharedPointer<QSslSocket> mSocket;
|
||||||
|
QSharedPointer<QBuffer> mBuffer;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void socketFailed(QAbstractSocket::SocketError error);
|
void socketFailed(QAbstractSocket::SocketError error);
|
||||||
void socketConnected();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UPLOADJOB_H
|
#endif // UPLOADJOB_H
|
||||||
|
|
|
@ -79,10 +79,6 @@ void FileTransferJob::doStart()
|
||||||
|
|
||||||
void FileTransferJob::startTransfer()
|
void FileTransferJob::startTransfer()
|
||||||
{
|
{
|
||||||
// Don't put each ready read
|
|
||||||
if (mTimer.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
setProcessedAmount(Bytes, 0);
|
setProcessedAmount(Bytes, 0);
|
||||||
description(this, i18n("Receiving file over KDE Connect"),
|
description(this, i18n("Receiving file over KDE Connect"),
|
||||||
{ i18nc("File transfer origin", "From"), mFrom },
|
{ i18nc("File transfer origin", "From"), mFrom },
|
||||||
|
|
Loading…
Reference in a new issue