mirror of https://github.com/aria2/aria2
wallclock is now retrieved using global::wallclock() call.
This is necessary to avoid global variable initialization order problem.pull/1/head
parent
97f34ab668
commit
e8e3a6f259
|
@ -85,7 +85,7 @@ AbstractCommand::AbstractCommand
|
||||||
const SocketHandle& s,
|
const SocketHandle& s,
|
||||||
const SharedHandle<SocketRecvBuffer>& socketRecvBuffer,
|
const SharedHandle<SocketRecvBuffer>& socketRecvBuffer,
|
||||||
bool incNumConnection)
|
bool incNumConnection)
|
||||||
: Command(cuid), checkPoint_(global::wallclock),
|
: Command(cuid), checkPoint_(global::wallclock()),
|
||||||
timeout_(requestGroup->getTimeout()),
|
timeout_(requestGroup->getTimeout()),
|
||||||
requestGroup_(requestGroup),
|
requestGroup_(requestGroup),
|
||||||
req_(req), fileEntry_(fileEntry), e_(e), socket_(s),
|
req_(req), fileEntry_(fileEntry), e_(e), socket_(s),
|
||||||
|
@ -93,7 +93,7 @@ AbstractCommand::AbstractCommand
|
||||||
checkSocketIsReadable_(false), checkSocketIsWritable_(false),
|
checkSocketIsReadable_(false), checkSocketIsWritable_(false),
|
||||||
nameResolverCheck_(false),
|
nameResolverCheck_(false),
|
||||||
incNumConnection_(incNumConnection),
|
incNumConnection_(incNumConnection),
|
||||||
serverStatTimer_(global::wallclock)
|
serverStatTimer_(global::wallclock())
|
||||||
{
|
{
|
||||||
if(socket_ && socket_->isOpen()) {
|
if(socket_ && socket_->isOpen()) {
|
||||||
setReadCheckSocket(socket_);
|
setReadCheckSocket(socket_);
|
||||||
|
@ -184,8 +184,8 @@ bool AbstractCommand::execute() {
|
||||||
if(req_ && fileEntry_->getLength() > 0 &&
|
if(req_ && fileEntry_->getLength() > 0 &&
|
||||||
e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit() == 0 &&
|
e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit() == 0 &&
|
||||||
requestGroup_->getMaxDownloadSpeedLimit() == 0 &&
|
requestGroup_->getMaxDownloadSpeedLimit() == 0 &&
|
||||||
serverStatTimer_.difference(global::wallclock) >= 10) {
|
serverStatTimer_.difference(global::wallclock()) >= 10) {
|
||||||
serverStatTimer_ = global::wallclock;
|
serverStatTimer_ = global::wallclock();
|
||||||
std::vector<std::pair<size_t, std::string> > usedHosts;
|
std::vector<std::pair<size_t, std::string> > usedHosts;
|
||||||
if(getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
|
if(getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
|
||||||
getDownloadEngine()->getRequestGroupMan()->getUsedHosts(usedHosts);
|
getDownloadEngine()->getRequestGroupMan()->getUsedHosts(usedHosts);
|
||||||
|
@ -209,7 +209,7 @@ bool AbstractCommand::execute() {
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
(!checkSocketIsReadable_ && !checkSocketIsWritable_ &&
|
(!checkSocketIsReadable_ && !checkSocketIsWritable_ &&
|
||||||
!nameResolverCheck_)) {
|
!nameResolverCheck_)) {
|
||||||
checkPoint_ = global::wallclock;
|
checkPoint_ = global::wallclock();
|
||||||
if(getPieceStorage()) {
|
if(getPieceStorage()) {
|
||||||
if(!req_ || req_->getMaxPipelinedRequest() == 1 ||
|
if(!req_ || req_->getMaxPipelinedRequest() == 1 ||
|
||||||
// Why the following condition is necessary? That's because
|
// Why the following condition is necessary? That's because
|
||||||
|
@ -263,7 +263,7 @@ bool AbstractCommand::execute() {
|
||||||
throw DL_RETRY_EX(fmt(MSG_NETWORK_PROBLEM,
|
throw DL_RETRY_EX(fmt(MSG_NETWORK_PROBLEM,
|
||||||
socket_->getSocketError().c_str()));
|
socket_->getSocketError().c_str()));
|
||||||
} else {
|
} else {
|
||||||
if(checkPoint_.difference(global::wallclock) >= timeout_) {
|
if(checkPoint_.difference(global::wallclock()) >= timeout_) {
|
||||||
// timeout triggers ServerStat error state.
|
// timeout triggers ServerStat error state.
|
||||||
SharedHandle<ServerStat> ss =
|
SharedHandle<ServerStat> ss =
|
||||||
e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(),
|
e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(),
|
||||||
|
@ -339,7 +339,7 @@ bool AbstractCommand::execute() {
|
||||||
tryReserved();
|
tryReserved();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Timer wakeTime(global::wallclock);
|
Timer wakeTime(global::wallclock());
|
||||||
wakeTime.advance(getOption()->getAsInt(PREF_RETRY_WAIT));
|
wakeTime.advance(getOption()->getAsInt(PREF_RETRY_WAIT));
|
||||||
req_->setWakeTime(wakeTime);
|
req_->setWakeTime(wakeTime);
|
||||||
return prepareForRetry(0);
|
return prepareForRetry(0);
|
||||||
|
|
|
@ -79,8 +79,8 @@ bool ActivePeerConnectionCommand::execute() {
|
||||||
if(btRuntime_->isHalt()) {
|
if(btRuntime_->isHalt()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(checkPoint_.difference(global::wallclock) >= interval_) {
|
if(checkPoint_.difference(global::wallclock()) >= interval_) {
|
||||||
checkPoint_ = global::wallclock;
|
checkPoint_ = global::wallclock();
|
||||||
TransferStat tstat = requestGroup_->calculateStat();
|
TransferStat tstat = requestGroup_->calculateStat();
|
||||||
const unsigned int maxDownloadLimit =
|
const unsigned int maxDownloadLimit =
|
||||||
requestGroup_->getMaxDownloadSpeedLimit();
|
requestGroup_->getMaxDownloadSpeedLimit();
|
||||||
|
|
|
@ -57,7 +57,7 @@ BtLeecherStateChoke::PeerEntry::PeerEntry(const SharedHandle<Peer>& peer):
|
||||||
// peer must be interested to us and sent block in the last 30 seconds
|
// peer must be interested to us and sent block in the last 30 seconds
|
||||||
regularUnchoker_
|
regularUnchoker_
|
||||||
(peer->peerInterested() &&
|
(peer->peerInterested() &&
|
||||||
peer->getLastDownloadUpdate().difference(global::wallclock) < 30) {}
|
peer->getLastDownloadUpdate().difference(global::wallclock()) < 30) {}
|
||||||
|
|
||||||
BtLeecherStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
|
BtLeecherStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
|
||||||
: peer_(c.peer_),
|
: peer_(c.peer_),
|
||||||
|
@ -208,7 +208,7 @@ BtLeecherStateChoke::executeChoke
|
||||||
(const std::vector<SharedHandle<Peer> >& peerSet)
|
(const std::vector<SharedHandle<Peer> >& peerSet)
|
||||||
{
|
{
|
||||||
A2_LOG_INFO(fmt("Leecher state, %d choke round started", round_));
|
A2_LOG_INFO(fmt("Leecher state, %d choke round started", round_));
|
||||||
lastRound_ = global::wallclock;
|
lastRound_ = global::wallclock();
|
||||||
|
|
||||||
std::vector<PeerEntry> peerEntries;
|
std::vector<PeerEntry> peerEntries;
|
||||||
std::transform(peerSet.begin(), peerSet.end(),
|
std::transform(peerSet.begin(), peerSet.end(),
|
||||||
|
|
|
@ -57,7 +57,7 @@ BtSeederStateChoke::PeerEntry::PeerEntry
|
||||||
peer_(peer),
|
peer_(peer),
|
||||||
outstandingUpload_(peer->countOutstandingUpload()),
|
outstandingUpload_(peer->countOutstandingUpload()),
|
||||||
lastAmUnchoking_(peer->getLastAmUnchoking()),
|
lastAmUnchoking_(peer->getLastAmUnchoking()),
|
||||||
recentUnchoking_(lastAmUnchoking_.difference(global::wallclock) < TIME_FRAME),
|
recentUnchoking_(lastAmUnchoking_.difference(global::wallclock()) < TIME_FRAME),
|
||||||
uploadSpeed_(peer->calculateUploadSpeed())
|
uploadSpeed_(peer->calculateUploadSpeed())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ BtSeederStateChoke::executeChoke
|
||||||
(const std::vector<SharedHandle<Peer> >& peerSet)
|
(const std::vector<SharedHandle<Peer> >& peerSet)
|
||||||
{
|
{
|
||||||
A2_LOG_INFO(fmt("Seeder state, %d choke round started", round_));
|
A2_LOG_INFO(fmt("Seeder state, %d choke round started", round_));
|
||||||
lastRound_ = global::wallclock;
|
lastRound_ = global::wallclock();
|
||||||
|
|
||||||
std::vector<PeerEntry> peerEntries;
|
std::vector<PeerEntry> peerEntries;
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ void BtStopDownloadCommand::preProcess()
|
||||||
if(btRuntime_->isHalt() || pieceStorage_->downloadFinished()) {
|
if(btRuntime_->isHalt() || pieceStorage_->downloadFinished()) {
|
||||||
enableExit();
|
enableExit();
|
||||||
}
|
}
|
||||||
if(checkPoint_.difference(global::wallclock) >= timeout_) {
|
if(checkPoint_.difference(global::wallclock()) >= timeout_) {
|
||||||
A2_LOG_NOTICE(fmt("GID#%s Stop downloading torrent due to"
|
A2_LOG_NOTICE(fmt("GID#%s Stop downloading torrent due to"
|
||||||
" --bt-stop-timeout option.",
|
" --bt-stop-timeout option.",
|
||||||
util::itos(requestGroup_->getGID()).c_str()));
|
util::itos(requestGroup_->getGID()).c_str()));
|
||||||
|
@ -73,7 +73,7 @@ void BtStopDownloadCommand::preProcess()
|
||||||
void BtStopDownloadCommand::process()
|
void BtStopDownloadCommand::process()
|
||||||
{
|
{
|
||||||
if(requestGroup_->calculateStat().getDownloadSpeed() > 0) {
|
if(requestGroup_->calculateStat().getDownloadSpeed() > 0) {
|
||||||
checkPoint_ = global::wallclock;
|
checkPoint_ = global::wallclock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,10 +248,10 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval, bool humanReadable):
|
||||||
void
|
void
|
||||||
ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
{
|
{
|
||||||
if(cp_.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS < 1000) {
|
if(cp_.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS < 1000) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cp_ = global::wallclock;
|
cp_ = global::wallclock();
|
||||||
const SizeFormatter& sizeFormatter = *sizeFormatter_.get();
|
const SizeFormatter& sizeFormatter = *sizeFormatter_.get();
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|
@ -278,9 +278,9 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
||||||
if((summaryInterval_ > 0) &&
|
if((summaryInterval_ > 0) &&
|
||||||
lastSummaryNotified_.differenceInMillis(global::wallclock)+
|
lastSummaryNotified_.differenceInMillis(global::wallclock())+
|
||||||
A2_DELTA_MILLIS >= summaryInterval_*1000) {
|
A2_DELTA_MILLIS >= summaryInterval_*1000) {
|
||||||
lastSummaryNotified_ = global::wallclock;
|
lastSummaryNotified_ = global::wallclock();
|
||||||
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
|
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
|
||||||
sizeFormatter);
|
sizeFormatter);
|
||||||
global::cout->write("\n");
|
global::cout->write("\n");
|
||||||
|
|
|
@ -98,7 +98,7 @@ bool CreateRequestCommand::executeInternal()
|
||||||
// so use it here.
|
// so use it here.
|
||||||
throw DL_ABORT_EX2("No URI available.",
|
throw DL_ABORT_EX2("No URI available.",
|
||||||
getRequestGroup()->getLastErrorCode());
|
getRequestGroup()->getLastErrorCode());
|
||||||
} else if(getRequest()->getWakeTime() > global::wallclock) {
|
} else if(getRequest()->getWakeTime() > global::wallclock()) {
|
||||||
A2_LOG_DEBUG("This request object is still sleeping.");
|
A2_LOG_DEBUG("This request object is still sleeping.");
|
||||||
getFileEntry()->poolRequest(getRequest());
|
getFileEntry()->poolRequest(getRequest());
|
||||||
getDownloadEngine()->addCommand(this);
|
getDownloadEngine()->addCommand(this);
|
||||||
|
|
|
@ -57,7 +57,7 @@ DHTBucket::DHTBucket
|
||||||
const SharedHandle<DHTNode>& localNode)
|
const SharedHandle<DHTNode>& localNode)
|
||||||
: prefixLength_(prefixLength),
|
: prefixLength_(prefixLength),
|
||||||
localNode_(localNode),
|
localNode_(localNode),
|
||||||
lastUpdated_(global::wallclock)
|
lastUpdated_(global::wallclock())
|
||||||
{
|
{
|
||||||
memcpy(max_, max, DHT_ID_LENGTH);
|
memcpy(max_, max, DHT_ID_LENGTH);
|
||||||
memcpy(min_, min, DHT_ID_LENGTH);
|
memcpy(min_, min, DHT_ID_LENGTH);
|
||||||
|
@ -66,7 +66,7 @@ DHTBucket::DHTBucket
|
||||||
DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode)
|
DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode)
|
||||||
: prefixLength_(0),
|
: prefixLength_(0),
|
||||||
localNode_(localNode),
|
localNode_(localNode),
|
||||||
lastUpdated_(global::wallclock)
|
lastUpdated_(global::wallclock())
|
||||||
{
|
{
|
||||||
memset(max_, 0xffu, DHT_ID_LENGTH);
|
memset(max_, 0xffu, DHT_ID_LENGTH);
|
||||||
memset(min_, 0, DHT_ID_LENGTH);
|
memset(min_, 0, DHT_ID_LENGTH);
|
||||||
|
@ -249,12 +249,12 @@ bool DHTBucket::operator==(const DHTBucket& bucket) const
|
||||||
bool DHTBucket::needsRefresh() const
|
bool DHTBucket::needsRefresh() const
|
||||||
{
|
{
|
||||||
return nodes_.size() < K ||
|
return nodes_.size() < K ||
|
||||||
lastUpdated_.difference(global::wallclock) >= DHT_BUCKET_REFRESH_INTERVAL;
|
lastUpdated_.difference(global::wallclock()) >= DHT_BUCKET_REFRESH_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTBucket::notifyUpdate()
|
void DHTBucket::notifyUpdate()
|
||||||
{
|
{
|
||||||
lastUpdated_ = global::wallclock;
|
lastUpdated_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -90,7 +90,7 @@ bool DHTGetPeersCommand::execute()
|
||||||
if(btRuntime_->isHalt()) {
|
if(btRuntime_->isHalt()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
time_t elapsed = lastGetPeerTime_.difference(global::wallclock);
|
time_t elapsed = lastGetPeerTime_.difference(global::wallclock());
|
||||||
if(!task_ &&
|
if(!task_ &&
|
||||||
(elapsed >= GET_PEER_INTERVAL ||
|
(elapsed >= GET_PEER_INTERVAL ||
|
||||||
(((btRuntime_->lessThanMinPeers() &&
|
(((btRuntime_->lessThanMinPeers() &&
|
||||||
|
@ -109,7 +109,7 @@ bool DHTGetPeersCommand::execute()
|
||||||
taskQueue_->addPeriodicTask2(task_);
|
taskQueue_->addPeriodicTask2(task_);
|
||||||
} else if(task_ && task_->finished()) {
|
} else if(task_ && task_->finished()) {
|
||||||
A2_LOG_DEBUG("task finished detected");
|
A2_LOG_DEBUG("task finished detected");
|
||||||
lastGetPeerTime_ = global::wallclock;
|
lastGetPeerTime_ = global::wallclock();
|
||||||
if(numRetry_ < MAX_RETRIES &&
|
if(numRetry_ < MAX_RETRIES &&
|
||||||
(btRuntime_->getMaxPeers() == 0 ||
|
(btRuntime_->getMaxPeers() == 0 ||
|
||||||
btRuntime_->getMaxPeers() > peerStorage_->countPeer())) {
|
btRuntime_->getMaxPeers() > peerStorage_->countPeer())) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ DHTMessageTrackerEntry::DHTMessageTrackerEntry(const SharedHandle<DHTMessage>& s
|
||||||
transactionID_(sentMessage->getTransactionID()),
|
transactionID_(sentMessage->getTransactionID()),
|
||||||
messageType_(sentMessage->getMessageType()),
|
messageType_(sentMessage->getMessageType()),
|
||||||
callback_(callback),
|
callback_(callback),
|
||||||
dispatchedTime_(global::wallclock),
|
dispatchedTime_(global::wallclock()),
|
||||||
timeout_(timeout)
|
timeout_(timeout)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ DHTMessageTrackerEntry::~DHTMessageTrackerEntry() {}
|
||||||
|
|
||||||
bool DHTMessageTrackerEntry::isTimeout() const
|
bool DHTMessageTrackerEntry::isTimeout() const
|
||||||
{
|
{
|
||||||
return dispatchedTime_.difference(global::wallclock) >= timeout_;
|
return dispatchedTime_.difference(global::wallclock()) >= timeout_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageTrackerEntry::extendTimeout()
|
void DHTMessageTrackerEntry::extendTimeout()
|
||||||
|
@ -81,7 +81,7 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
|
||||||
|
|
||||||
int64_t DHTMessageTrackerEntry::getElapsedMillis() const
|
int64_t DHTMessageTrackerEntry::getElapsedMillis() const
|
||||||
{
|
{
|
||||||
return dispatchedTime_.differenceInMillis(global::wallclock);
|
return dispatchedTime_.differenceInMillis(global::wallclock());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "DHTConstants.h"
|
#include "DHTConstants.h"
|
||||||
#include "TimerA2.h"
|
#include "TimerA2.h"
|
||||||
#include "wallclock.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ bool DHTNode::isBad() const
|
||||||
bool DHTNode::isQuestionable() const
|
bool DHTNode::isQuestionable() const
|
||||||
{
|
{
|
||||||
return !isBad() &&
|
return !isBad() &&
|
||||||
lastContact_.difference(global::wallclock) >= DHT_NODE_CONTACT_INTERVAL;
|
lastContact_.difference(global::wallclock()) >= DHT_NODE_CONTACT_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTNode::markGood()
|
void DHTNode::markGood()
|
||||||
|
@ -107,7 +107,7 @@ void DHTNode::markBad()
|
||||||
|
|
||||||
void DHTNode::updateLastContact()
|
void DHTNode::updateLastContact()
|
||||||
{
|
{
|
||||||
lastContact_ = global::wallclock;
|
lastContact_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTNode::timeout()
|
void DHTNode::timeout()
|
||||||
|
|
|
@ -75,7 +75,7 @@ public:
|
||||||
|
|
||||||
bool operator()(const PeerAddrEntry& entry) const
|
bool operator()(const PeerAddrEntry& entry) const
|
||||||
{
|
{
|
||||||
if(entry.getLastUpdated().difference(global::wallclock) >= timeout_) {
|
if(entry.getLastUpdated().difference(global::wallclock()) >= timeout_) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -107,7 +107,7 @@ void DHTPeerAnnounceEntry::getPeers
|
||||||
|
|
||||||
void DHTPeerAnnounceEntry::notifyUpdate()
|
void DHTPeerAnnounceEntry::notifyUpdate()
|
||||||
{
|
{
|
||||||
lastUpdated_ = global::wallclock;
|
lastUpdated_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -145,7 +145,7 @@ void DHTPeerAnnounceStorage::announcePeer()
|
||||||
for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
|
for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
|
||||||
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
|
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
|
||||||
if((*i)->getLastUpdated().
|
if((*i)->getLastUpdated().
|
||||||
difference(global::wallclock) >= DHT_PEER_ANNOUNCE_INTERVAL) {
|
difference(global::wallclock()) >= DHT_PEER_ANNOUNCE_INTERVAL) {
|
||||||
(*i)->notifyUpdate();
|
(*i)->notifyUpdate();
|
||||||
SharedHandle<DHTTask> task =
|
SharedHandle<DHTTask> task =
|
||||||
taskFactory_->createPeerAnnounceTask((*i)->getInfoHash());
|
taskFactory_->createPeerAnnounceTask((*i)->getInfoHash());
|
||||||
|
|
|
@ -79,7 +79,7 @@ bool DefaultBtAnnounce::isDefaultAnnounceReady() {
|
||||||
return
|
return
|
||||||
(trackers_ == 0 &&
|
(trackers_ == 0 &&
|
||||||
prevAnnounceTimer_.
|
prevAnnounceTimer_.
|
||||||
difference(global::wallclock) >= (userDefinedInterval_==0?
|
difference(global::wallclock()) >= (userDefinedInterval_==0?
|
||||||
minInterval_:userDefinedInterval_) &&
|
minInterval_:userDefinedInterval_) &&
|
||||||
!announceList_.allTiersFailed());
|
!announceList_.allTiersFailed());
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ bool DefaultBtAnnounce::isAllAnnounceFailed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtAnnounce::resetAnnounce() {
|
void DefaultBtAnnounce::resetAnnounce() {
|
||||||
prevAnnounceTimer_ = global::wallclock;
|
prevAnnounceTimer_ = global::wallclock();
|
||||||
announceList_.resetTier();
|
announceList_.resetTier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,12 +84,12 @@ DefaultBtInteractive::DefaultBtInteractive
|
||||||
metadataGetMode_(false),
|
metadataGetMode_(false),
|
||||||
localNode_(0),
|
localNode_(0),
|
||||||
allowedFastSetSize_(10),
|
allowedFastSetSize_(10),
|
||||||
haveTimer_(global::wallclock),
|
haveTimer_(global::wallclock()),
|
||||||
keepAliveTimer_(global::wallclock),
|
keepAliveTimer_(global::wallclock()),
|
||||||
floodingTimer_(global::wallclock),
|
floodingTimer_(global::wallclock()),
|
||||||
inactiveTimer_(global::wallclock),
|
inactiveTimer_(global::wallclock()),
|
||||||
pexTimer_(global::wallclock),
|
pexTimer_(global::wallclock()),
|
||||||
perSecTimer_(global::wallclock),
|
perSecTimer_(global::wallclock()),
|
||||||
keepAliveInterval_(120),
|
keepAliveInterval_(120),
|
||||||
utPexEnabled_(false),
|
utPexEnabled_(false),
|
||||||
dhtEnabled_(false),
|
dhtEnabled_(false),
|
||||||
|
@ -161,8 +161,8 @@ BtMessageHandle DefaultBtInteractive::receiveAndSendHandshake() {
|
||||||
void DefaultBtInteractive::doPostHandshakeProcessing() {
|
void DefaultBtInteractive::doPostHandshakeProcessing() {
|
||||||
// Set time 0 to haveTimer to cache http/ftp download piece completion
|
// Set time 0 to haveTimer to cache http/ftp download piece completion
|
||||||
haveTimer_.reset(0);
|
haveTimer_.reset(0);
|
||||||
keepAliveTimer_ = global::wallclock;
|
keepAliveTimer_ = global::wallclock();
|
||||||
floodingTimer_ = global::wallclock;
|
floodingTimer_ = global::wallclock();
|
||||||
pexTimer_.reset(0);
|
pexTimer_.reset(0);
|
||||||
if(peer_->isExtendedMessagingEnabled()) {
|
if(peer_->isExtendedMessagingEnabled()) {
|
||||||
addHandshakeExtendedMessageToQueue();
|
addHandshakeExtendedMessageToQueue();
|
||||||
|
@ -247,7 +247,7 @@ void DefaultBtInteractive::decideChoking() {
|
||||||
void DefaultBtInteractive::checkHave() {
|
void DefaultBtInteractive::checkHave() {
|
||||||
std::vector<size_t> indexes;
|
std::vector<size_t> indexes;
|
||||||
pieceStorage_->getAdvertisedPieceIndexes(indexes, cuid_, haveTimer_);
|
pieceStorage_->getAdvertisedPieceIndexes(indexes, cuid_, haveTimer_);
|
||||||
haveTimer_ = global::wallclock;
|
haveTimer_ = global::wallclock();
|
||||||
if(indexes.size() >= 20) {
|
if(indexes.size() >= 20) {
|
||||||
if(peer_->isFastExtensionEnabled() &&
|
if(peer_->isFastExtensionEnabled() &&
|
||||||
pieceStorage_->allDownloadFinished()) {
|
pieceStorage_->allDownloadFinished()) {
|
||||||
|
@ -264,10 +264,10 @@ void DefaultBtInteractive::checkHave() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtInteractive::sendKeepAlive() {
|
void DefaultBtInteractive::sendKeepAlive() {
|
||||||
if(keepAliveTimer_.difference(global::wallclock) >= keepAliveInterval_) {
|
if(keepAliveTimer_.difference(global::wallclock()) >= keepAliveInterval_) {
|
||||||
dispatcher_->addMessageToQueue(messageFactory_->createKeepAliveMessage());
|
dispatcher_->addMessageToQueue(messageFactory_->createKeepAliveMessage());
|
||||||
dispatcher_->sendMessages();
|
dispatcher_->sendMessages();
|
||||||
keepAliveTimer_ = global::wallclock;
|
keepAliveTimer_ = global::wallclock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ size_t DefaultBtInteractive::receiveMessages() {
|
||||||
peerStorage_->updateTransferStatFor(peer_);
|
peerStorage_->updateTransferStatFor(peer_);
|
||||||
// pass through
|
// pass through
|
||||||
case BtRequestMessage::ID:
|
case BtRequestMessage::ID:
|
||||||
inactiveTimer_ = global::wallclock;
|
inactiveTimer_ = global::wallclock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,20 +422,20 @@ void DefaultBtInteractive::sendPendingMessage() {
|
||||||
|
|
||||||
void DefaultBtInteractive::detectMessageFlooding() {
|
void DefaultBtInteractive::detectMessageFlooding() {
|
||||||
if(floodingTimer_.
|
if(floodingTimer_.
|
||||||
difference(global::wallclock) >= FLOODING_CHECK_INTERVAL) {
|
difference(global::wallclock()) >= FLOODING_CHECK_INTERVAL) {
|
||||||
if(floodingStat_.getChokeUnchokeCount() >= 2 ||
|
if(floodingStat_.getChokeUnchokeCount() >= 2 ||
|
||||||
floodingStat_.getKeepAliveCount() >= 2) {
|
floodingStat_.getKeepAliveCount() >= 2) {
|
||||||
throw DL_ABORT_EX(EX_FLOODING_DETECTED);
|
throw DL_ABORT_EX(EX_FLOODING_DETECTED);
|
||||||
} else {
|
} else {
|
||||||
floodingStat_.reset();
|
floodingStat_.reset();
|
||||||
}
|
}
|
||||||
floodingTimer_ = global::wallclock;
|
floodingTimer_ = global::wallclock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtInteractive::checkActiveInteraction()
|
void DefaultBtInteractive::checkActiveInteraction()
|
||||||
{
|
{
|
||||||
time_t inactiveTime = inactiveTimer_.difference(global::wallclock);
|
time_t inactiveTime = inactiveTimer_.difference(global::wallclock());
|
||||||
// To allow aria2 to accept mutially interested peer, disconnect unintersted
|
// To allow aria2 to accept mutially interested peer, disconnect unintersted
|
||||||
// peer.
|
// peer.
|
||||||
{
|
{
|
||||||
|
@ -471,7 +471,7 @@ void DefaultBtInteractive::checkActiveInteraction()
|
||||||
void DefaultBtInteractive::addPeerExchangeMessage()
|
void DefaultBtInteractive::addPeerExchangeMessage()
|
||||||
{
|
{
|
||||||
if(pexTimer_.
|
if(pexTimer_.
|
||||||
difference(global::wallclock) >= UTPexExtensionMessage::DEFAULT_INTERVAL) {
|
difference(global::wallclock()) >= UTPexExtensionMessage::DEFAULT_INTERVAL) {
|
||||||
UTPexExtensionMessageHandle m
|
UTPexExtensionMessageHandle m
|
||||||
(new UTPexExtensionMessage(peer_->getExtensionMessageID("ut_pex")));
|
(new UTPexExtensionMessage(peer_->getExtensionMessageID("ut_pex")));
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
|
||||||
|
|
||||||
BtMessageHandle msg = messageFactory_->createBtExtendedMessage(m);
|
BtMessageHandle msg = messageFactory_->createBtExtendedMessage(m);
|
||||||
dispatcher_->addMessageToQueue(msg);
|
dispatcher_->addMessageToQueue(msg);
|
||||||
pexTimer_ = global::wallclock;
|
pexTimer_ = global::wallclock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,8 +517,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
||||||
utMetadataRequestFactory_->create(requests, num, pieceStorage_);
|
utMetadataRequestFactory_->create(requests, num, pieceStorage_);
|
||||||
dispatcher_->addMessageToQueue(requests);
|
dispatcher_->addMessageToQueue(requests);
|
||||||
}
|
}
|
||||||
if(perSecTimer_.difference(global::wallclock) >= 1) {
|
if(perSecTimer_.difference(global::wallclock()) >= 1) {
|
||||||
perSecTimer_ = global::wallclock;
|
perSecTimer_ = global::wallclock();
|
||||||
// Drop timeout request after queuing message to give a chance
|
// Drop timeout request after queuing message to give a chance
|
||||||
// to other connection to request piece.
|
// to other connection to request piece.
|
||||||
std::vector<size_t> indexes =
|
std::vector<size_t> indexes =
|
||||||
|
@ -537,8 +537,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
||||||
checkActiveInteraction();
|
checkActiveInteraction();
|
||||||
decideChoking();
|
decideChoking();
|
||||||
detectMessageFlooding();
|
detectMessageFlooding();
|
||||||
if(perSecTimer_.difference(global::wallclock) >= 1) {
|
if(perSecTimer_.difference(global::wallclock()) >= 1) {
|
||||||
perSecTimer_ = global::wallclock;
|
perSecTimer_ = global::wallclock();
|
||||||
dispatcher_->checkRequestSlotAndDoNecessaryThing();
|
dispatcher_->checkRequestSlotAndDoNecessaryThing();
|
||||||
}
|
}
|
||||||
checkHave();
|
checkHave();
|
||||||
|
|
|
@ -246,10 +246,10 @@ TransferStat calculateStatFor(const SharedHandle<Peer>& peer)
|
||||||
TransferStat DefaultPeerStorage::calculateStat()
|
TransferStat DefaultPeerStorage::calculateStat()
|
||||||
{
|
{
|
||||||
TransferStat stat;
|
TransferStat stat;
|
||||||
if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock)+
|
if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock())+
|
||||||
A2_DELTA_MILLIS >= 250) {
|
A2_DELTA_MILLIS >= 250) {
|
||||||
A2_LOG_DEBUG("Updating TransferStat of PeerStorage");
|
A2_LOG_DEBUG("Updating TransferStat of PeerStorage");
|
||||||
lastTransferStatMapUpdated_ = global::wallclock;
|
lastTransferStatMapUpdated_ = global::wallclock();
|
||||||
peerTransferStatMap_.clear();
|
peerTransferStatMap_.clear();
|
||||||
std::vector<SharedHandle<Peer> > activePeers;
|
std::vector<SharedHandle<Peer> > activePeers;
|
||||||
getActivePeers(activePeers);
|
getActivePeers(activePeers);
|
||||||
|
@ -358,10 +358,10 @@ bool DefaultPeerStorage::chokeRoundIntervalElapsed()
|
||||||
const time_t CHOKE_ROUND_INTERVAL = 10;
|
const time_t CHOKE_ROUND_INTERVAL = 10;
|
||||||
if(pieceStorage_->downloadFinished()) {
|
if(pieceStorage_->downloadFinished()) {
|
||||||
return seederStateChoke_->getLastRound().
|
return seederStateChoke_->getLastRound().
|
||||||
difference(global::wallclock) >= CHOKE_ROUND_INTERVAL;
|
difference(global::wallclock()) >= CHOKE_ROUND_INTERVAL;
|
||||||
} else {
|
} else {
|
||||||
return leecherStateChoke_->getLastRound().
|
return leecherStateChoke_->getLastRound().
|
||||||
difference(global::wallclock) >= CHOKE_ROUND_INTERVAL;
|
difference(global::wallclock()) >= CHOKE_ROUND_INTERVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -655,7 +655,7 @@ size_t DefaultPieceStorage::getPieceLength(size_t index)
|
||||||
|
|
||||||
void DefaultPieceStorage::advertisePiece(cuid_t cuid, size_t index)
|
void DefaultPieceStorage::advertisePiece(cuid_t cuid, size_t index)
|
||||||
{
|
{
|
||||||
HaveEntry entry(cuid, index, global::wallclock);
|
HaveEntry entry(cuid, index, global::wallclock());
|
||||||
haves_.push_front(entry);
|
haves_.push_front(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ public:
|
||||||
FindElapsedHave(time_t elapsed):elapsed(elapsed) {}
|
FindElapsedHave(time_t elapsed):elapsed(elapsed) {}
|
||||||
|
|
||||||
bool operator()(const HaveEntry& have) {
|
bool operator()(const HaveEntry& have) {
|
||||||
if(have.getRegisteredTime().difference(global::wallclock) >= elapsed) {
|
if(have.getRegisteredTime().difference(global::wallclock()) >= elapsed) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -271,7 +271,7 @@ bool DownloadCommand::executeInternal() {
|
||||||
void DownloadCommand::checkLowestDownloadSpeed() const
|
void DownloadCommand::checkLowestDownloadSpeed() const
|
||||||
{
|
{
|
||||||
if(lowestDownloadSpeedLimit_ > 0 &&
|
if(lowestDownloadSpeedLimit_ > 0 &&
|
||||||
peerStat_->getDownloadStartTime().difference(global::wallclock) >=
|
peerStat_->getDownloadStartTime().difference(global::wallclock()) >=
|
||||||
startupIdleTime_) {
|
startupIdleTime_) {
|
||||||
unsigned int nowSpeed = peerStat_->calculateDownloadSpeed();
|
unsigned int nowSpeed = peerStat_->calculateDownloadSpeed();
|
||||||
if(nowSpeed <= lowestDownloadSpeedLimit_) {
|
if(nowSpeed <= lowestDownloadSpeedLimit_) {
|
||||||
|
|
|
@ -75,13 +75,13 @@ DownloadContext::~DownloadContext() {}
|
||||||
|
|
||||||
void DownloadContext::resetDownloadStartTime()
|
void DownloadContext::resetDownloadStartTime()
|
||||||
{
|
{
|
||||||
downloadStartTime_ = global::wallclock;
|
downloadStartTime_ = global::wallclock();
|
||||||
downloadStopTime_.reset(0);
|
downloadStopTime_.reset(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadContext::resetDownloadStopTime()
|
void DownloadContext::resetDownloadStopTime()
|
||||||
{
|
{
|
||||||
downloadStopTime_ = global::wallclock;
|
downloadStopTime_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t DownloadContext::calculateSessionTime() const
|
int64_t DownloadContext::calculateSessionTime() const
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
#include "BtProgressInfoFile.h"
|
#include "BtProgressInfoFile.h"
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
|
#include "wallclock.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "BtRegistry.h"
|
# include "BtRegistry.h"
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
@ -73,10 +74,6 @@ namespace aria2 {
|
||||||
|
|
||||||
namespace global {
|
namespace global {
|
||||||
|
|
||||||
// Global clock, this clock is reseted before executeCommand() call to
|
|
||||||
// reduce the call gettimeofday() system call.
|
|
||||||
Timer wallclock;
|
|
||||||
|
|
||||||
// 0 ... running
|
// 0 ... running
|
||||||
// 1 ... stop signal detected
|
// 1 ... stop signal detected
|
||||||
// 2 ... stop signal processed by DownloadEngine
|
// 2 ... stop signal processed by DownloadEngine
|
||||||
|
@ -146,12 +143,12 @@ void DownloadEngine::run()
|
||||||
Timer cp;
|
Timer cp;
|
||||||
cp.reset(0);
|
cp.reset(0);
|
||||||
while(!commands_.empty() || !routineCommands_.empty()) {
|
while(!commands_.empty() || !routineCommands_.empty()) {
|
||||||
global::wallclock.reset();
|
global::wallclock().reset();
|
||||||
calculateStatistics();
|
calculateStatistics();
|
||||||
if(cp.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS >=
|
if(cp.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS >=
|
||||||
refreshInterval_) {
|
refreshInterval_) {
|
||||||
refreshInterval_ = DEFAULT_REFRESH_INTERVAL;
|
refreshInterval_ = DEFAULT_REFRESH_INTERVAL;
|
||||||
cp = global::wallclock;
|
cp = global::wallclock();
|
||||||
executeCommand(commands_, Command::STATUS_ALL);
|
executeCommand(commands_, Command::STATUS_ALL);
|
||||||
} else {
|
} else {
|
||||||
executeCommand(commands_, Command::STATUS_ACTIVE);
|
executeCommand(commands_, Command::STATUS_ACTIVE);
|
||||||
|
@ -288,10 +285,10 @@ void DownloadEngine::poolSocket(const std::string& key,
|
||||||
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
|
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
|
||||||
socketPool_.insert(p);
|
socketPool_.insert(p);
|
||||||
|
|
||||||
if(lastSocketPoolScan_.difference(global::wallclock) >= 60) {
|
if(lastSocketPoolScan_.difference(global::wallclock()) >= 60) {
|
||||||
std::multimap<std::string, SocketPoolEntry> newPool;
|
std::multimap<std::string, SocketPoolEntry> newPool;
|
||||||
A2_LOG_DEBUG("Scaning SocketPool and erasing timed out entry.");
|
A2_LOG_DEBUG("Scaning SocketPool and erasing timed out entry.");
|
||||||
lastSocketPoolScan_ = global::wallclock;
|
lastSocketPoolScan_ = global::wallclock();
|
||||||
for(std::multimap<std::string, SocketPoolEntry>::iterator i =
|
for(std::multimap<std::string, SocketPoolEntry>::iterator i =
|
||||||
socketPool_.begin(), eoi = socketPool_.end(); i != eoi; ++i) {
|
socketPool_.begin(), eoi = socketPool_.end(); i != eoi; ++i) {
|
||||||
if(!(*i).second.isTimeout()) {
|
if(!(*i).second.isTimeout()) {
|
||||||
|
@ -497,7 +494,7 @@ DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}
|
||||||
|
|
||||||
bool DownloadEngine::SocketPoolEntry::isTimeout() const
|
bool DownloadEngine::SocketPoolEntry::isTimeout() const
|
||||||
{
|
{
|
||||||
return registeredTime_.difference(global::wallclock) >= timeout_;
|
return registeredTime_.difference(global::wallclock()) >= timeout_;
|
||||||
}
|
}
|
||||||
|
|
||||||
cuid_t DownloadEngine::newCUID()
|
cuid_t DownloadEngine::newCUID()
|
||||||
|
|
|
@ -70,7 +70,7 @@ bool FileAllocationCommand::executeInternal()
|
||||||
if(fileAllocationEntry_->finished()) {
|
if(fileAllocationEntry_->finished()) {
|
||||||
A2_LOG_DEBUG
|
A2_LOG_DEBUG
|
||||||
(fmt(MSG_ALLOCATION_COMPLETED,
|
(fmt(MSG_ALLOCATION_COMPLETED,
|
||||||
static_cast<long int>(timer_.difference(global::wallclock)),
|
static_cast<long int>(timer_.difference(global::wallclock())),
|
||||||
util::itos(getRequestGroup()->getTotalLength(), true).c_str()));
|
util::itos(getRequestGroup()->getTotalLength(), true).c_str()));
|
||||||
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
||||||
|
|
||||||
|
|
|
@ -174,13 +174,13 @@ FileEntry::getRequest
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Skip Request object if it is still
|
// Skip Request object if it is still
|
||||||
// sleeping(Request::getWakeTime() < global::wallclock). If all
|
// sleeping(Request::getWakeTime() < global::wallclock()). If all
|
||||||
// pooled objects are sleeping, return first one. Caller should
|
// pooled objects are sleeping, return first one. Caller should
|
||||||
// inspect returned object's getWakeTime().
|
// inspect returned object's getWakeTime().
|
||||||
std::deque<SharedHandle<Request> >::iterator i = requestPool_.begin();
|
std::deque<SharedHandle<Request> >::iterator i = requestPool_.begin();
|
||||||
std::deque<SharedHandle<Request> >::iterator eoi = requestPool_.end();
|
std::deque<SharedHandle<Request> >::iterator eoi = requestPool_.end();
|
||||||
for(; i != eoi; ++i) {
|
for(; i != eoi; ++i) {
|
||||||
if((*i)->getWakeTime() <= global::wallclock) {
|
if((*i)->getWakeTime() <= global::wallclock()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ FileEntry::findFasterRequest(const SharedHandle<Request>& base)
|
||||||
{
|
{
|
||||||
const int startupIdleTime = 10;
|
const int startupIdleTime = 10;
|
||||||
if(requestPool_.empty() ||
|
if(requestPool_.empty() ||
|
||||||
lastFasterReplace_.difference(global::wallclock) < startupIdleTime) {
|
lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
||||||
return SharedHandle<Request>();
|
return SharedHandle<Request>();
|
||||||
}
|
}
|
||||||
const SharedHandle<PeerStat>& fastest = requestPool_.front()->getPeerStat();
|
const SharedHandle<PeerStat>& fastest = requestPool_.front()->getPeerStat();
|
||||||
|
@ -211,13 +211,13 @@ FileEntry::findFasterRequest(const SharedHandle<Request>& base)
|
||||||
// TODO hard coded value. See PREF_STARTUP_IDLE_TIME
|
// TODO hard coded value. See PREF_STARTUP_IDLE_TIME
|
||||||
if(!basestat ||
|
if(!basestat ||
|
||||||
(basestat->getDownloadStartTime().
|
(basestat->getDownloadStartTime().
|
||||||
difference(global::wallclock) >= startupIdleTime &&
|
difference(global::wallclock()) >= startupIdleTime &&
|
||||||
fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){
|
fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){
|
||||||
// TODO we should consider that "fastest" is very slow.
|
// TODO we should consider that "fastest" is very slow.
|
||||||
SharedHandle<Request> fastestRequest = requestPool_.front();
|
SharedHandle<Request> fastestRequest = requestPool_.front();
|
||||||
requestPool_.pop_front();
|
requestPool_.pop_front();
|
||||||
inFlightRequests_.push_back(fastestRequest);
|
inFlightRequests_.push_back(fastestRequest);
|
||||||
lastFasterReplace_ = global::wallclock;
|
lastFasterReplace_ = global::wallclock();
|
||||||
return fastestRequest;
|
return fastestRequest;
|
||||||
}
|
}
|
||||||
return SharedHandle<Request>();
|
return SharedHandle<Request>();
|
||||||
|
@ -231,7 +231,7 @@ FileEntry::findFasterRequest
|
||||||
{
|
{
|
||||||
const int startupIdleTime = 10;
|
const int startupIdleTime = 10;
|
||||||
const unsigned int SPEED_THRESHOLD = 20*1024;
|
const unsigned int SPEED_THRESHOLD = 20*1024;
|
||||||
if(lastFasterReplace_.difference(global::wallclock) < startupIdleTime) {
|
if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
||||||
return SharedHandle<Request>();
|
return SharedHandle<Request>();
|
||||||
}
|
}
|
||||||
std::vector<std::string> inFlightHosts;
|
std::vector<std::string> inFlightHosts;
|
||||||
|
@ -280,7 +280,7 @@ FileEntry::findFasterRequest
|
||||||
uris_.erase(std::find(uris_.begin(), uris_.end(), uri));
|
uris_.erase(std::find(uris_.begin(), uris_.end(), uri));
|
||||||
spentUris_.push_back(uri);
|
spentUris_.push_back(uri);
|
||||||
inFlightRequests_.push_back(fastestRequest);
|
inFlightRequests_.push_back(fastestRequest);
|
||||||
lastFasterReplace_ = global::wallclock;
|
lastFasterReplace_ = global::wallclock();
|
||||||
return fastestRequest;
|
return fastestRequest;
|
||||||
}
|
}
|
||||||
A2_LOG_DEBUG("No faster server found.");
|
A2_LOG_DEBUG("No faster server found.");
|
||||||
|
|
|
@ -77,7 +77,7 @@ bool FtpFinishDownloadCommand::execute()
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(readEventEnabled() || hupEventEnabled()) {
|
if(readEventEnabled() || hupEventEnabled()) {
|
||||||
getCheckPoint() = global::wallclock;
|
getCheckPoint() = global::wallclock();
|
||||||
unsigned int status = ftpConnection_->receiveResponse();
|
unsigned int status = ftpConnection_->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
getDownloadEngine()->addCommand(this);
|
getDownloadEngine()->addCommand(this);
|
||||||
|
@ -95,7 +95,7 @@ bool FtpFinishDownloadCommand::execute()
|
||||||
A2_LOG_INFO(fmt("CUID#%lld - Bad status for transfer complete.",
|
A2_LOG_INFO(fmt("CUID#%lld - Bad status for transfer complete.",
|
||||||
getCuid()));
|
getCuid()));
|
||||||
}
|
}
|
||||||
} else if(getCheckPoint().difference(global::wallclock) >= getTimeout()) {
|
} else if(getCheckPoint().difference(global::wallclock()) >= getTimeout()) {
|
||||||
A2_LOG_INFO(fmt("CUID#%lld - Timeout before receiving transfer complete.",
|
A2_LOG_INFO(fmt("CUID#%lld - Timeout before receiving transfer complete.",
|
||||||
getCuid()));
|
getCuid()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -201,7 +201,7 @@ bool HttpServerBodyCommand::execute()
|
||||||
if(socket_->isReadable(0) ||
|
if(socket_->isReadable(0) ||
|
||||||
!httpServer_->getSocketRecvBuffer()->bufferEmpty() ||
|
!httpServer_->getSocketRecvBuffer()->bufferEmpty() ||
|
||||||
httpServer_->getContentLength() == 0) {
|
httpServer_->getContentLength() == 0) {
|
||||||
timeoutTimer_ = global::wallclock;
|
timeoutTimer_ = global::wallclock();
|
||||||
|
|
||||||
if(httpServer_->receiveBody()) {
|
if(httpServer_->receiveBody()) {
|
||||||
std::string reqPath = httpServer_->getRequestPath();
|
std::string reqPath = httpServer_->getRequestPath();
|
||||||
|
@ -280,7 +280,7 @@ bool HttpServerBodyCommand::execute()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(timeoutTimer_.difference(global::wallclock) >= 30) {
|
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
|
||||||
A2_LOG_INFO("HTTP request body timeout.");
|
A2_LOG_INFO("HTTP request body timeout.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -109,7 +109,7 @@ bool HttpServerCommand::execute()
|
||||||
try {
|
try {
|
||||||
if(socket_->isReadable(0) ||
|
if(socket_->isReadable(0) ||
|
||||||
!httpServer_->getSocketRecvBuffer()->bufferEmpty()) {
|
!httpServer_->getSocketRecvBuffer()->bufferEmpty()) {
|
||||||
timeoutTimer_ = global::wallclock;
|
timeoutTimer_ = global::wallclock();
|
||||||
SharedHandle<HttpHeader> header;
|
SharedHandle<HttpHeader> header;
|
||||||
|
|
||||||
header = httpServer_->receiveRequest();
|
header = httpServer_->receiveRequest();
|
||||||
|
@ -144,7 +144,7 @@ bool HttpServerCommand::execute()
|
||||||
e_->setNoWait(true);
|
e_->setNoWait(true);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if(timeoutTimer_.difference(global::wallclock) >= 30) {
|
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
|
||||||
A2_LOG_INFO("HTTP request timeout.");
|
A2_LOG_INFO("HTTP request timeout.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,7 +91,7 @@ bool HttpServerResponseCommand::execute()
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if(timeoutTimer_.difference(global::wallclock) >= 10) {
|
if(timeoutTimer_.difference(global::wallclock()) >= 10) {
|
||||||
A2_LOG_INFO(fmt("CUID#%lld - HttpServer: Timeout while trasmitting"
|
A2_LOG_INFO(fmt("CUID#%lld - HttpServer: Timeout while trasmitting"
|
||||||
" response.",
|
" response.",
|
||||||
getCuid()));
|
getCuid()));
|
||||||
|
|
|
@ -93,12 +93,12 @@ bool LpdMessageDispatcher::sendMessage()
|
||||||
|
|
||||||
bool LpdMessageDispatcher::isAnnounceReady() const
|
bool LpdMessageDispatcher::isAnnounceReady() const
|
||||||
{
|
{
|
||||||
return timer_.difference(global::wallclock) >= interval_;
|
return timer_.difference(global::wallclock()) >= interval_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpdMessageDispatcher::resetAnnounceTimer()
|
void LpdMessageDispatcher::resetAnnounceTimer()
|
||||||
{
|
{
|
||||||
timer_ = global::wallclock;
|
timer_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace bittorrent {
|
namespace bittorrent {
|
||||||
|
|
|
@ -194,7 +194,7 @@ SRCS = Socket.h\
|
||||||
bitfield.cc bitfield.h\
|
bitfield.cc bitfield.h\
|
||||||
CreateRequestCommand.cc CreateRequestCommand.h\
|
CreateRequestCommand.cc CreateRequestCommand.h\
|
||||||
error_code.h\
|
error_code.h\
|
||||||
wallclock.h\
|
wallclock.cc wallclock.h\
|
||||||
download_helper.cc download_helper.h\
|
download_helper.cc download_helper.h\
|
||||||
MetadataInfo.cc MetadataInfo.h\
|
MetadataInfo.cc MetadataInfo.h\
|
||||||
SessionSerializer.cc SessionSerializer.h\
|
SessionSerializer.cc SessionSerializer.h\
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace aria2 {
|
||||||
Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
|
Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
|
||||||
ipaddr_(ipaddr),
|
ipaddr_(ipaddr),
|
||||||
port_(port),
|
port_(port),
|
||||||
firstContactTime_(global::wallclock),
|
firstContactTime_(global::wallclock()),
|
||||||
badConditionStartTime_(0),
|
badConditionStartTime_(0),
|
||||||
seeder_(false),
|
seeder_(false),
|
||||||
res_(0),
|
res_(0),
|
||||||
|
@ -326,13 +326,13 @@ void Peer::setAllBitfield() {
|
||||||
|
|
||||||
void Peer::startBadCondition()
|
void Peer::startBadCondition()
|
||||||
{
|
{
|
||||||
badConditionStartTime_ = global::wallclock;
|
badConditionStartTime_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isGood() const
|
bool Peer::isGood() const
|
||||||
{
|
{
|
||||||
return badConditionStartTime_.
|
return badConditionStartTime_.
|
||||||
difference(global::wallclock) >= BAD_CONDITION_INTERVAL;
|
difference(global::wallclock()) >= BAD_CONDITION_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Peer::getExtensionMessageID(const std::string& name) const
|
uint8_t Peer::getExtensionMessageID(const std::string& name) const
|
||||||
|
|
|
@ -55,7 +55,7 @@ PeerAbstractCommand::PeerAbstractCommand
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SocketHandle& s)
|
const SocketHandle& s)
|
||||||
: Command(cuid),
|
: Command(cuid),
|
||||||
checkPoint_(global::wallclock),
|
checkPoint_(global::wallclock()),
|
||||||
// TODO referring global option
|
// TODO referring global option
|
||||||
timeout_(e->getOption()->getAsInt(PREF_BT_TIMEOUT)),
|
timeout_(e->getOption()->getAsInt(PREF_BT_TIMEOUT)),
|
||||||
e_(e),
|
e_(e),
|
||||||
|
@ -93,13 +93,13 @@ bool PeerAbstractCommand::execute()
|
||||||
(checkSocketIsReadable_ && readEventEnabled()) ||
|
(checkSocketIsReadable_ && readEventEnabled()) ||
|
||||||
(checkSocketIsWritable_ && writeEventEnabled()) ||
|
(checkSocketIsWritable_ && writeEventEnabled()) ||
|
||||||
hupEventEnabled()) {
|
hupEventEnabled()) {
|
||||||
checkPoint_ = global::wallclock;
|
checkPoint_ = global::wallclock();
|
||||||
} else if(errorEventEnabled()) {
|
} else if(errorEventEnabled()) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt(MSG_NETWORK_PROBLEM,
|
(fmt(MSG_NETWORK_PROBLEM,
|
||||||
socket_->getSocketError().c_str()));
|
socket_->getSocketError().c_str()));
|
||||||
}
|
}
|
||||||
if(checkPoint_.difference(global::wallclock) >= timeout_) {
|
if(checkPoint_.difference(global::wallclock()) >= timeout_) {
|
||||||
throw DL_ABORT_EX(EX_TIME_OUT);
|
throw DL_ABORT_EX(EX_TIME_OUT);
|
||||||
}
|
}
|
||||||
return executeInternal();
|
return executeInternal();
|
||||||
|
@ -190,7 +190,7 @@ void PeerAbstractCommand::setNoCheck(bool check)
|
||||||
|
|
||||||
void PeerAbstractCommand::updateKeepAlive()
|
void PeerAbstractCommand::updateKeepAlive()
|
||||||
{
|
{
|
||||||
checkPoint_ = global::wallclock;
|
checkPoint_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerAbstractCommand::createSocket()
|
void PeerAbstractCommand::createSocket()
|
||||||
|
|
|
@ -62,7 +62,7 @@ PeerAddrEntry& PeerAddrEntry::operator=(const PeerAddrEntry& c)
|
||||||
|
|
||||||
void PeerAddrEntry::notifyUpdate()
|
void PeerAddrEntry::notifyUpdate()
|
||||||
{
|
{
|
||||||
lastUpdated_ = global::wallclock;
|
lastUpdated_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerAddrEntry::operator==(const PeerAddrEntry& entry) const
|
bool PeerAddrEntry::operator==(const PeerAddrEntry& entry) const
|
||||||
|
|
|
@ -70,7 +70,7 @@ void PeerSessionResource::amChoking(bool b)
|
||||||
{
|
{
|
||||||
amChoking_ = b;
|
amChoking_ = b;
|
||||||
if(!b) {
|
if(!b) {
|
||||||
lastAmUnchoking_ = global::wallclock;
|
lastAmUnchoking_ = global::wallclock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ void PeerSessionResource::updateDownloadLength(size_t bytes)
|
||||||
{
|
{
|
||||||
peerStat_.updateDownloadLength(bytes);
|
peerStat_.updateDownloadLength(bytes);
|
||||||
|
|
||||||
lastDownloadUpdate_ = global::wallclock;
|
lastDownloadUpdate_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t PeerSessionResource::getCompletedLength() const
|
uint64_t PeerSessionResource::getCompletedLength() const
|
||||||
|
|
|
@ -43,7 +43,7 @@ PeerStat::PeerStat
|
||||||
: cuid_(cuid),
|
: cuid_(cuid),
|
||||||
hostname_(hostname),
|
hostname_(hostname),
|
||||||
protocol_(protocol),
|
protocol_(protocol),
|
||||||
downloadStartTime_(global::wallclock),
|
downloadStartTime_(global::wallclock()),
|
||||||
status_(PeerStat::IDLE),
|
status_(PeerStat::IDLE),
|
||||||
avgDownloadSpeed_(0),
|
avgDownloadSpeed_(0),
|
||||||
avgUploadSpeed_(0),
|
avgUploadSpeed_(0),
|
||||||
|
@ -113,7 +113,7 @@ void PeerStat::reset()
|
||||||
{
|
{
|
||||||
downloadSpeed_.reset();
|
downloadSpeed_.reset();
|
||||||
uploadSpeed_.reset();
|
uploadSpeed_.reset();
|
||||||
downloadStartTime_ = global::wallclock;
|
downloadStartTime_ = global::wallclock();
|
||||||
status_ = PeerStat::IDLE;
|
status_ = PeerStat::IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ Request::Request():
|
||||||
ipv6LiteralAddress_(false),
|
ipv6LiteralAddress_(false),
|
||||||
removalRequested_(false),
|
removalRequested_(false),
|
||||||
connectedPort_(0),
|
connectedPort_(0),
|
||||||
wakeTime_(global::wallclock)
|
wakeTime_(global::wallclock())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Request::~Request() {}
|
Request::~Request() {}
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "RequestSlot.h"
|
#include "RequestSlot.h"
|
||||||
#include "wallclock.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ void RequestSlot::setDispatchedTime(time_t sec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestSlot::isTimeout(time_t timeoutSec) const {
|
bool RequestSlot::isTimeout(time_t timeoutSec) const {
|
||||||
return dispatchedTime_.difference(global::wallclock) >= timeoutSec;
|
return dispatchedTime_.difference(global::wallclock()) >= timeoutSec;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestSlot::isNull(const RequestSlot& requestSlot) {
|
bool RequestSlot::isNull(const RequestSlot& requestSlot) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
|
|
||||||
RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex,
|
RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex,
|
||||||
const SharedHandle<Piece>& piece = SharedHandle<Piece>()):
|
const SharedHandle<Piece>& piece = SharedHandle<Piece>()):
|
||||||
dispatchedTime_(global::wallclock),
|
dispatchedTime_(global::wallclock()),
|
||||||
index_(index), begin_(begin), length_(length), blockIndex_(blockIndex),
|
index_(index), begin_(begin), length_(length), blockIndex_(blockIndex),
|
||||||
piece_(piece) {}
|
piece_(piece) {}
|
||||||
|
|
||||||
|
|
|
@ -409,9 +409,9 @@ void SegmentMan::updateFastestPeerStat(const SharedHandle<PeerStat>& peerStat)
|
||||||
unsigned int SegmentMan::calculateDownloadSpeed()
|
unsigned int SegmentMan::calculateDownloadSpeed()
|
||||||
{
|
{
|
||||||
unsigned int speed = 0;
|
unsigned int speed = 0;
|
||||||
if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock)+
|
if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock())+
|
||||||
A2_DELTA_MILLIS >= 250){
|
A2_DELTA_MILLIS >= 250){
|
||||||
lastPeerStatDlspdMapUpdated_ = global::wallclock;
|
lastPeerStatDlspdMapUpdated_ = global::wallclock();
|
||||||
peerStatDlspdMap_.clear();
|
peerStatDlspdMap_.clear();
|
||||||
for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
|
for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
|
||||||
peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
|
peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ SleepCommand::SleepCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
Command* nextCommand, time_t wait):
|
Command* nextCommand, time_t wait):
|
||||||
Command(cuid), engine_(e), requestGroup_(requestGroup),
|
Command(cuid), engine_(e), requestGroup_(requestGroup),
|
||||||
nextCommand_(nextCommand), wait_(wait), checkPoint_(global::wallclock) {}
|
nextCommand_(nextCommand), wait_(wait), checkPoint_(global::wallclock()) {}
|
||||||
|
|
||||||
SleepCommand::~SleepCommand() {
|
SleepCommand::~SleepCommand() {
|
||||||
delete nextCommand_;
|
delete nextCommand_;
|
||||||
|
@ -52,7 +52,7 @@ SleepCommand::~SleepCommand() {
|
||||||
bool SleepCommand::execute() {
|
bool SleepCommand::execute() {
|
||||||
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
|
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
|
||||||
return true;
|
return true;
|
||||||
} else if(checkPoint_.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS
|
} else if(checkPoint_.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS
|
||||||
>= wait_*1000) {
|
>= wait_*1000) {
|
||||||
engine_->addCommand(nextCommand_);
|
engine_->addCommand(nextCommand_);
|
||||||
nextCommand_ = 0;
|
nextCommand_ = 0;
|
||||||
|
|
|
@ -52,17 +52,17 @@ SpeedCalc::SpeedCalc():sw_(0), maxSpeed_(0), prevSpeed_(0),
|
||||||
|
|
||||||
void SpeedCalc::reset() {
|
void SpeedCalc::reset() {
|
||||||
std::fill(&lengthArray_[0], &lengthArray_[2], 0);
|
std::fill(&lengthArray_[0], &lengthArray_[2], 0);
|
||||||
std::fill(&cpArray_[0], &cpArray_[2], global::wallclock);
|
std::fill(&cpArray_[0], &cpArray_[2], global::wallclock());
|
||||||
sw_ = 0;
|
sw_ = 0;
|
||||||
maxSpeed_ = 0;
|
maxSpeed_ = 0;
|
||||||
prevSpeed_ = 0;
|
prevSpeed_ = 0;
|
||||||
start_ = global::wallclock;
|
start_ = global::wallclock();
|
||||||
accumulatedLength_ = 0;
|
accumulatedLength_ = 0;
|
||||||
nextInterval_ = CHANGE_INTERVAL_SEC;
|
nextInterval_ = CHANGE_INTERVAL_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SpeedCalc::calculateSpeed() {
|
unsigned int SpeedCalc::calculateSpeed() {
|
||||||
int64_t milliElapsed = cpArray_[sw_].differenceInMillis(global::wallclock);
|
int64_t milliElapsed = cpArray_[sw_].differenceInMillis(global::wallclock());
|
||||||
if(milliElapsed) {
|
if(milliElapsed) {
|
||||||
unsigned int speed = lengthArray_[sw_]*1000/milliElapsed;
|
unsigned int speed = lengthArray_[sw_]*1000/milliElapsed;
|
||||||
prevSpeed_ = speed;
|
prevSpeed_ = speed;
|
||||||
|
@ -86,7 +86,7 @@ void SpeedCalc::update(size_t bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpeedCalc::isIntervalOver() const {
|
bool SpeedCalc::isIntervalOver() const {
|
||||||
return nextInterval_ <= cpArray_[sw_].difference(global::wallclock);
|
return nextInterval_ <= cpArray_[sw_].difference(global::wallclock());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
|
bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
|
||||||
|
@ -96,14 +96,14 @@ bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
|
||||||
|
|
||||||
void SpeedCalc::changeSw() {
|
void SpeedCalc::changeSw() {
|
||||||
lengthArray_[sw_] = 0;
|
lengthArray_[sw_] = 0;
|
||||||
cpArray_[sw_] = global::wallclock;
|
cpArray_[sw_] = global::wallclock();
|
||||||
sw_ ^= 0x01u;
|
sw_ ^= 0x01u;
|
||||||
nextInterval_ =
|
nextInterval_ =
|
||||||
cpArray_[sw_].difference(global::wallclock)+CHANGE_INTERVAL_SEC;
|
cpArray_[sw_].difference(global::wallclock())+CHANGE_INTERVAL_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SpeedCalc::calculateAvgSpeed() const {
|
unsigned int SpeedCalc::calculateAvgSpeed() const {
|
||||||
uint64_t milliElapsed = start_.differenceInMillis(global::wallclock);
|
uint64_t milliElapsed = start_.differenceInMillis(global::wallclock());
|
||||||
|
|
||||||
// if milliElapsed is too small, the average speed is rubish, better return 0
|
// if milliElapsed is too small, the average speed is rubish, better return 0
|
||||||
if(milliElapsed > 4) {
|
if(milliElapsed > 4) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ TimeBasedCommand::TimeBasedCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
time_t interval,
|
time_t interval,
|
||||||
bool routineCommand):
|
bool routineCommand):
|
||||||
Command(cuid), e_(e),exit_(false), interval_(interval),
|
Command(cuid), e_(e),exit_(false), interval_(interval),
|
||||||
routineCommand_(routineCommand), checkPoint_(global::wallclock) {}
|
routineCommand_(routineCommand), checkPoint_(global::wallclock()) {}
|
||||||
|
|
||||||
TimeBasedCommand::~TimeBasedCommand() {}
|
TimeBasedCommand::~TimeBasedCommand() {}
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ bool TimeBasedCommand::execute()
|
||||||
if(exit_) {
|
if(exit_) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(checkPoint_.difference(global::wallclock) >= interval_) {
|
if(checkPoint_.difference(global::wallclock()) >= interval_) {
|
||||||
checkPoint_ = global::wallclock;
|
checkPoint_ = global::wallclock();
|
||||||
process();
|
process();
|
||||||
if(exit_) {
|
if(exit_) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -43,12 +43,12 @@ TimeSeedCriteria::~TimeSeedCriteria() {}
|
||||||
|
|
||||||
void TimeSeedCriteria::reset()
|
void TimeSeedCriteria::reset()
|
||||||
{
|
{
|
||||||
watch_ = global::wallclock;
|
watch_ = global::wallclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimeSeedCriteria::evaluate()
|
bool TimeSeedCriteria::evaluate()
|
||||||
{
|
{
|
||||||
return watch_.difference(global::wallclock) >= duration_;
|
return watch_.difference(global::wallclock()) >= duration_;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -54,7 +54,7 @@ private:
|
||||||
|
|
||||||
bool elapsed(time_t t) const
|
bool elapsed(time_t t) const
|
||||||
{
|
{
|
||||||
return dispatchedTime_.difference(global::wallclock) >= t;
|
return dispatchedTime_.difference(global::wallclock()) >= t;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const RequestEntry& e) const
|
bool operator==(const RequestEntry& e) const
|
||||||
|
|
|
@ -134,7 +134,7 @@ void UTPexExtensionMessage::doReceivedAction()
|
||||||
bool UTPexExtensionMessage::addFreshPeer(const SharedHandle<Peer>& peer)
|
bool UTPexExtensionMessage::addFreshPeer(const SharedHandle<Peer>& peer)
|
||||||
{
|
{
|
||||||
if(!peer->isIncomingPeer() &&
|
if(!peer->isIncomingPeer() &&
|
||||||
peer->getFirstContactTime().difference(global::wallclock) < interval_) {
|
peer->getFirstContactTime().difference(global::wallclock()) < interval_) {
|
||||||
freshPeers_.push_back(peer);
|
freshPeers_.push_back(peer);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,7 +151,7 @@ bool UTPexExtensionMessage::addDroppedPeer(const SharedHandle<Peer>& peer)
|
||||||
{
|
{
|
||||||
if(!peer->isIncomingPeer() &&
|
if(!peer->isIncomingPeer() &&
|
||||||
peer->getBadConditionStartTime().
|
peer->getBadConditionStartTime().
|
||||||
difference(global::wallclock) < interval_) {
|
difference(global::wallclock()) < interval_) {
|
||||||
droppedPeers_.push_back(peer);
|
droppedPeers_.push_back(peer);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* <!-- copyright */
|
||||||
|
/*
|
||||||
|
* aria2 - The high speed download utility
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give
|
||||||
|
* permission to link the code of portions of this program with the
|
||||||
|
* OpenSSL library under certain conditions as described in each
|
||||||
|
* individual source file, and distribute linked combinations
|
||||||
|
* including the two.
|
||||||
|
* You must obey the GNU General Public License in all respects
|
||||||
|
* for all of the code used other than OpenSSL. If you modify
|
||||||
|
* file(s) with this exception, you may extend this exception to your
|
||||||
|
* version of the file(s), but you are not obligated to do so. If you
|
||||||
|
* do not wish to do so, delete this exception statement from your
|
||||||
|
* version. If you delete this exception statement from all source
|
||||||
|
* files in the program, then also delete it here.
|
||||||
|
*/
|
||||||
|
/* copyright --> */
|
||||||
|
#include "wallclock.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
namespace global {
|
||||||
|
|
||||||
|
Timer& wallclock()
|
||||||
|
{
|
||||||
|
static Timer* t = new Timer();
|
||||||
|
return *t;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace global
|
||||||
|
|
||||||
|
} // namespace aria2
|
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
* aria2 - The high speed download utility
|
* aria2 - The high speed download utility
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
* Copyright (C) 2011 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -38,8 +38,9 @@ namespace aria2 {
|
||||||
|
|
||||||
namespace global {
|
namespace global {
|
||||||
|
|
||||||
// wallclock is defined in DownloadEngine.cc
|
// Global clock, this clock is reseted before executeCommand() call to
|
||||||
extern Timer wallclock;
|
// reduce the call gettimeofday() system call.
|
||||||
|
Timer& wallclock();
|
||||||
|
|
||||||
} // namespace global
|
} // namespace global
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TimeSeedCriteriaTest);
|
||||||
|
|
||||||
void TimeSeedCriteriaTest::testEvaluate() {
|
void TimeSeedCriteriaTest::testEvaluate() {
|
||||||
TimeSeedCriteria cri(1);
|
TimeSeedCriteria cri(1);
|
||||||
global::wallclock.reset();
|
global::wallclock().reset();
|
||||||
global::wallclock.advance(2);
|
global::wallclock().advance(2);
|
||||||
CPPUNIT_ASSERT(cri.evaluate());
|
CPPUNIT_ASSERT(cri.evaluate());
|
||||||
cri.reset();
|
cri.reset();
|
||||||
cri.setDuration(10);
|
cri.setDuration(10);
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
void setUp()
|
void setUp()
|
||||||
{
|
{
|
||||||
peerStorage_.reset(new MockPeerStorage());
|
peerStorage_.reset(new MockPeerStorage());
|
||||||
global::wallclock.reset();
|
global::wallclock().reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testGetExtensionMessageID();
|
void testGetExtensionMessageID();
|
||||||
|
|
Loading…
Reference in New Issue