summaryrefslogtreecommitdiff
path: root/src/SinkStreamFilter.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-11-27 22:04:59 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-03 01:39:10 +0900
commitf314719618d181036ceebcf45338ab76559daf55 (patch)
treef85677a7afad929a7cf320ff93ec4265cda0dc6a /src/SinkStreamFilter.cc
parent8ac433a8e9ab8bddd96c62db4bbeac3adce2b3ba (diff)
Added --disk-cache option
This option enables disk cache. If SIZE is 0, the disk cache is disabled. This feature caches the downloaded data in memory, which grows to at most SIZE bytes. The cache storage is created for aria2 instance and shared by all downloads. The one advantage of the disk cache is reduce the disk seek time because the data is written in larger unit and it is reordered by the offset of the file. If the underlying file is heavily fragmented it is not the case.
Diffstat (limited to 'src/SinkStreamFilter.cc')
-rw-r--r--src/SinkStreamFilter.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/SinkStreamFilter.cc b/src/SinkStreamFilter.cc
index 089cf37e..a5e4566b 100644
--- a/src/SinkStreamFilter.cc
+++ b/src/SinkStreamFilter.cc
@@ -33,14 +33,20 @@
*/
/* copyright --> */
#include "SinkStreamFilter.h"
+
+#include <cstring>
+
#include "BinaryStream.h"
#include "Segment.h"
+#include "WrDiskCache.h"
+#include "Piece.h"
namespace aria2 {
const std::string SinkStreamFilter::NAME("SinkStreamFilter");
-SinkStreamFilter::SinkStreamFilter(bool hashUpdate):
+SinkStreamFilter::SinkStreamFilter(WrDiskCache* wrDiskCache, bool hashUpdate):
+ wrDiskCache_(wrDiskCache),
hashUpdate_(hashUpdate),
bytesProcessed_(0) {}
@@ -60,7 +66,16 @@ ssize_t SinkStreamFilter::transform
} else {
wlen = inlen;
}
- out->writeData(inbuf, wlen, segment->getPositionToWrite());
+ const SharedHandle<Piece>& piece = segment->getPiece();
+ if(piece && piece->getWrDiskCacheEntry()) {
+ assert(wrDiskCache_);
+ unsigned char* dataCopy = new unsigned char[wlen];
+ memcpy(dataCopy, inbuf, wlen);
+ piece->updateWrCache(wrDiskCache_, dataCopy, 0, wlen,
+ segment->getPositionToWrite());
+ } else {
+ out->writeData(inbuf, wlen, segment->getPositionToWrite());
+ }
#ifdef ENABLE_MESSAGE_DIGEST
if(hashUpdate_) {
segment->updateHash(segment->getWrittenLength(), inbuf, wlen);