diff --git a/ChangeLog b/ChangeLog index a7bcd13f..47c73576 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-07-05 Tatsuhiro Tsujikawa + + Allocate buffer in ctor of DownloadCommand. + * src/DownloadCommand.cc + * src/DownloadCommand.h + 2009-07-05 Tatsuhiro Tsujikawa Removed DiskAdaptor::onDownloadComplete() 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(_fileEntry->getLastOffset())) { @@ -123,7 +122,7 @@ bool DownloadCommand::executeInternal() { } else { bufSize = BUFSIZE; } - socket->readData(buf, bufSize); + socket->readData(_buf, bufSize); const SharedHandle& 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(decoded.c_str()); bufSizeFinal = decoded.size(); diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index ad078746..23a1de0c 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -47,6 +47,10 @@ class MessageDigestContext; class DownloadCommand : public AbstractCommand { private: + static const size_t BUFSIZE = 16*1024; + + unsigned char* _buf; + time_t startupIdleTime; unsigned int lowestDownloadSpeedLimit; SharedHandle peerStat;