summaryrefslogtreecommitdiff
path: root/src/DownloadCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-07-05 03:24:31 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-07-05 03:24:31 +0000
commit92638946899a2725dcc6e55326e64fd2cbf4768b (patch)
tree1ab3b083de59a5297d8bc6fefd1f389e69415e10 /src/DownloadCommand.cc
parent6bd4447d235c756e758e1647d125f37182097990 (diff)
2009-07-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Allocate buffer in ctor of DownloadCommand. * src/DownloadCommand.cc * src/DownloadCommand.h
Diffstat (limited to 'src/DownloadCommand.cc')
-rw-r--r--src/DownloadCommand.cc11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc
index 7652b531..cf3586d9 100644
--- a/src/DownloadCommand.cc
+++ b/src/DownloadCommand.cc
@@ -70,7 +70,8 @@ DownloadCommand::DownloadCommand(int cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
const SocketHandle& s):
- AbstractCommand(cuid, req, fileEntry, requestGroup, e, s)
+ AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
+ _buf(new unsigned char[BUFSIZE])
#ifdef ENABLE_MESSAGE_DIGEST
, _pieceHashValidationEnabled(false)
#endif // ENABLE_MESSAGE_DIGEST
@@ -110,8 +111,6 @@ bool DownloadCommand::executeInternal() {
setReadCheckSocket(socket);
SegmentHandle segment = _segments.front();
- size_t BUFSIZE = 16*1024;
- unsigned char buf[BUFSIZE];
size_t bufSize;
if(segment->getLength() > 0) {
if(segment->getPosition()+segment->getLength() <= static_cast<uint64_t>(_fileEntry->getLastOffset())) {
@@ -123,7 +122,7 @@ bool DownloadCommand::executeInternal() {
} else {
bufSize = BUFSIZE;
}
- socket->readData(buf, bufSize);
+ socket->readData(_buf, bufSize);
const SharedHandle<DiskAdaptor>& diskAdaptor =
_requestGroup->getPieceStorage()->getDiskAdaptor();
@@ -133,10 +132,10 @@ bool DownloadCommand::executeInternal() {
std::string decoded;
if(_transferEncodingDecoder.isNull()) {
- bufFinal = buf;
+ bufFinal = _buf;
bufSizeFinal = bufSize;
} else {
- decoded = _transferEncodingDecoder->decode(buf, bufSize);
+ decoded = _transferEncodingDecoder->decode(_buf, bufSize);
bufFinal = reinterpret_cast<const unsigned char*>(decoded.c_str());
bufSizeFinal = decoded.size();