Changed int to qint64 for tracking payload size

No longer keeping the entire file in RAM while uploading
This commit is contained in:
Jens Dagerbo 2014-11-09 12:57:09 -08:00 committed by Albert Vaca
parent 3b192ea18e
commit 53a33096ad
4 changed files with 23 additions and 13 deletions

View file

@ -65,17 +65,27 @@ void UploadJob::readyRead()
{
//TODO: Implement payload encryption
qint64 bytes = qMax(mInput->bytesAvailable(), (qint64)4096);
int w = mSocket->write(mInput->read(bytes));
if (w<0) {
qWarning() << "error when writing data to upload" << bytes << mInput->bytesAvailable();
while ( mInput->bytesAvailable() > 0 )
{
qint64 bytes = qMin(mInput->bytesAvailable(), (qint64)4096);
int w = mSocket->write(mInput->read(bytes));
if (w<0) {
qWarning() << "error when writing data to upload" << bytes << mInput->bytesAvailable();
break;
}
else
{
while ( mSocket->flush() );
}
}
mInput->close();
}
void UploadJob::aboutToClose()
{
mSocket->close();
mSocket->disconnectFromHost();
mSocket->close();
emitResult();
}

View file

@ -28,7 +28,7 @@
#include "kdebugnamespace.h"
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, int size, const KUrl& destination): KJob()
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const KUrl& destination): KJob()
{
Q_ASSERT(destination.isLocalFile());
//TODO: Make a precondition before calling this function that destination file exists

View file

@ -37,7 +37,7 @@ class FileTransferJob
Q_OBJECT
public:
FileTransferJob(const QSharedPointer<QIODevice>& origin, int size, const KUrl& destination);
FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const KUrl& destination);
virtual void start();
KUrl destination() const { return mDestination; }
void setDeviceName(const QString &deviceName) {mDeviceName = deviceName;};
@ -61,8 +61,8 @@ private:
KUrl mDestination;
QTime m_time;
qulonglong m_speedBytes;
int mSize;
int mWritten;
qint64 mSize;
qint64 mWritten;
};

View file

@ -75,9 +75,9 @@ public:
bool has(const QString& key) const { return mBody.contains(key); }
QSharedPointer<QIODevice> payload() const { return mPayload; }
void setPayload(const QSharedPointer<QIODevice>& device, int payloadSize) { mPayload = device; mPayloadSize = payloadSize; Q_ASSERT(mPayloadSize >= -1); }
void setPayload(const QSharedPointer<QIODevice>& device, qint64 payloadSize) { mPayload = device; mPayloadSize = payloadSize; Q_ASSERT(mPayloadSize >= -1); }
bool hasPayload() const { return (mPayloadSize != 0); }
int payloadSize() const { return mPayloadSize; } //-1 means it is an endless stream
qint64 payloadSize() const { return mPayloadSize; } //-1 means it is an endless stream
FileTransferJob* createPayloadTransferJob(const KUrl& destination) const;
//To be called by a particular DeviceLink
@ -90,14 +90,14 @@ private:
void setId(const QString& id) { mId = id; }
void setType(const QString& t) { mType = t; }
void setBody(const QVariantMap& b) { mBody = b; }
void setPayloadSize(int s) { mPayloadSize = s; }
void setPayloadSize(qint64 s) { mPayloadSize = s; }
QString mId;
QString mType;
QVariantMap mBody;
QSharedPointer<QIODevice> mPayload;
int mPayloadSize;
qint64 mPayloadSize;
QVariantMap mPayloadTransferInfo;
};