From cb903a8d06471c9744ec0ed4076da65de657d0ef Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 31 Aug 2015 15:30:18 -0600 Subject: [PATCH] fix the new send asset task --- .../src/assets/SendAssetTask.cpp | 24 +++++++++---------- assignment-client/src/assets/SendAssetTask.h | 13 +++------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/assignment-client/src/assets/SendAssetTask.cpp b/assignment-client/src/assets/SendAssetTask.cpp index c4c7bf2503..8131bafaf3 100644 --- a/assignment-client/src/assets/SendAssetTask.cpp +++ b/assignment-client/src/assets/SendAssetTask.cpp @@ -22,7 +22,7 @@ #include "AssetUtils.h" -SendAssetTask::SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) : +SendAssetTask::SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir) : QRunnable(), _packet(packet), _senderNode(sendToNode), @@ -43,31 +43,31 @@ void SendAssetTask::run() { _packet->readPrimitive(&start); _packet->readPrimitive(&end); - QString hexHash = _assetHash.toHex(); + QString hexHash = assetHash.toHex(); qDebug() << "Received a request for the file (" << messageID << "): " << hexHash << " from " << start << " to " << end; - qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << _messageID; + qDebug() << "Starting task to send asset: " << hexHash << " for messageID " << messageID; auto replyPacketList = std::unique_ptr(new NLPacketList(PacketType::AssetGetReply, QByteArray(), true, true)); - replyPacketList->write(_assetHash); + replyPacketList->write(assetHash); - replyPacketList->writePrimitive(_messageID); + replyPacketList->writePrimitive(messageID); - if (_end <= _start) { + if (end <= start) { writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE); } else { QString filePath = _resourcesDir.filePath(QString(hexHash) + "." + QString(extension)); - QFile file { _filePath }; + QFile file { filePath }; if (file.open(QIODevice::ReadOnly)) { - if (file.size() < _end) { + if (file.size() < end) { writeError(replyPacketList.get(), AssetServerError::INVALID_BYTE_RANGE); - qCDebug(networking) << "Bad byte range: " << hexHash << " " << _start << ":" << _end; + qCDebug(networking) << "Bad byte range: " << hexHash << " " << start << ":" << end; } else { - auto size = _end - _start; - file.seek(_start); + auto size = end - start; + file.seek(start); replyPacketList->writePrimitive(AssetServerError::NO_ERROR); replyPacketList->writePrimitive(size); replyPacketList->write(file.read(size)); @@ -75,7 +75,7 @@ void SendAssetTask::run() { } file.close(); } else { - qCDebug(networking) << "Asset not found: " << _filePath << "(" << hexHash << ")"; + qCDebug(networking) << "Asset not found: " << filePath << "(" << hexHash << ")"; writeError(replyPacketList.get(), AssetServerError::ASSET_NOT_FOUND); } } diff --git a/assignment-client/src/assets/SendAssetTask.h b/assignment-client/src/assets/SendAssetTask.h index 1dc6c8dca2..4e1a35b3fe 100644 --- a/assignment-client/src/assets/SendAssetTask.h +++ b/assignment-client/src/assets/SendAssetTask.h @@ -21,23 +21,16 @@ #include "AssetServer.h" #include "Node.h" -namespace udt { - class Packet; -} +class NLPacket; class SendAssetTask : public QRunnable { public: - SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir); + SendAssetTask(QSharedPointer packet, const SharedNodePointer& sendToNode, const QDir& resourcesDir); void run(); private: - QSharedPointer _packet; - MessageID _messageID; - QByteArray _assetHash; - QString _filePath; - DataOffset _start; - DataOffset _end; + QSharedPointer _packet; SharedNodePointer _senderNode; QDir _resourcesDir; };