2010-04-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use clock_gettime(CLOCK_MONOTONIC, ...) if it is available and
	usable to prevent from aria2 from being affected by system time
	change.
pull/1/head
Tatsuhiro Tsujikawa 2010-04-11 08:28:22 +00:00
parent bf0cf1f5d9
commit 0529e78187
78 changed files with 550 additions and 207 deletions

View File

@ -1,3 +1,9 @@
2010-04-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use clock_gettime(CLOCK_MONOTONIC, ...) if it is available and
usable to prevent from aria2 from being affected by system time
change.
2010-04-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added aria2.pause and aria2.unpause XML-RPC method. aria2.pause

View File

@ -81,6 +81,9 @@
the CoreFoundation framework. */
#undef HAVE_CFPREFERENCESCOPYAPPVALUE
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME
/* Define to 1 if you have the `daemon' function. */
#undef HAVE_DAEMON
@ -418,6 +421,9 @@
/* Define to 1 if you have the `strtoull' function. */
#undef HAVE_STRTOULL
/* Define to 1 if the system has the type `struct timespec'. */
#undef HAVE_STRUCT_TIMESPEC
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H

67
configure vendored
View File

@ -7431,6 +7431,63 @@ else
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing clock_gettime" >&5
$as_echo_n "checking for library containing clock_gettime... " >&6; }
if test "${ac_cv_search_clock_gettime+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char clock_gettime ();
int
main ()
{
return clock_gettime ();
;
return 0;
}
_ACEOF
for ac_lib in '' rt; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_cxx_try_link "$LINENO"; then :
ac_cv_search_clock_gettime=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if test "${ac_cv_search_clock_gettime+set}" = set; then :
break
fi
done
if test "${ac_cv_search_clock_gettime+set}" = set; then :
else
ac_cv_search_clock_gettime=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clock_gettime" >&5
$as_echo "$ac_cv_search_clock_gettime" >&6; }
ac_res=$ac_cv_search_clock_gettime
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
fi
# Checks for header files.
# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
# for constant arguments. Useless!
@ -8295,6 +8352,15 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
fi
ac_fn_cxx_check_type "$LINENO" "struct timespec" "ac_cv_type_struct_timespec" "$ac_includes_default"
if test "x$ac_cv_type_struct_timespec" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_TIMESPEC 1
_ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
@ -14496,6 +14562,7 @@ for ac_func in __argz_count \
__argz_next \
__argz_stringify \
atexit \
clock_gettime \
ftruncate \
getcwd \
gethostbyaddr \

View File

