summaryrefslogtreecommitdiff
path: root/src/ByteArrayDiskWriter.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-04-19 17:23:58 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-04-19 17:23:58 +0000
commite199bf88986ce441c3383e3c00ce4864a77023b2 (patch)
tree7fedb64bd0089a92251ae77aa0ec318aa35d33b6 /src/ByteArrayDiskWriter.cc
parent195aff51ba58e62a139f1a392208c88cccb3af3d (diff)
To add TrackerUpdateCommand with which replaces
CompactTrackerResponseProcessor: * src/TrackerWatcherCommand.h (req): Removed. * src/TrackerWatcherCommand.cc (execute): Send a request to tracker if the number of peer connections are less than 30. * src/ByteArrayDiskWriter.h (readData): Implemented. * src/SegmentMan.h (diskWriter): New function. * src/SegmentMan.cc (init): Added a call to diskWriter->closeFile() * src/main.cc : Removed #include "CompactTrackerResponseProcessor.h" (main): Use TrackerUpdateCommand. * src/TorrentMan.h (CompactTrackerResponseProcessor): Removed. (req): New variable. (setTrackerResponseProcessor): Removed. (getTrackerResponseProcessor): Removed. (processTrackerResponse): Removed. * src/DownloadEngine.h (diskWriter): Removed. * src/TorrentDownloadEngine.cc (afterEachIteration): Removed a call to torrentMan->processTrackerResponse(). To add Util::expandBuffer: * src/ByteArrayDiskWriter.h (expandBuffer): Removed. * src/ByteArrayDiskWriter.cc (writeData): Use Util::expandBuffer(). * src/Util.h (expandBuffer): New function. To fix the bug that causes segmentation fault when "-l ." is specified in command-line option: * src/SimpleLogger.h (SimpleLogger): Removed "filename" argument. (openFile): New function. (closeFile): New function. * src/SimpleLogger.cc (SimpleLogger): Removed fopen. (~SimpleLogger): Call closeFile(); * src/LogFactory.cc (getInstance): Added a call to slogger->openFile(). * src/main.cc (main): Added a check to see logger is configured properly. To enable HTTP authentication without specifying "--http-auth-scheme" * src/prefs.h (PREF_HTTP_AUTH_ENABLED): New definition. * src/HttpConnection.cc (createRequest): Send Authorization header if PREF_HTTP_AUTH_ENABLED == V_TRUE. * src/main.cc (main): Preset PREF_HTTP_AUTH_SCHEME to V_TRUE If "--http-user" is specified, set PREF_HTTP_AUTH_ENABLED to V_TRUE * src/Peer.cc (shouldChoke): Updated algorithm. * src/message.h (EX_AUTH_FAILED): New definition. (EX_FILE_OPEN): New definition. * src/HttpResponseCommand.cc (checkResponse): Throw DlAbortEx if status == 401. (handleDefaultEncoding): Added a call to diskWriter->initAndOpenFile() if req->isTorrent == true. * src/main.cc (handler): Removed the check to see e->diskWriter != NULL (torrentHandler): Removed the check to see diskAdaptor != NULL. * src/AbstractDiskWriter.cc (openExistingFile): Updated messsage. (createFile): Updated message.
Diffstat (limited to 'src/ByteArrayDiskWriter.cc')
-rw-r--r--src/ByteArrayDiskWriter.cc22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc
index dfc94ede..e51d500b 100644
--- a/src/ByteArrayDiskWriter.cc
+++ b/src/ByteArrayDiskWriter.cc
@@ -20,6 +20,7 @@
*/
/* copyright --> */
#include "ByteArrayDiskWriter.h"
+#include "Util.h"
ByteArrayDiskWriter::ByteArrayDiskWriter():buf(NULL) {
}
@@ -65,16 +66,23 @@ void ByteArrayDiskWriter::openExistingFile(string filename) {
void ByteArrayDiskWriter::writeData(const char* data, int dataLength, long long int position) {
if(bufLength+dataLength >= maxBufLength) {
- expandBuffer(bufLength+dataLength);
+ maxBufLength = Util::expandBuffer(&buf, bufLength, bufLength+dataLength);
}
memcpy(buf+bufLength, data, dataLength);
bufLength += dataLength;
}
-void ByteArrayDiskWriter::expandBuffer(int newSize) {
- char* newbuf = new char[newSize];
- memcpy(newbuf, buf, bufLength);
- delete [] buf;
- buf = newbuf;
- maxBufLength = newSize;
+int ByteArrayDiskWriter::readData(char* data, int len, long long int position) {
+ if(position >= bufLength) {
+ return 0;
+ }
+ int readLength;
+ if(position+len <= bufLength) {
+ readLength = len;
+ } else {
+ readLength = bufLength-position;
+ }
+ memcpy(data, buf+position, readLength);
+ return readLength;
}
+