Allocate buffer used by DownloadCommand in stack.

pull/1/head
Tatsuhiro Tsujikawa 2010-12-08 20:41:12 +09:00
parent 9103fb6105
commit 235b5a0848
2 changed files with 6 additions and 9 deletions

View File

@ -82,7 +82,6 @@ DownloadCommand::DownloadCommand(cuid_t cuid,
DownloadEngine* e, DownloadEngine* e,
const SocketHandle& s): const SocketHandle& s):
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s), AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
buf_(new unsigned char[BUFSIZE]),
startupIdleTime_(10), startupIdleTime_(10),
lowestDownloadSpeedLimit_(0), lowestDownloadSpeedLimit_(0),
pieceHashValidationEnabled_(false) pieceHashValidationEnabled_(false)
@ -111,7 +110,6 @@ DownloadCommand::DownloadCommand(cuid_t cuid,
DownloadCommand::~DownloadCommand() { DownloadCommand::~DownloadCommand() {
peerStat_->downloadStop(); peerStat_->downloadStop();
getSegmentMan()->updateFastestPeerStat(peerStat_); getSegmentMan()->updateFastestPeerStat(peerStat_);
delete [] buf_;
} }
bool DownloadCommand::executeInternal() { bool DownloadCommand::executeInternal() {
@ -127,6 +125,7 @@ bool DownloadCommand::executeInternal() {
getPieceStorage()->getDiskAdaptor(); getPieceStorage()->getDiskAdaptor();
SharedHandle<Segment> segment = getSegments().front(); SharedHandle<Segment> segment = getSegments().front();
size_t bufSize; size_t bufSize;
unsigned char buf[BUFSIZE];
if(sinkFilterOnly_) { if(sinkFilterOnly_) {
if(segment->getLength() > 0 ) { if(segment->getLength() > 0 ) {
if(static_cast<uint64_t>(segment->getPosition()+segment->getLength()) <= if(static_cast<uint64_t>(segment->getPosition()+segment->getLength()) <=
@ -143,18 +142,18 @@ bool DownloadCommand::executeInternal() {
} else { } else {
bufSize = BUFSIZE; bufSize = BUFSIZE;
} }
getSocket()->readData(buf_, bufSize); getSocket()->readData(buf, bufSize);
streamFilter_->transform(diskAdaptor, segment, buf_, bufSize); streamFilter_->transform(diskAdaptor, segment, buf, bufSize);
} else { } else {
// It is possible that segment is completed but we have some bytes // It is possible that segment is completed but we have some bytes
// of stream to read. For example, chunked encoding has "0"+CRLF // of stream to read. For example, chunked encoding has "0"+CRLF
// after data. After we read data(at this moment segment is // after data. After we read data(at this moment segment is
// completed), we need another 3bytes(or more if it has trailers). // completed), we need another 3bytes(or more if it has trailers).
bufSize = BUFSIZE; bufSize = BUFSIZE;
getSocket()->peekData(buf_, bufSize); getSocket()->peekData(buf, bufSize);
streamFilter_->transform(diskAdaptor, segment, buf_, bufSize); streamFilter_->transform(diskAdaptor, segment, buf, bufSize);
bufSize = streamFilter_->getBytesProcessed(); bufSize = streamFilter_->getBytesProcessed();
getSocket()->readData(buf_, bufSize); getSocket()->readData(buf, bufSize);
} }
peerStat_->updateDownloadLength(bufSize); peerStat_->updateDownloadLength(bufSize);
getSegmentMan()->updateDownloadSpeedFor(peerStat_); getSegmentMan()->updateDownloadSpeedFor(peerStat_);

View File

@ -49,8 +49,6 @@ class MessageDigest;
class DownloadCommand : public AbstractCommand { class DownloadCommand : public AbstractCommand {
private: private:
unsigned char* buf_;
time_t startupIdleTime_; time_t startupIdleTime_;
unsigned int lowestDownloadSpeedLimit_; unsigned int lowestDownloadSpeedLimit_;
SharedHandle<PeerStat> peerStat_; SharedHandle<PeerStat> peerStat_;