@ -208,6 +208,8 @@ AM_CONDITIONAL([HAVE_LIBZ], [test "x$have_libz" = "xyes"])
# Set conditional for sqlite3
AM_CONDITIONAL([HAVE_SQLITE3], [test "x$have_sqlite3" = "xyes"])
AC_SEARCH_LIBS([clock_gettime], [rt])
# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC
@ -268,7 +270,7 @@ AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_TYPE_PID_T
AC_C_VOLATILE
AC_CHECK_TYPES([ptrdiff_t])
AC_CHECK_TYPES([ptrdiff_t, struct timespec])
AC_C_BIGENDIAN
AC_SYS_LARGEFILE
@ -291,6 +293,7 @@ AC_CHECK_FUNCS([__argz_count \
__argz_next \
__argz_stringify \
atexit \
clock_gettime \
ftruncate \
getcwd \
gethostbyaddr \

View File

@ -75,7 +75,7 @@ AbstractCommand::AbstractCommand(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
const SocketHandle& s):
Command(cuid), _requestGroup(requestGroup),
Command(cuid), checkPoint(global::wallclock), _requestGroup(requestGroup),
req(req), _fileEntry(fileEntry), e(e), socket(s),
checkSocketIsReadable(false), checkSocketIsWritable(false),
nameResolverCheck(false)

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "FileEntry.h"
#include "RequestGroup.h"
@ -55,7 +55,7 @@ class AsyncNameResolver;
class AbstractCommand : public Command {
private:
Time checkPoint;
Timer checkPoint;
time_t timeout;
protected:
RequestGroup* _requestGroup;

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -59,7 +59,7 @@ private:
time_t interval; // UNIT: sec
DownloadEngine* e;
Time checkPoint;
Timer checkPoint;
unsigned int _numNewConnection; // the number of the connection to establish.
public:
ActivePeerConnectionCommand(cuid_t cuid,

View File

@ -51,7 +51,6 @@
#include "SimpleRandomizer.h"
#include "SocketCore.h"
#include "FileEntry.h"
#include "wallclock.h"
namespace aria2 {
@ -330,7 +329,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
power = (int)pow(2.0, (float)counter);
/* We test the mirror another time if it has not been
* tested since 2^counter days */
if(ss->getLastUpdated().difference(global::wallclock) > power*24*60*60) {
if(ss->getLastUpdated().difference() > power*24*60*60) {
return *i;
}
}

View File

@ -39,7 +39,6 @@
#include "Peer.h"
#include "Logger.h"
#include "LogFactory.h"
#include "a2time.h"
#include "SimpleRandomizer.h"
#include "wallclock.h"
@ -216,7 +215,7 @@ BtLeecherStateChoke::executeChoke
}
}
const Time& BtLeecherStateChoke::getLastRound() const
const Timer& BtLeecherStateChoke::getLastRound() const
{
return _lastRound;
}

View File

@ -40,7 +40,7 @@
#include <vector>
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -51,7 +51,7 @@ class BtLeecherStateChoke {
private:
int _round;
Time _lastRound;
Timer _lastRound;
Logger* _logger;
@ -95,7 +95,7 @@ public:
void executeChoke(const std::vector<SharedHandle<Peer> >& peerSet);
const Time& getLastRound() const;
const Timer& getLastRound() const;
};
} // namespace aria2

View File

@ -69,7 +69,7 @@ BtSeederStateChoke::PeerEntry::operator<(const PeerEntry& rhs) const
return false;
}
if(this->_recentUnchoking &&
this->_lastAmUnchoking.isNewer(rhs._lastAmUnchoking)) {
(this->_lastAmUnchoking > rhs._lastAmUnchoking)) {
return true;
} else if(rhs._recentUnchoking) {
return false;

View File

@ -40,7 +40,7 @@
#include <vector>
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -51,7 +51,7 @@ class BtSeederStateChoke {
private:
int _round;
Time _lastRound;
Timer _lastRound;
Logger* _logger;
@ -59,7 +59,7 @@ private:
private:
SharedHandle<Peer> _peer;
size_t _outstandingUpload;
Time _lastAmUnchoking;
Timer _lastAmUnchoking;
bool _recentUnchoking;
unsigned int _uploadSpeed;
@ -87,7 +87,7 @@ public:
void executeChoke(const std::vector<SharedHandle<Peer> >& peerSet);
const Time& getLastRound() const { return _lastRound; }
const Timer& getLastRound() const { return _lastRound; }
};
} // namespace aria2

View File

@ -52,7 +52,7 @@ private:
time_t _timeout;
Time _checkPoint;
Timer _checkPoint;
SharedHandle<BtRuntime> _btRuntime;

View File

@ -37,7 +37,6 @@
#include "RealtimeCommand.h"
#include "SharedHandle.h"
#include "TimeA2.h"
namespace aria2 {
@ -46,7 +45,6 @@ class CheckIntegrityEntry;
class CheckIntegrityCommand : public RealtimeCommand {
private:
SharedHandle<CheckIntegrityEntry> _entry;
Time _timer;
public:
CheckIntegrityCommand(cuid_t cuid,
RequestGroup* requestGroup,

View File

@ -36,7 +36,7 @@
#define _D_CONSOLE_STAT_CALC_H_
#include "StatCalc.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "util.h"
namespace aria2 {
@ -72,9 +72,9 @@ protected:
class ConsoleStatCalc:public StatCalc
{
private:
Time _cp;
Timer _cp;
Time _lastSummaryNotified;
Timer _lastSummaryNotified;
time_t _summaryInterval;

View File

@ -43,7 +43,7 @@
#include "SharedHandle.h"
#include "DHTConstants.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -68,7 +68,7 @@ private:
// This is sorted by last time seen.
std::deque<SharedHandle<DHTNode> > _cachedNodes;
Time _lastUpdated;
Timer _lastUpdated;
Logger* _logger;

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -72,7 +72,7 @@ private:
size_t _numRetry;
Time _lastGetPeerTime;
Timer _lastGetPeerTime;
public:
DHTGetPeersCommand(cuid_t cuid, RequestGroup* requestGroup,
DownloadEngine* e);

View File

@ -38,7 +38,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "DHTConstants.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include <string>
namespace aria2 {
@ -57,7 +57,7 @@ private:
SharedHandle<DHTMessageCallback> _callback;
Time _dispatchedTime;
Timer _dispatchedTime;
time_t _timeout;
public:

View File

@ -38,7 +38,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "DHTConstants.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include <string>
namespace aria2 {
@ -56,7 +56,7 @@ private:
unsigned int _condition;
Time _lastContact;
Timer _lastContact;
public:
DHTNode();

View File

@ -42,7 +42,7 @@
#include "SharedHandle.h"
#include "DHTConstants.h"
#include "PeerAddrEntry.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -54,7 +54,7 @@ private:
std::vector<PeerAddrEntry> _peerAddrEntries;
Time _lastUpdated;
Timer _lastUpdated;
public:
DHTPeerAnnounceEntry(const unsigned char* infoHash);
@ -75,7 +75,7 @@ public:
bool empty() const;
const Time& getLastUpdated() const
const Timer& getLastUpdated() const
{
return _lastUpdated;
}

View File

@ -46,6 +46,7 @@
#include "a2netcompat.h"
#include "StringFormat.h"
#include "util.h"
#include "TimeA2.h"
namespace aria2 {

View File

@ -192,7 +192,7 @@ void DHTSetup::setup(std::vector<Command*>& commands, DownloadEngine* e)
}
if(!desnodes.empty() &&
deserializer.getSerializedTime().
difference(global::wallclock) >= DHT_BUCKET_REFRESH_INTERVAL) {
difference() >= DHT_BUCKET_REFRESH_INTERVAL) {
SharedHandle<DHTBucketRefreshTask> task
(dynamic_pointer_cast<DHTBucketRefreshTask>(taskFactory->createBucketRefreshTask()));
task->setForceRefresh(true);

View File

@ -61,6 +61,7 @@ DefaultBtAnnounce::DefaultBtAnnounce
const Option* option):
_downloadContext(downloadContext),
trackers(0),
prevAnnounceTimer(0),
interval(DEFAULT_ANNOUNCE_INTERVAL),
minInterval(DEFAULT_ANNOUNCE_INTERVAL),
_userDefinedInterval(0),
@ -70,9 +71,7 @@ DefaultBtAnnounce::DefaultBtAnnounce
option(option),
logger(LogFactory::getInstance()),
_randomizer(SimpleRandomizer::getInstance())
{
prevAnnounceTime.setTimeInSec(0);
}
{}
DefaultBtAnnounce::~DefaultBtAnnounce() {
}
@ -80,7 +79,7 @@ DefaultBtAnnounce::~DefaultBtAnnounce() {
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
return
(trackers == 0 &&
prevAnnounceTime.
prevAnnounceTimer.
difference(global::wallclock) >= (_userDefinedInterval==0?
minInterval:_userDefinedInterval) &&
!announceList.allTiersFailed());
@ -207,7 +206,7 @@ bool DefaultBtAnnounce::isAllAnnounceFailed() {
}
void DefaultBtAnnounce::resetAnnounce() {
prevAnnounceTime = global::wallclock;
prevAnnounceTimer = global::wallclock;
announceList.resetTier();
}

View File

@ -36,7 +36,7 @@
#define _D_DEFAULT_BT_ANNOUNCE_H_
#include "BtAnnounce.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "AnnounceList.h"
namespace aria2 {
@ -53,7 +53,7 @@ class DefaultBtAnnounce : public BtAnnounce {
private:
SharedHandle<DownloadContext> _downloadContext;
unsigned int trackers;
Time prevAnnounceTime;
Timer prevAnnounceTimer;
time_t interval;
time_t minInterval;
time_t _userDefinedInterval;

View File

@ -163,11 +163,11 @@ BtMessageHandle DefaultBtInteractive::receiveAndSendHandshake() {
}
void DefaultBtInteractive::doPostHandshakeProcessing() {
// Set time 0 to haveCheckPoint to cache http/ftp download piece completion
haveCheckPoint.setTimeInSec(0);
keepAliveCheckPoint = global::wallclock;
floodingCheckPoint = global::wallclock;
_pexCheckPoint.setTimeInSec(0);
// Set time 0 to haveTimer to cache http/ftp download piece completion
haveTimer.reset(0);
keepAliveTimer = global::wallclock;
floodingTimer = global::wallclock;
_pexTimer.reset(0);
if(peer->isExtendedMessagingEnabled()) {
addHandshakeExtendedMessageToQueue();
}
@ -249,8 +249,8 @@ void DefaultBtInteractive::decideChoking() {
void DefaultBtInteractive::checkHave() {
std::vector<size_t> indexes;
_pieceStorage->getAdvertisedPieceIndexes(indexes, cuid, haveCheckPoint);
haveCheckPoint = global::wallclock;
_pieceStorage->getAdvertisedPieceIndexes(indexes, cuid, haveTimer);
haveTimer = global::wallclock;
if(indexes.size() >= 20) {
if(peer->isFastExtensionEnabled() && _pieceStorage->allDownloadFinished()) {
dispatcher->addMessageToQueue(messageFactory->createHaveAllMessage());
@ -266,10 +266,10 @@ void DefaultBtInteractive::checkHave() {
}
void DefaultBtInteractive::sendKeepAlive() {
if(keepAliveCheckPoint.difference(global::wallclock) >= keepAliveInterval) {
if(keepAliveTimer.difference(global::wallclock) >= keepAliveInterval) {
dispatcher->addMessageToQueue(messageFactory->createKeepAliveMessage());
dispatcher->sendMessages();
keepAliveCheckPoint = global::wallclock;
keepAliveTimer = global::wallclock;
}
}
@ -311,7 +311,7 @@ size_t DefaultBtInteractive::receiveMessages() {
_peerStorage->updateTransferStatFor(peer);
// pass through
case BtRequestMessage::ID:
inactiveCheckPoint = global::wallclock;
inactiveTimer = global::wallclock;
break;
}
}
@ -422,7 +422,7 @@ void DefaultBtInteractive::sendPendingMessage() {
}
void DefaultBtInteractive::detectMessageFlooding() {
if(floodingCheckPoint.
if(floodingTimer.
difference(global::wallclock) >= FLOODING_CHECK_INTERVAL) {
if(floodingStat.getChokeUnchokeCount() >= 2 ||
floodingStat.getKeepAliveCount() >= 2) {
@ -430,13 +430,13 @@ void DefaultBtInteractive::detectMessageFlooding() {
} else {
floodingStat.reset();
}
floodingCheckPoint = global::wallclock;
floodingTimer = global::wallclock;
}
}
void DefaultBtInteractive::checkActiveInteraction()
{
time_t inactiveTime = inactiveCheckPoint.difference(global::wallclock);
time_t inactiveTime = inactiveTimer.difference(global::wallclock);
// To allow aria2 to accept mutially interested peer, disconnect unintersted
// peer.
{
@ -463,7 +463,7 @@ void DefaultBtInteractive::checkActiveInteraction()
void DefaultBtInteractive::addPeerExchangeMessage()
{
if(_pexCheckPoint.
if(_pexTimer.
difference(global::wallclock) >= UTPexExtensionMessage::DEFAULT_INTERVAL) {
UTPexExtensionMessageHandle m
(new UTPexExtensionMessage(peer->getExtensionMessageID("ut_pex")));
@ -489,7 +489,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
}
BtMessageHandle msg = messageFactory->createBtExtendedMessage(m);
dispatcher->addMessageToQueue(msg);
_pexCheckPoint = global::wallclock;
_pexTimer = global::wallclock;
}
}
@ -510,8 +510,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
_utMetadataRequestFactory->create(requests, num, _pieceStorage);
dispatcher->addMessageToQueue(requests);
}
if(_perSecCheckPoint.difference(global::wallclock) >= 1) {
_perSecCheckPoint = global::wallclock;
if(_perSecTimer.difference(global::wallclock) >= 1) {
_perSecTimer = global::wallclock;
// Drop timeout request after queuing message to give a chance
// to other connection to request piece.
std::vector<size_t> indexes =
@ -533,8 +533,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
detectMessageFlooding();
if(_perSecCheckPoint.difference(global::wallclock) >= 1) {
_perSecCheckPoint = global::wallclock;
if(_perSecTimer.difference(global::wallclock) >= 1) {
_perSecTimer = global::wallclock;
dispatcher->checkRequestSlotAndDoNecessaryThing();
}
checkHave();

View File

@ -39,7 +39,7 @@
#include <limits.h>
#include "TimeA2.h"
#include "TimerA2.h"
#include "Command.h"
namespace aria2 {
@ -126,13 +126,13 @@ private:
Logger* logger;
size_t allowedFastSetSize;
Time haveCheckPoint;
Time keepAliveCheckPoint;
Time floodingCheckPoint;
Timer haveTimer;
Timer keepAliveTimer;
Timer floodingTimer;
FloodingStat floodingStat;
Time inactiveCheckPoint;
Time _pexCheckPoint;
Time _perSecCheckPoint;
Timer inactiveTimer;
Timer _pexTimer;
Timer _perSecTimer;
time_t keepAliveInterval;
bool _utPexEnabled;
bool _dhtEnabled;

View File

@ -39,7 +39,6 @@
#include "LogFactory.h"
#include "Logger.h"
#include "message.h"
#include "a2time.h"
#include "Peer.h"
#include "BtRuntime.h"
#include "BtSeederStateChoke.h"

View File

@ -39,7 +39,7 @@
#include <map>
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -65,7 +65,7 @@ private:
std::map<std::string, TransferStat> _peerTransferStatMap;
Time _lastTransferStatMapUpdated;
Timer _lastTransferStatMapUpdated;
TransferStat _cachedTransferStat;

View File

@ -537,14 +537,14 @@ size_t DefaultPieceStorage::getPieceLength(size_t index)
void DefaultPieceStorage::advertisePiece(cuid_t cuid, size_t index)
{
HaveEntry entry(cuid, index);
HaveEntry entry(cuid, index, global::wallclock);
haves.push_front(entry);
}
void
DefaultPieceStorage::getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
cuid_t myCuid,
const Time& lastCheckTime)
const Timer& lastCheckTime)
{
for(std::deque<HaveEntry>::const_iterator itr = haves.begin(),
eoi = haves.end(); itr != eoi; ++itr) {
@ -552,7 +552,7 @@ DefaultPieceStorage::getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
if(have.getCuid() == myCuid) {
continue;
}
if(lastCheckTime.isNewer(have.getRegisteredTime())) {
if(lastCheckTime > have.getRegisteredTime()) {
break;
}
indexes.push_back(have.getIndex());

View File

@ -56,17 +56,18 @@ class HaveEntry {
private:
cuid_t cuid;
size_t index;
Time registeredTime;
Timer registeredTime;
public:
HaveEntry(cuid_t cuid, size_t index):
HaveEntry(cuid_t cuid, size_t index, const Timer& registeredTime):
cuid(cuid),
index(index) {}
index(index),
registeredTime(registeredTime) {}
cuid_t getCuid() const { return cuid; }
size_t getIndex() const { return index; }
const Time& getRegisteredTime() const { return registeredTime; }
const Timer& getRegisteredTime() const { return registeredTime; }
};
class DefaultPieceStorage : public PieceStorage {
@ -195,7 +196,7 @@ public:
virtual void
getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
cuid_t myCuid, const Time& lastCheckTime);
cuid_t myCuid, const Timer& lastCheckTime);
virtual void removeAdvertisedPiece(time_t elapsed);

View File

@ -69,7 +69,7 @@ DownloadContext::DownloadContext(size_t pieceLength,
void DownloadContext::resetDownloadStartTime()
{
_downloadStartTime = global::wallclock;
_downloadStopTime.setTimeInSec(0);
_downloadStopTime.reset(0);
}
void DownloadContext::resetDownloadStopTime()
@ -79,9 +79,9 @@ void DownloadContext::resetDownloadStopTime()
int64_t DownloadContext::calculateSessionTime() const
{
if(_downloadStopTime.isNewer(_downloadStartTime)) {
if(_downloadStopTime > _downloadStartTime) {
return
_downloadStopTime.getTimeInMillis()-_downloadStartTime.getTimeInMillis();
_downloadStartTime.differenceInMillis(_downloadStopTime);
} else {
return 0;
}

View File

@ -43,7 +43,7 @@
#include "SharedHandle.h"
#include "Signature.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "A2STR.h"
#include "BDE.h"
#include "IntSequence.h"
@ -78,9 +78,9 @@ private:
BDE _attrs;
Time _downloadStartTime;
Timer _downloadStartTime;
Time _downloadStopTime;
Timer _downloadStopTime;
SharedHandle<Signature> _signature;
@ -233,7 +233,7 @@ public:
void resetDownloadStopTime();
const Time& getDownloadStopTime() const
const Timer& getDownloadStopTime() const
{
return _downloadStopTime;
}

View File

@ -48,8 +48,6 @@
#include "StatCalc.h"
#include "LogFactory.h"
#include "Logger.h"
#include "TimeA2.h"
#include "a2time.h"
#include "Socket.h"
#include "util.h"
#include "a2functional.h"
@ -80,7 +78,7 @@ namespace global {
// Global clock, this clock is reseted before executeCommand() call to
// reduce the call gettimeofday() system call.
Time wallclock;
Timer wallclock;
// 0 ... running
// 1 ... stop signal detected
@ -141,8 +139,8 @@ static void executeCommand(std::deque<Command*>& commands,
void DownloadEngine::run()
{
Time cp;
cp.setTimeInSec(0);
Timer cp;
cp.reset(0);
while(!commands.empty() || !_routineCommands.empty()) {
global::wallclock.reset();
if(cp.difference(global::wallclock) >= _refreshInterval) {

View File

@ -44,7 +44,7 @@
#include "SharedHandle.h"
#include "a2netcompat.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "a2io.h"
#ifdef ENABLE_ASYNC_DNS
# include "AsyncNameResolver.h"
@ -92,7 +92,7 @@ private:
time_t _timeout;
Time _registeredTime;
Timer _registeredTime;
public:
SocketPoolEntry(const SharedHandle<SocketCore>& socket,
const std::map<std::string, std::string>& option,
@ -116,7 +116,7 @@ private:
// key = IP address:port, value = SocketPoolEntry
std::multimap<std::string, SocketPoolEntry> _socketPool;
Time _lastSocketPoolScan;
Timer _lastSocketPoolScan;
bool _noWait;

View File

@ -107,7 +107,7 @@ DownloadEngineFactory::newDownloadEngine
#ifdef ENABLE_MESSAGE_DIGEST
e->_checkIntegrityMan.reset(new CheckIntegrityMan());
#endif // ENABLE_MESSAGE_DIGEST
e->addRoutineCommand(new FillRequestGroupCommand(e->newCUID(), e.get(), 1));
e->addRoutineCommand(new FillRequestGroupCommand(e->newCUID(), e.get()));
e->addRoutineCommand(new FileAllocationDispatcherCommand
(e->newCUID(), e->_fileAllocationMan, e.get()));
#ifdef ENABLE_MESSAGE_DIGEST

View File

@ -37,7 +37,7 @@
#include "common.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "a2time.h"
#include "a2netcompat.h"
namespace aria2 {

View File

@ -45,6 +45,7 @@
#include "DownloadContext.h"
#include "a2functional.h"
#include "RecoverableException.h"
#include "wallclock.h"
namespace aria2 {
@ -65,7 +66,7 @@ bool FileAllocationCommand::executeInternal()
if(_fileAllocationEntry->finished()) {
if(logger->debug()) {
logger->debug(MSG_ALLOCATION_COMPLETED,
_timer.difference(),
_timer.difference(global::wallclock),
util::itos(_requestGroup->getTotalLength(), true).c_str());
}
_e->_fileAllocationMan->dropPickedEntry();

View File

@ -37,7 +37,7 @@
#include "RealtimeCommand.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -46,7 +46,7 @@ class FileAllocationEntry;
class FileAllocationCommand : public RealtimeCommand {
private:
SharedHandle<FileAllocationEntry> _fileAllocationEntry;
Time _timer;
Timer _timer;
public:
FileAllocationCommand(cuid_t cuid, RequestGroup* requestGroup,
DownloadEngine* e,

View File

@ -45,11 +45,9 @@
namespace aria2 {
FillRequestGroupCommand::FillRequestGroupCommand(cuid_t cuid,
DownloadEngine* e,
time_t interval):
DownloadEngine* e):
Command(cuid),
_e(e),
_interval(interval)
_e(e)
{
setStatusRealtime();
}

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "a2time.h"
namespace aria2 {
@ -47,19 +47,12 @@ class DownloadEngine;
class FillRequestGroupCommand : public Command {
private:
DownloadEngine* _e;
time_t _interval;
Time _checkPoint;
public:
FillRequestGroupCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
FillRequestGroupCommand(cuid_t cuid, DownloadEngine* e);
virtual ~FillRequestGroupCommand();
virtual bool execute();
void setInterval(time_t interval)
{
_interval = interval;
}
};
} // namespace aria2

View File

@ -81,7 +81,7 @@ bool HttpServerBodyCommand::execute()
}
try {
if(_socket->isReadable(0) || _httpServer->getContentLength() == 0) {
_timeout = global::wallclock;
_timeoutTimer = global::wallclock;
if(_httpServer->receiveBody()) {
// Do something for requestpath and body
@ -108,7 +108,7 @@ bool HttpServerBodyCommand::execute()
return false;
}
} else {
if(_timeout.difference(global::wallclock) >= 30) {
if(_timeoutTimer.difference(global::wallclock) >= 30) {
logger->info("HTTP request body timeout.");
return true;
} else {

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -50,7 +50,7 @@ private:
DownloadEngine* _e;
SharedHandle<SocketCore> _socket;
SharedHandle<HttpServer> _httpServer;
Time _timeout;
Timer _timeoutTimer;
public:
HttpServerBodyCommand(cuid_t cuid,
const SharedHandle<HttpServer>& httpServer,

View File

@ -93,7 +93,7 @@ bool HttpServerCommand::execute()
}
try {
if(_socket->isReadable(0)) {
_timeout = global::wallclock;
_timeoutTimer = global::wallclock;
SharedHandle<HttpHeader> header;
header = _httpServer->receiveRequest();
@ -128,7 +128,7 @@ bool HttpServerCommand::execute()
_e->setNoWait(true);
return true;
} else {
if(_timeout.difference(global::wallclock) >= 30) {
if(_timeoutTimer.difference(global::wallclock) >= 30) {
logger->info("HTTP request timeout.");
return true;
} else {

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -50,7 +50,7 @@ private:
DownloadEngine* _e;
SharedHandle<SocketCore> _socket;
SharedHandle<HttpServer> _httpServer;
Time _timeout;
Timer _timeoutTimer;
public:
HttpServerCommand(cuid_t cuid, DownloadEngine* e,
const SharedHandle<SocketCore>& socket);

View File

@ -93,7 +93,7 @@ bool HttpServerResponseCommand::execute()
}
return true;
} else {
if(_timeout.difference(global::wallclock) >= 10) {
if(_timeoutTimer.difference(global::wallclock) >= 10) {
if(logger->info()) {
logger->info("CUID#%s - HttpServer: Timeout while trasmitting"
" response.", util::itos(cuid).c_str());

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -50,7 +50,7 @@ private:
DownloadEngine* _e;
SharedHandle<SocketCore> _socket;
SharedHandle<HttpServer> _httpServer;
Time _timeout;
Timer _timeoutTimer;
public:
HttpServerResponseCommand(cuid_t cuid,
const SharedHandle<HttpServer>& httpServer,

View File

@ -38,7 +38,7 @@
#include <string>
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -52,7 +52,7 @@ private:
uint16_t _port;
std::string _multicastAddress;
uint16_t _multicastPort;
Time _timer;
Timer _timer;
time_t _interval;
std::string _request;
Logger* _logger;

View File

@ -51,6 +51,7 @@ SRCS = Socket.h\
Base64.cc Base64.h\
base32.cc base32.h\
LogFactory.cc LogFactory.h\
TimerA2.cc TimerA2.h\
TimeA2.cc TimeA2.h\
SharedHandle.h\
HandleRegistry.h\

View File

@ -341,9 +341,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
DefaultDiskWriter.cc DefaultDiskWriter.h \
DefaultDiskWriterFactory.cc DefaultDiskWriterFactory.h File.cc \
File.h Option.cc Option.h Base64.cc Base64.h base32.cc \
base32.h LogFactory.cc LogFactory.h TimeA2.cc TimeA2.h \
SharedHandle.h HandleRegistry.h FeatureConfig.cc \
FeatureConfig.h DownloadEngineFactory.cc \
base32.h LogFactory.cc LogFactory.h TimerA2.cc TimerA2.h \
TimeA2.cc TimeA2.h SharedHandle.h HandleRegistry.h \
FeatureConfig.cc FeatureConfig.h DownloadEngineFactory.cc \
DownloadEngineFactory.h SpeedCalc.cc SpeedCalc.h PeerStat.h \
BitfieldMan.cc BitfieldMan.h Randomizer.h SimpleRandomizer.cc \
SimpleRandomizer.h HttpResponse.cc HttpResponse.h \
@ -800,11 +800,12 @@ am__objects_27 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
SimpleLogger.$(OBJEXT) AbstractDiskWriter.$(OBJEXT) \
DefaultDiskWriter.$(OBJEXT) DefaultDiskWriterFactory.$(OBJEXT) \
File.$(OBJEXT) Option.$(OBJEXT) Base64.$(OBJEXT) \
base32.$(OBJEXT) LogFactory.$(OBJEXT) TimeA2.$(OBJEXT) \
FeatureConfig.$(OBJEXT) DownloadEngineFactory.$(OBJEXT) \
SpeedCalc.$(OBJEXT) BitfieldMan.$(OBJEXT) \
SimpleRandomizer.$(OBJEXT) HttpResponse.$(OBJEXT) \
HttpRequest.$(OBJEXT) AbstractProxyRequestCommand.$(OBJEXT) \
base32.$(OBJEXT) LogFactory.$(OBJEXT) TimerA2.$(OBJEXT) \
TimeA2.$(OBJEXT) FeatureConfig.$(OBJEXT) \
DownloadEngineFactory.$(OBJEXT) SpeedCalc.$(OBJEXT) \
BitfieldMan.$(OBJEXT) SimpleRandomizer.$(OBJEXT) \
HttpResponse.$(OBJEXT) HttpRequest.$(OBJEXT) \
AbstractProxyRequestCommand.$(OBJEXT) \
AbstractProxyResponseCommand.$(OBJEXT) Netrc.$(OBJEXT) \
AuthConfig.$(OBJEXT) AbstractAuthResolver.$(OBJEXT) \
DefaultAuthResolver.$(OBJEXT) NetrcAuthResolver.$(OBJEXT) \
@ -1103,9 +1104,9 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
DefaultDiskWriter.cc DefaultDiskWriter.h \
DefaultDiskWriterFactory.cc DefaultDiskWriterFactory.h File.cc \
File.h Option.cc Option.h Base64.cc Base64.h base32.cc \
base32.h LogFactory.cc LogFactory.h TimeA2.cc TimeA2.h \
SharedHandle.h HandleRegistry.h FeatureConfig.cc \
FeatureConfig.h DownloadEngineFactory.cc \
base32.h LogFactory.cc LogFactory.h TimerA2.cc TimerA2.h \
TimeA2.cc TimeA2.h SharedHandle.h HandleRegistry.h \
FeatureConfig.cc FeatureConfig.h DownloadEngineFactory.cc \
DownloadEngineFactory.h SpeedCalc.cc SpeedCalc.h PeerStat.h \
BitfieldMan.cc BitfieldMan.h Randomizer.h SimpleRandomizer.cc \
SimpleRandomizer.h HttpResponse.cc HttpResponse.h \
@ -1573,6 +1574,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeA2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeBasedCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimedHaltCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimerA2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerWatcherCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TransferStat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/URIResult.Po@am__quote@

View File

@ -370,13 +370,13 @@ bool Peer::isDHTEnabled() const
return _res->dhtEnabled();
}
const Time& Peer::getLastDownloadUpdate() const
const Timer& Peer::getLastDownloadUpdate() const
{
assert(_res);
return _res->getLastDownloadUpdate();
}
const Time& Peer::getLastAmUnchoking() const
const Timer& Peer::getLastAmUnchoking() const
{
assert(_res);
return _res->getLastAmUnchoking();
@ -393,7 +393,7 @@ void Peer::setIncomingPeer(bool incoming)
_incoming = incoming;
}
void Peer::setFirstContactTime(const Time& time)
void Peer::setFirstContactTime(const Timer& time)
{
_firstContactTime = time;
}

View File

@ -43,7 +43,7 @@
#include <algorithm>
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "BtConstants.h"
#include "PeerStat.h"
#include "a2functional.h"
@ -68,9 +68,9 @@ private:
unsigned char _peerId[PEER_ID_LENGTH];
Time _firstContactTime;
Timer _firstContactTime;
Time _badConditionStartTime;
Timer _badConditionStartTime;
bool _seeder;
@ -146,14 +146,14 @@ public:
void releaseSessionResource();
const Time& getFirstContactTime() const
const Timer& getFirstContactTime() const
{
return _firstContactTime;
}
void setFirstContactTime(const Time& time);
void setFirstContactTime(const Timer& time);
const Time& getBadConditionStartTime() const
const Timer& getBadConditionStartTime() const
{
return _badConditionStartTime;
}
@ -269,9 +269,9 @@ public:
void setExtension(const std::string& name, uint8_t id);
const Time& getLastDownloadUpdate() const;
const Timer& getLastDownloadUpdate() const;
const Time& getLastAmUnchoking() const;
const Timer& getLastAmUnchoking() const;
uint64_t getCompletedLength() const;

View File

@ -37,7 +37,7 @@
#include "Command.h"
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -48,7 +48,7 @@ class SocketCore;
class PeerAbstractCommand : public Command {
private:
Time checkPoint;
Timer checkPoint;
time_t timeout;
protected:
DownloadEngine* e;

View File

@ -36,9 +36,11 @@
#define _D_DHT_PEER_ADDR_ENTRY_H_
#include "common.h"
#include "TimeA2.h"
#include <string>
#include "TimerA2.h"
namespace aria2 {
class PeerAddrEntry {
@ -47,9 +49,10 @@ private:
uint16_t _port;
Time _lastUpdated;
Timer _lastUpdated;
public:
PeerAddrEntry(const std::string& ipaddr, uint16_t port, Time updated = Time()):
PeerAddrEntry
(const std::string& ipaddr, uint16_t port, Timer updated = Timer()):
_ipaddr(ipaddr), _port(port), _lastUpdated(updated) {}
const std::string& getIPAddress() const
@ -62,7 +65,7 @@ public:
return _port;
}
const Time& getLastUpdated() const
const Timer& getLastUpdated() const
{
return _lastUpdated;
}

View File

@ -42,7 +42,7 @@
#include "BtConstants.h"
#include "PeerStat.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -77,9 +77,9 @@ private:
bool _dhtEnabled;
PeerStat _peerStat;
Time _lastDownloadUpdate;
Timer _lastDownloadUpdate;
Time _lastAmUnchoking;
Timer _lastAmUnchoking;
WeakHandle<BtMessageDispatcher> _dispatcher;
public:
@ -216,12 +216,12 @@ public:
void updateDownloadLength(size_t bytes);
const Time& getLastDownloadUpdate() const
const Timer& getLastDownloadUpdate() const
{
return _lastDownloadUpdate;
}
const Time& getLastAmUnchoking() const
const Timer& getLastAmUnchoking() const
{
return _lastAmUnchoking;
}

View File

@ -57,7 +57,7 @@ private:
std::string _protocol;
SpeedCalc downloadSpeed;
SpeedCalc uploadSpeed;
Time downloadStartTime;
Timer downloadStartTime;
PeerStat::STATUS status;
unsigned int _avgDownloadSpeed;
unsigned int _avgUploadSpeed;
@ -147,7 +147,7 @@ public:
status = PeerStat::IDLE;
}
const Time& getDownloadStartTime() const {
const Timer& getDownloadStartTime() const {
return downloadStartTime;
}

View File

@ -41,7 +41,7 @@
#include <vector>
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "Command.h"
namespace aria2 {
@ -207,7 +207,7 @@ public:
*/
virtual void getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
cuid_t myCuid,
const Time& lastCheckTime) = 0;
const Timer& lastCheckTime) = 0;
/**
* Removes have entry if specified seconds have elapsed since its

View File

@ -39,12 +39,8 @@ namespace aria2 {
RequestSlot RequestSlot::nullSlot = RequestSlot();
void RequestSlot::setDispatchedTime() {
dispatchedTime = global::wallclock;
}
void RequestSlot::setDispatchedTime(time_t secFromEpoch) {
dispatchedTime.setTimeInSec(secFromEpoch);
void RequestSlot::setDispatchedTime(time_t sec) {
dispatchedTime.reset(sec);
}
bool RequestSlot::isTimeout(time_t timeoutSec) const {

View File

@ -36,14 +36,15 @@
#define _D_REQUEST_SLOT_H_
#include "common.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "Piece.h"
#include "wallclock.h"
namespace aria2 {
class RequestSlot {
private:
Time dispatchedTime;
Timer dispatchedTime;
size_t index;
uint32_t begin;
size_t length;
@ -70,6 +71,7 @@ public:
RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex,
const SharedHandle<Piece>& piece = SharedHandle<Piece>()):
dispatchedTime(global::wallclock),
index(index), begin(begin), length(length), blockIndex(blockIndex),
_piece(piece) {}
@ -113,7 +115,6 @@ public:
}
}
void setDispatchedTime();
void setDispatchedTime(time_t secFromEpoch);
bool isTimeout(time_t timeoutSec) const;

View File

@ -42,7 +42,7 @@
#include <map>
#include "SharedHandle.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "Command.h"
#include "BitfieldMan.h"
@ -98,7 +98,7 @@ private:
// key: PeerStat's cuid, value: its download speed
std::map<cuid_t, unsigned int> _peerStatDlspdMap;
Time _lastPeerStatDlspdMapUpdated;
Timer _lastPeerStatDlspdMapUpdated;
unsigned int _cachedDlspd;

View File

@ -39,7 +39,6 @@
#include "array_fun.h"
#include "LogFactory.h"
#include "wallclock.h"
namespace aria2 {
@ -78,7 +77,7 @@ void ServerStat::updateDownloadSpeed(unsigned int downloadSpeed)
if(downloadSpeed > 0) {
_status = OK;
}
_lastUpdated = global::wallclock;
_lastUpdated.reset();
}
void ServerStat::setSingleConnectionAvgSpeed
@ -183,7 +182,7 @@ void ServerStat::setStatusInternal(STATUS status)
_hostname.c_str(), _protocol.c_str());
}
_status = status;
_lastUpdated = global::wallclock;
_lastUpdated.reset();
}
void ServerStat::setOK()

View File

@ -43,7 +43,6 @@
#include "ServerStat.h"
#include "util.h"
#include "RecoverableException.h"
#include "wallclock.h"
namespace aria2 {
@ -144,12 +143,13 @@ bool ServerStatMan::load(std::istream& in)
class FindStaleServerStat {
private:
time_t _timeout;
Time _time;
public:
FindStaleServerStat(time_t timeout):_timeout(timeout) {}
bool operator()(const SharedHandle<ServerStat>& ss) const
{
return ss->getLastUpdated().difference(global::wallclock) >= _timeout;
return ss->getLastUpdated().difference(_time) >= _timeout;
}
};

View File

@ -35,11 +35,14 @@
#ifndef _D_SERVER_STAT_MAN_H_
#define _D_SERVER_STAT_MAN_H_
#include "common.h"
#include "SharedHandle.h"
#include <string>
#include <deque>
#include <iosfwd>
#include "SharedHandle.h"
#include "a2time.h"
namespace aria2 {
class ServerStat;

View File

@ -44,7 +44,7 @@ SleepCommand::SleepCommand(cuid_t cuid, DownloadEngine* e,
RequestGroup* requestGroup,
Command* nextCommand, time_t wait):
Command(cuid), engine(e), _requestGroup(requestGroup),
nextCommand(nextCommand), wait(wait) {}
nextCommand(nextCommand), wait(wait), checkPoint(global::wallclock) {}
SleepCommand::~SleepCommand() {
delete nextCommand;

View File

@ -36,7 +36,7 @@
#define _D_SLEEP_COMMAND_H_
#include "Command.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -49,7 +49,7 @@ private:
RequestGroup* _requestGroup;
Command* nextCommand;
time_t wait;
Time checkPoint;
Timer checkPoint;
public:
SleepCommand(cuid_t cuid, DownloadEngine* e, RequestGroup* requestGroup,
Command* nextCommand, time_t wait);

View File

@ -36,7 +36,7 @@
#define _D_SPEED_CALC_H_
#include "common.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -44,10 +44,10 @@ class SpeedCalc {
private:
uint64_t lengthArray[2];
int sw;
Time cpArray[2];
Timer cpArray[2];
unsigned int maxSpeed;
unsigned int prevSpeed;
Time start;
Timer start;
uint64_t accumulatedLength;
time_t nextInterval;

View File

@ -36,14 +36,11 @@
#define _D_STREAM_CHECK_INTEGRITY_ENTRY_H_
#include "PieceHashCheckIntegrityEntry.h"
#include "TimeA2.h"
namespace aria2 {
class StreamCheckIntegrityEntry:public PieceHashCheckIntegrityEntry
{
private:
Time _timer;
public:
StreamCheckIntegrityEntry(RequestGroup* requestGroup,
Command* nextCommand = 0);

View File

@ -36,13 +36,10 @@
#define _D_STREAM_FILE_ALLOCATION_ENTRY_H_
#include "FileAllocationEntry.h"
#include "TimeA2.h"
namespace aria2 {
class StreamFileAllocationEntry : public FileAllocationEntry {
private:
Time _timer;
public:
StreamFileAllocationEntry(RequestGroup* requestGroup,
Command* nextCommand = 0);

View File

@ -36,7 +36,7 @@
#define _D_TIME_BASED_COMMAND_H_
#include "Command.h"
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
@ -60,7 +60,7 @@ protected:
bool _routineCommand;
private:
Time _checkPoint;
Timer _checkPoint;
public:
/**
* preProcess() is called each time when excute() is called.

View File

@ -36,7 +36,7 @@
#define _D_TIME_SEED_CRITERIA_H_
#include "SeedCriteria.h"
#include "TimeA2.h"
#include "TimerA2.h"
#include "wallclock.h"
namespace aria2 {
@ -45,7 +45,7 @@ class TimeSeedCriteria : public SeedCriteria {
private:
// How much time the client does seeding in seconds.
time_t duration;
Time watch;
Timer watch;
public:
TimeSeedCriteria(time_t duration):duration(duration) {}
virtual ~TimeSeedCriteria() {}

165
src/TimerA2.cc Normal file
View File

@ -0,0 +1,165 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "TimerA2.h"
#include <cassert>
#include "util.h"
namespace aria2 {
Timer::Timer()
{
reset();
}
Timer::Timer(const Timer& timer):_tv(timer._tv) {}
Timer::Timer(time_t sec)
{
reset(sec);
}
Timer::Timer(const struct timeval& tv):_tv(tv) {}
static bool useClockGettime()
{
static timespec ts;
static int r = clock_gettime(CLOCK_MONOTONIC, &ts);
return r == 0;
}
Timer& Timer::operator=(const Timer& timer)
{
if(this != &timer) {
_tv = timer._tv;
}
return *this;
}
bool Timer::operator<(const Timer& timer) const
{
return util::difftv(timer._tv, _tv) > 0;
}
bool Timer::operator>(const Timer& timer) const
{
return util::difftv(_tv, timer._tv) > 0;
}
static timeval getCurrentTime()
{
timeval tv;
if(useClockGettime()) {
timespec ts;
int r = clock_gettime(CLOCK_MONOTONIC, &ts);
assert(r == 0);
tv.tv_sec = ts.tv_sec+2678400; // 1month offset(24*3600*31)
tv.tv_usec = ts.tv_nsec/1000;
} else {
gettimeofday(&tv, 0);
}
return tv;
}
void Timer::reset()
{
_tv = getCurrentTime();
}
void Timer::reset(time_t sec)
{
_tv.tv_sec = sec;
_tv.tv_usec = 0;
}
bool Timer::elapsed(time_t sec) const
{
return
util::difftv(getCurrentTime(), _tv) >= static_cast<int64_t>(sec)*1000000;
}
bool Timer::elapsedInMillis(int64_t millis) const
{
return util::difftv(getCurrentTime(), _tv)/1000 >= millis;
}
time_t Timer::difference() const
{
return util::difftv(getCurrentTime(), _tv)/1000000;
}
time_t Timer::difference(const timeval& tv) const
{
return util::difftv(tv, _tv)/1000000;
}
int64_t Timer::differenceInMillis() const
{
return util::difftv(getCurrentTime(), _tv)/1000;
}
int64_t Timer::differenceInMillis(const timeval& tv) const
{
return util::difftv(tv, _tv)/1000;
}
bool Timer::isZero() const
{
return _tv.tv_sec == 0 && _tv.tv_usec == 0;
}
int64_t Timer::getTimeInMicros() const
{
return (int64_t)_tv.tv_sec*1000*1000+_tv.tv_usec;
}
int64_t Timer::getTimeInMillis() const
{
return (int64_t)_tv.tv_sec*1000+_tv.tv_usec/1000;
}
time_t Timer::getTime() const
{
return _tv.tv_sec;
}
void Timer::advance(time_t sec)
{
_tv.tv_sec += sec;
}
} // namespace aria2

101
src/TimerA2.h Normal file
View File

@ -0,0 +1,101 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 --> */
#ifndef _D_TIMER_A2_H_
#define _D_TIMER_A2_H_
#include "common.h"
#include "a2time.h"
namespace aria2 {
class Timer {
private:
timeval _tv;
int64_t difference(const struct timeval& tv) const;
int64_t differenceInMillis(const struct timeval& tv) const;
public:
// The time value is initialized so that it represents the time at which
// this object was created.
Timer();
Timer(const Timer& time);
Timer(time_t sec);
Timer(const struct timeval& tv);
Timer& operator=(const Timer& timer);
bool operator<(const Timer& timer) const;
bool operator>(const Timer& timer) const;
void reset();
void reset(time_t sec);
bool elapsed(time_t sec) const;
bool elapsedInMillis(int64_t millis) const;
time_t difference() const;
time_t difference(const Timer& timer) const
{
return difference(timer._tv);
}
int64_t differenceInMillis() const;
int64_t differenceInMillis(const Timer& timer) const
{
return differenceInMillis(timer._tv);
}
// Returns true if this object's time value is zero.
bool isZero() const;
void advance(time_t sec);
// Returns this object's time value in seconds.
time_t getTime() const;
int64_t getTimeInMicros() const;
int64_t getTimeInMillis() const;
};
} // namespace aria2
#endif // _D_TIMER_A2_H_

View File

@ -39,7 +39,7 @@
#include <vector>
#include "TimeA2.h"
#include "TimerA2.h"
#include "wallclock.h"
namespace aria2 {
@ -50,7 +50,7 @@ class UTMetadataRequestTracker {
private:
struct RequestEntry {
size_t _index;
Time _dispatchedTime;
Timer _dispatchedTime;
RequestEntry(size_t index):_index(index) {}

View File

@ -229,7 +229,7 @@ public:
*/
virtual void
getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
cuid_t myCuid, const Time& lastCheckTime)
cuid_t myCuid, const Timer& lastCheckTime)
{}
/**

View File

@ -61,4 +61,14 @@
# define suseconds_t uint64_t
#endif
#ifndef CLOCK_MONOTONIC
# define CLOCK_MONOTONIC 0
#endif // !CLOCK_MONOTONIC
#ifndef HAVE_STRUCT_TIMESPEC
# define timespec int
#endif // !HAVE_STRUCT_TIMESPEC
#ifndef HAVE_CLOCK_GETTIME
# define clock_gettime(ID, TP) (-1)
#endif // !HAVE_CLOCK_GETTIME
#endif // _D_A2TIME_H_

View File

@ -32,14 +32,14 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "TimeA2.h"
#include "TimerA2.h"
namespace aria2 {
namespace global {
// wallclock is defined in DownloadEngine.cc
extern Time wallclock;
extern Timer wallclock;
} // namespace global

View File

@ -36,9 +36,9 @@ void DHTPeerAnnounceEntryTest::testRemoveStalePeerAddrEntry()
DHTPeerAnnounceEntry entry(infohash);
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6881));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.2", 6882, Time(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.2", 6882, Timer(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.3", 6883));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.4", 6884, Time(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.4", 6884, Timer(0)));
entry.removeStalePeerAddrEntry(10);
@ -72,7 +72,7 @@ void DHTPeerAnnounceEntryTest::testAddPeerAddrEntry()
memset(infohash, 0xff, DHT_ID_LENGTH);
DHTPeerAnnounceEntry entry(infohash);
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6881, Time(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6881, Timer(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6882));
CPPUNIT_ASSERT_EQUAL((size_t)2, entry.countPeerAddrEntry());
@ -95,7 +95,7 @@ void DHTPeerAnnounceEntryTest::testGetPeers()
CPPUNIT_ASSERT_EQUAL((size_t)0, peers.size());
}
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6881, Time(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6881, Timer(0)));
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.2", 6882));
{

View File

@ -214,7 +214,7 @@ public:
virtual void getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
cuid_t myCuid,
const Time& lastCheckTime)
const Timer& lastCheckTime)
{}
virtual void removeAdvertisedPiece(time_t elapsed) {}

View File

@ -206,7 +206,7 @@ void UTPexExtensionMessageTest::testAddFreshPeer()
SharedHandle<Peer> p1(new Peer("192.168.0.1", 6881));
CPPUNIT_ASSERT(msg.addFreshPeer(p1));
SharedHandle<Peer> p2(new Peer("10.1.1.2", 9999));
p2->setFirstContactTime(Time(Time().getTime()-61));
p2->setFirstContactTime(Timer(Timer().getTime()-61));
CPPUNIT_ASSERT(!msg.addFreshPeer(p2));
SharedHandle<Peer> p3(new Peer("10.1.1.3", 9999, true));
CPPUNIT_ASSERT(!msg.addFreshPeer(p3));