summaryrefslogtreecommitdiff
path: root/src/ByteArrayDiskWriter.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-01-08 00:13:25 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-01-08 00:13:25 +0000
commit3a412f89b24edf25579d3904e85687373eeb2172 (patch)
tree37297c8da78643b17a773a2c6e157b074bb0ab6b /src/ByteArrayDiskWriter.cc
parenta413cb50f7035fdaa1c85b6247b98946b3342ef1 (diff)
2007-01-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add an ability to pre-allocate file space: * src/DirectDiskAdaptor.h: Rewritten. * src/PieceStorage.h: DiskAdaptor -> DiskAdaptorHandle * src/MultiDiskAdaptor.h: Rewritten. * src/DefaultPieceStorage.cc (MultiDiskWriter.h): Removed include. (PreAllocationDiskWriter.h): Removed include. (FileAllocationMonitor.h): New include. (~DefaultPieceStorage): Removed deletion of diskAdaptor. (initStorage): Rewritten. (getDiskAdaptor): DiskAdaptor -> DiskAdaptorHandle * src/FileAllocator.h: New class. * src/FileAllocator.cc: New class. * src/FileAllocationMonitor.h: New class. * src/FileAllocationMonitor.cc: New class. * src/ConsoleFileAllocationMonitor.h: New class. * src/ConsoleFileAllocationMonitor.cc: New class. * src/AbstractSingleDiskAdaptor.h: New class. * src/AbstractSingleDiskAdaptor.cc: New class. * src/DiskAdaptor.h (Directory.h): Removed include. (DiskWriter.h): Removed include. (FileEntry.h): Removed include. (diskWriter): Removed. (DiskAdaptor): Removed diskWriter. (openFile): Made pure virtual. (closeFile): Made pure virtual. (openExistingFile): Made pure virtual. (initAndOpenFile): Made pure virtual. (writeData): Made pure virtual. (readData): Made pure virtual. (sha1Sum): Made pure virtual. (getStoreDir): Returns const reference of storeDir. (DiskAdaptorHandle): New type definition. * src/main.cc (ConsoleFileAllocationMonitor.h): New include. (showUsage): Added default value description of -s option. Added the description of --file-allocation option. (main): Set default value of --file-allocation option to 'none'. Added --file-allocation command-line option. Setup FileAllocationMonitorFactory. * src/FtpInitiateConnectionCommand.cc (executeInternal): Removed diskWriter related processing, which was moved to FtpNegotiationCommand.cc. * src/DirectDiskAdaptor.cc (getFilePath): Made non-const. * src/CopyDiskAdaptor.h (DiskAdaptor.h): Removed include. (DiskWriter.h): Removed include. (AbstractSingleDiskAdaptor.h): New include. (getFilePath): Made non-const. Added virtual keyword. (CopyDiskAdaptor): Removed diskWriter. (getTempFile): Returns const reference. (CopyDiskAdaptorHandle): New type definition. * src/ByteArrayDiskWriter.cc (clear): Simplified. (initAndOpenFile): Rewritten. (openFile): Call initAndOpenFile() * src/MultiDiskAdaptor.cc: Rewritten. * src/DownloadEngineFactory.cc (FileAllocator.h): New include. (FileAllocationMonitor.h): New include. (newConsoleEngine): Call DefaultDiskWriter::createNewDiskWriter() to create DefaultDiskWriter with file allocator. * src/DiskWriter.h (initAndOpenFile): Added totalLength argument. (openFile): Added totalLength argument. * src/prefs.h (PREF_FILE_ALLOCATION): New definition. (V_PREALLOC): New definition. (V_NONE): New definition. * src/HttpResponseCommand.cc (handleDefaultEncoding): Call DefaultDiskWriter::initAndOpenFile with size. * src/FtpNegotiateCommand.cc (Util.h): New include. (recvSize): Open file here. * src/Util.h (ullitos): New function. * src/CopyDiskWriter.h (getFilePath): Made non-const. * src/DefaultDiskWriter.h (Option.h): New include. (totalLength): Removed. (DefaultDiskWriter): Removed totalLength. (initAndOpenFile): Added totalLength argument. (DefaultDiskWriterHandle): New type definition. (createNewDiskWriter): New function. * src/Util.cc (ullitos): New function. * src/DefaultDiskWriter.cc (message.h): New include. (FileAllocator.h): New include. (prefs.h): New include. (Util.h): New include. (DefaultDiskWriter): Removed totalLength. (initAndOpenFile): Added file allocation. (createNewDiskWriter): New function. Just for temporary solution. It will be rewritten later. * src/DiskAdaptor.cc (DiskAdaptor): Removed diskWriter. * src/AbstractDiskWriter.cc (LogFactory.h): New include. (AbstractDiskWriter): Added fileAllocator, logger. (openFile): Added totalLength argument. * src/AbstractDiskWriter.h (FileAllocator.h): New include. (Logger.h): New include. (fileAllocator): New variable. (logger): New variable. (openFile): Added totalLength argument. Added virtual keyword explicitly. (openExistingFile): Added totalLength argument. Added virtual keyword explicitly. (closeFile): Added virtual keyword explicitly. (sha1Sum): Added virtual keyword explicitly. (writeData): Added virtual keyword explicitly. (readData): Added virtual keyword explicitly. (setFileAllocator): New function. * src/DefaultPieceStorage.h (FileAllocator.h): New include. (diskAdaptor): DiskAdaptor -> DiskAdaptorHandle (getDiskAdaptor): DiskAdaptor -> DiskAdaptorHandle * src/FileProgressMonitor.h: New class. To compile aria2 on PC-BSD: * src/DefaultBtContext.cc (libgen.h): New include. To fix memory leak: * src/Exception.h (~Exception): Delete cause. Fixed memory leak.
Diffstat (limited to 'src/ByteArrayDiskWriter.cc')
-rw-r--r--src/ByteArrayDiskWriter.cc25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc
index e916197d..63236014 100644
--- a/src/ByteArrayDiskWriter.cc
+++ b/src/ByteArrayDiskWriter.cc
@@ -35,7 +35,7 @@
#include "ByteArrayDiskWriter.h"
#include "Util.h"
-ByteArrayDiskWriter::ByteArrayDiskWriter():buf(NULL) {
+ByteArrayDiskWriter::ByteArrayDiskWriter():buf(0) {
}
ByteArrayDiskWriter::~ByteArrayDiskWriter() {
@@ -43,10 +43,7 @@ ByteArrayDiskWriter::~ByteArrayDiskWriter() {
}
void ByteArrayDiskWriter::clear() {
- if(buf != NULL) {
- delete [] buf;
- buf = NULL;
- }
+ delete [] buf;
}
void ByteArrayDiskWriter::init() {
@@ -55,15 +52,17 @@ void ByteArrayDiskWriter::init() {
bufLength = 0;
}
-void ByteArrayDiskWriter::initAndOpenFile(const string& filename) {
- openFile(filename);
-}
-
-void ByteArrayDiskWriter::openFile(const string& filename) {
+void ByteArrayDiskWriter::initAndOpenFile(const string& filename,
+ uint64_t totalLength) {
clear();
init();
}
+void ByteArrayDiskWriter::openFile(const string& filename,
+ uint64_t totalLength) {
+ initAndOpenFile(filename);
+}
+
void ByteArrayDiskWriter::closeFile() {
clear();
}
@@ -72,7 +71,7 @@ void ByteArrayDiskWriter::openExistingFile(const string& filename) {
openFile(filename);
}
-void ByteArrayDiskWriter::writeData(const char* data, int dataLength, long long int position) {
+void ByteArrayDiskWriter::writeData(const char* data, uint32_t dataLength, int64_t position) {
if(bufLength+dataLength >= maxBufLength) {
maxBufLength = Util::expandBuffer(&buf, bufLength, bufLength+dataLength);
}
@@ -80,11 +79,11 @@ void ByteArrayDiskWriter::writeData(const char* data, int dataLength, long long
bufLength += dataLength;
}
-int ByteArrayDiskWriter::readData(char* data, int len, long long int position) {
+int ByteArrayDiskWriter::readData(char* data, uint32_t len, int64_t position) {
if(position >= bufLength) {
return 0;
}
- int readLength;
+ uint32_t readLength;
if(position+len <= bufLength) {
readLength = len;
} else {