diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-02-22 16:01:54 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-02-22 16:01:54 +0000 |
| commit | 44beebd257b0fb265bea5387850b9beb33c0adc2 (patch) | |
| tree | 0ec08e4aad18ccff2d578aca1c0b3799d2716c6c /src/DownloadCommand.cc | |
| parent | d027ca8e7c383e9755d6fb997e8a880df99e88b9 (diff) | |
| parent | 87a229cab18679042beb06076e5dec1dcfadaeae (diff) | |
Tagging release 0.2.0 of aria2release-0.2.0
Diffstat (limited to 'src/DownloadCommand.cc')
| -rw-r--r-- | src/DownloadCommand.cc | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 39391963..b771cbe5 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -27,8 +27,9 @@ #include "InitiateConnectionCommandFactory.h" #include "message.h" -DownloadCommand::DownloadCommand(int cuid, Request* req, DownloadEngine* e, Socket* s):AbstractCommand(cuid, req, e, s) { - AbstractCommand::checkSocketIsReadable = true; +DownloadCommand::DownloadCommand(int cuid, Request* req, DownloadEngine* e, Socket* s):AbstractCommand(cuid, req, e, s), lastSize(0) { + sw.tv_sec = 0; + sw.tv_usec = 0; } DownloadCommand::~DownloadCommand() {} @@ -52,6 +53,20 @@ bool DownloadCommand::executeInternal(Segment seg) { e->diskWriter->writeData(buf, bufSize, seg.sp+seg.ds); seg.ds += bufSize; } + // calculate downloading speed + struct timeval now; + gettimeofday(&now, NULL); + if(sw.tv_sec == 0 && sw.tv_usec == 0) { + sw = now; + lastSize = seg.ds; + } else { + long long int diff = Util::difftv(now, sw); + if(diff >= 1000000) { + seg.speed = (int)((seg.ds-lastSize)/(diff/1000000.0)); + sw = now; + lastSize = seg.ds; + } + } if(te != NULL && te->finished() || te == NULL && seg.ds >= seg.ep-seg.sp+1 @@ -84,3 +99,8 @@ bool DownloadCommand::prepareForNextSegment() { return true; } } + +void DownloadCommand::onAbort(Exception* ex) { + e->logger->debug(MSG_UNREGISTER_CUID, cuid); + e->segmentMan->unregisterId(cuid); +} |
