mirror of https://github.com/aria2/aria2
Use user-defined literals for time units
parent
dd277b33af
commit
0b48bb1dbd
|
@ -237,8 +237,7 @@ bool AbstractCommand::execute()
|
|||
if (req_ && fileEntry_->getLength() > 0 &&
|
||||
e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit() == 0 &&
|
||||
requestGroup_->getMaxDownloadSpeedLimit() == 0 &&
|
||||
serverStatTimer_.difference(global::wallclock()) >=
|
||||
std::chrono::seconds(10)) {
|
||||
serverStatTimer_.difference(global::wallclock()) >= 10_s) {
|
||||
serverStatTimer_ = global::wallclock();
|
||||
std::vector<std::pair<size_t, std::string>> usedHosts;
|
||||
if (getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
|
||||
|
|
|
@ -119,8 +119,7 @@ bool AbstractHttpServerResponseCommand::execute()
|
|||
afterSend(httpServer_, e_);
|
||||
return true;
|
||||
} else {
|
||||
if (timeoutTimer_.difference(global::wallclock()) >=
|
||||
std::chrono::seconds(30)) {
|
||||
if (timeoutTimer_.difference(global::wallclock()) >= 30_s) {
|
||||
A2_LOG_INFO(fmt("CUID#%" PRId64
|
||||
" - HttpServer: Timeout while trasmitting response.",
|
||||
getCuid()));
|
||||
|
|
|
@ -97,7 +97,7 @@ std::string AdaptiveURISelector::select
|
|||
}
|
||||
|
||||
namespace {
|
||||
constexpr auto MAX_TIMEOUT = std::chrono::seconds(60);
|
||||
constexpr auto MAX_TIMEOUT = 60_s;
|
||||
} // namespace
|
||||
|
||||
void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
|
||||
|
|
|
@ -54,6 +54,6 @@ const std::string BtAnnounce::PEERS("peers");
|
|||
|
||||
const std::string BtAnnounce::PEERS6("peers6");
|
||||
|
||||
constexpr std::chrono::seconds BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL;
|
||||
constexpr std::chrono::minutes BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL;
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "a2time.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -138,7 +139,7 @@ public:
|
|||
|
||||
static const std::string PEERS6;
|
||||
|
||||
constexpr static auto DEFAULT_ANNOUNCE_INTERVAL = std::chrono::seconds(120);
|
||||
constexpr static auto DEFAULT_ANNOUNCE_INTERVAL = 2_min;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -56,9 +56,9 @@ BtLeecherStateChoke::PeerEntry::PeerEntry(const std::shared_ptr<Peer>& peer)
|
|||
: peer_(peer),
|
||||
downloadSpeed_(peer->calculateDownloadSpeed()),
|
||||
// peer must be interested to us and sent block in the last 30 seconds
|
||||
regularUnchoker_(peer->peerInterested() &&
|
||||
peer->getLastDownloadUpdate().difference(
|
||||
global::wallclock()) < std::chrono::seconds(30))
|
||||
regularUnchoker_(
|
||||
peer->peerInterested() &&
|
||||
peer->getLastDownloadUpdate().difference(global::wallclock()) < 30_s)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ BtSeederStateChoke::BtSeederStateChoke()
|
|||
BtSeederStateChoke::~BtSeederStateChoke() {}
|
||||
|
||||
namespace {
|
||||
constexpr auto TIME_FRAME = std::chrono::seconds(20);
|
||||
constexpr auto TIME_FRAME = 20_s;
|
||||
} // namespace
|
||||
|
||||
BtSeederStateChoke::PeerEntry::PeerEntry
|
||||
|
|
|
@ -126,8 +126,7 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
|||
}
|
||||
{
|
||||
auto c = make_unique<ActivePeerConnectionCommand>(
|
||||
e->newCUID(), requestGroup, e,
|
||||
std::chrono::seconds(metadataGetMode ? 2 : 10));
|
||||
e->newCUID(), requestGroup, e, metadataGetMode ? 2_s : 10_s);
|
||||
c->setBtRuntime(btRuntime);
|
||||
c->setPieceStorage(pieceStorage);
|
||||
c->setPeerStorage(peerStorage);
|
||||
|
|
|
@ -51,7 +51,7 @@ BtStopDownloadCommand::BtStopDownloadCommand
|
|||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
std::chrono::seconds timeout)
|
||||
: TimeBasedCommand(cuid, e, std::chrono::seconds(1)),
|
||||
: TimeBasedCommand(cuid, e, 1_s),
|
||||
requestGroup_(requestGroup),
|
||||
timeout_(std::move(timeout))
|
||||
{}
|
||||
|
|
|
@ -318,7 +318,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
|||
}
|
||||
ColorizedStream o;
|
||||
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
||||
if((summaryInterval_ > std::chrono::seconds(0)) &&
|
||||
if((summaryInterval_ > 0_s) &&
|
||||
lastSummaryNotified_.difference(global::wallclock())+
|
||||
A2_DELTA_MILLIS >= summaryInterval_*1000) {
|
||||
lastSummaryNotified_ = global::wallclock();
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "TimerA2.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
// Increment this if major improvements or bug fixes are made in DHT
|
||||
// code. This is 2 bytes unsigned integer.
|
||||
|
@ -48,21 +49,25 @@
|
|||
|
||||
#define DHT_TOKEN_LENGTH 4
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
// See --dht-message-timeout option.
|
||||
constexpr auto DHT_MESSAGE_TIMEOUT = std::chrono::seconds(10);
|
||||
constexpr auto DHT_MESSAGE_TIMEOUT = 10_s;
|
||||
|
||||
constexpr auto DHT_NODE_CONTACT_INTERVAL = std::chrono::minutes(15);
|
||||
constexpr auto DHT_NODE_CONTACT_INTERVAL = 15_min;
|
||||
|
||||
constexpr auto DHT_BUCKET_REFRESH_INTERVAL = std::chrono::minutes(15);
|
||||
constexpr auto DHT_BUCKET_REFRESH_INTERVAL = 15_min;
|
||||
|
||||
constexpr auto DHT_BUCKET_REFRESH_CHECK_INTERVAL = std::chrono::minutes(5);
|
||||
constexpr auto DHT_BUCKET_REFRESH_CHECK_INTERVAL = 5_min;
|
||||
|
||||
constexpr auto DHT_PEER_ANNOUNCE_PURGE_INTERVAL = std::chrono::minutes(30);
|
||||
constexpr auto DHT_PEER_ANNOUNCE_PURGE_INTERVAL = 30_min;
|
||||
|
||||
constexpr auto DHT_PEER_ANNOUNCE_INTERVAL = std::chrono::minutes(15);
|
||||
constexpr auto DHT_PEER_ANNOUNCE_INTERVAL = 15_min;
|
||||
|
||||
constexpr auto DHT_PEER_ANNOUNCE_CHECK_INTERVAL = std::chrono::minutes(5);
|
||||
constexpr auto DHT_PEER_ANNOUNCE_CHECK_INTERVAL = 5_min;
|
||||
|
||||
constexpr auto DHT_TOKEN_UPDATE_INTERVAL = std::chrono::minutes(10);
|
||||
constexpr auto DHT_TOKEN_UPDATE_INTERVAL = 10_min;
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_DHT_CONSTANTS_H
|
||||
|
|
|
@ -55,13 +55,13 @@ namespace aria2 {
|
|||
|
||||
namespace {
|
||||
|
||||
constexpr auto GET_PEER_INTERVAL = std::chrono::minutes(15);
|
||||
constexpr auto GET_PEER_INTERVAL = 15_min;
|
||||
// Interval when the size of peer list is low.
|
||||
constexpr auto GET_PEER_INTERVAL_LOW = std::chrono::minutes(5);
|
||||
constexpr auto GET_PEER_INTERVAL_LOW = 5_min;
|
||||
// Interval when the peer list is empty.
|
||||
constexpr auto GET_PEER_INTERVAL_ZERO = std::chrono::minutes(1);
|
||||
constexpr auto GET_PEER_INTERVAL_ZERO = 1_min;
|
||||
// Interval for retry.
|
||||
constexpr auto GET_PEER_INTERVAL_RETRY = std::chrono::seconds(5);
|
||||
constexpr auto GET_PEER_INTERVAL_RETRY = 5_s;
|
||||
// Maximum retries. Try more than 5 to drop bad node.
|
||||
const int MAX_RETRIES = 10;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ bool DHTMessageDispatcherImpl::sendMessage(DHTMessageEntry* entry)
|
|||
// DHTTask(such as DHTAbstractNodeLookupTask) don't finish
|
||||
// forever.
|
||||
if(!entry->message->isReply()) {
|
||||
tracker_->addMessage(entry->message.get(), std::chrono::seconds(0),
|
||||
tracker_->addMessage(entry->message.get(), 0_s,
|
||||
std::move(entry->callback));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
|||
}
|
||||
{
|
||||
auto command = make_unique<DHTAutoSaveCommand>(e->newCUID(), e, family,
|
||||
std::chrono::minutes(30));
|
||||
30_min);
|
||||
command->setLocalNode(localNode);
|
||||
command->setRoutingTable(routingTable.get());
|
||||
tempCommands.push_back(std::move(command));
|
||||
|
|
|
@ -64,7 +64,7 @@ DefaultBtAnnounce::DefaultBtAnnounce
|
|||
prevAnnounceTimer_(Timer::zero()),
|
||||
interval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
minInterval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
userDefinedInterval_(std::chrono::seconds(0)),
|
||||
userDefinedInterval_(0_s),
|
||||
complete_(0),
|
||||
incomplete_(0),
|
||||
announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList),
|
||||
|
|
|
@ -255,7 +255,7 @@ void DefaultBtInteractive::decideChoking() {
|
|||
}
|
||||
|
||||
namespace {
|
||||
constexpr auto MAX_HAVE_DELAY_SEC = std::chrono::seconds(10);
|
||||
constexpr auto MAX_HAVE_DELAY_SEC = 10_s;
|
||||
} // namespace
|
||||
|
||||
void DefaultBtInteractive::checkHave() {
|
||||
|
@ -434,7 +434,7 @@ void DefaultBtInteractive::sendPendingMessage() {
|
|||
}
|
||||
|
||||
namespace {
|
||||
constexpr auto FLOODING_CHECK_INTERVAL = std::chrono::seconds(5);
|
||||
constexpr auto FLOODING_CHECK_INTERVAL = 5_s;
|
||||
} // namespace
|
||||
|
||||
void DefaultBtInteractive::detectMessageFlooding() {
|
||||
|
@ -529,8 +529,7 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
|||
dispatcher_->addMessageToQueue(std::move(i));
|
||||
}
|
||||
}
|
||||
if(perSecTimer_.difference(global::wallclock()) >=
|
||||
std::chrono::seconds(1)) {
|
||||
if(perSecTimer_.difference(global::wallclock()) >= 1_s) {
|
||||
perSecTimer_ = global::wallclock();
|
||||
// Drop timeout request after queuing message to give a chance
|
||||
// to other connection to request piece.
|
||||
|
@ -548,8 +547,7 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
|||
checkActiveInteraction();
|
||||
decideChoking();
|
||||
detectMessageFlooding();
|
||||
if(perSecTimer_.difference(global::wallclock()) >=
|
||||
std::chrono::seconds(1)) {
|
||||
if(perSecTimer_.difference(global::wallclock()) >= 1_s) {
|
||||
perSecTimer_ = global::wallclock();
|
||||
dispatcher_->checkRequestSlotAndDoNecessaryThing();
|
||||
}
|
||||
|
|
|
@ -197,8 +197,7 @@ bool DefaultPeerStorage::isBadPeer(const std::string& ipaddr)
|
|||
|
||||
void DefaultPeerStorage::addBadPeer(const std::string& ipaddr)
|
||||
{
|
||||
if(lastBadPeerCleaned_.difference(global::wallclock()) >=
|
||||
std::chrono::hours(1)) {
|
||||
if(lastBadPeerCleaned_.difference(global::wallclock()) >= 1_h) {
|
||||
for(auto i = std::begin(badPeers_); i != std::end(badPeers_);) {
|
||||
if((*i).second <= global::wallclock()) {
|
||||
A2_LOG_DEBUG(fmt("Purge %s from bad peer", (*i).first.c_str()));
|
||||
|
@ -284,7 +283,7 @@ void DefaultPeerStorage::returnPeer(const std::shared_ptr<Peer>& peer)
|
|||
|
||||
bool DefaultPeerStorage::chokeRoundIntervalElapsed()
|
||||
{
|
||||
constexpr auto CHOKE_ROUND_INTERVAL = std::chrono::seconds(10);
|
||||
constexpr auto CHOKE_ROUND_INTERVAL = 10_s;
|
||||
if(pieceStorage_->downloadFinished()) {
|
||||
return seederStateChoke_->getLastRound().
|
||||
difference(global::wallclock()) >= CHOKE_ROUND_INTERVAL;
|
||||
|
|
|
@ -91,7 +91,7 @@ volatile sig_atomic_t globalHaltRequested = 0;
|
|||
} // namespace global
|
||||
|
||||
namespace {
|
||||
constexpr auto DEFAULT_REFRESH_INTERVAL = std::chrono::seconds(1);
|
||||
constexpr auto DEFAULT_REFRESH_INTERVAL = 1_s;
|
||||
} // namespace
|
||||
|
||||
DownloadEngine::DownloadEngine(std::unique_ptr<EventPoll> eventPoll)
|
||||
|
@ -312,8 +312,7 @@ void DownloadEngine::poolSocket(const std::string& key,
|
|||
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
|
||||
socketPool_.insert(p);
|
||||
|
||||
if(lastSocketPoolScan_.difference(global::wallclock()) <
|
||||
std::chrono::minutes(1)) {
|
||||
if(lastSocketPoolScan_.difference(global::wallclock()) < 1_min) {
|
||||
return;
|
||||
}
|
||||
std::multimap<std::string, SocketPoolEntry> newPool;
|
||||
|
|
|
@ -269,24 +269,24 @@ public:
|
|||
const std::string& proxyhost, uint16_t proxyport,
|
||||
const std::shared_ptr<SocketCore>& sock,
|
||||
const std::string& options,
|
||||
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||
std::chrono::seconds timeout = 15_s);
|
||||
|
||||
void poolSocket(const std::shared_ptr<Request>& request,
|
||||
const std::string& username,
|
||||
const std::shared_ptr<Request>& proxyRequest,
|
||||
const std::shared_ptr<SocketCore>& socket,
|
||||
const std::string& options,
|
||||
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||
std::chrono::seconds timeout = 15_s);
|
||||
|
||||
void poolSocket(const std::string& ipaddr, uint16_t port,
|
||||
const std::string& proxyhost, uint16_t proxyport,
|
||||
const std::shared_ptr<SocketCore>& sock,
|
||||
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||
std::chrono::seconds timeout = 15_s);
|
||||
|
||||
void poolSocket(const std::shared_ptr<Request>& request,
|
||||
const std::shared_ptr<Request>& proxyRequest,
|
||||
const std::shared_ptr<SocketCore>& socket,
|
||||
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||
std::chrono::seconds timeout = 15_s);
|
||||
|
||||
std::shared_ptr<SocketCore> popPooledSocket
|
||||
(const std::string& ipaddr,
|
||||
|
|
|
@ -175,8 +175,8 @@ DownloadEngineFactory::newDownloadEngine
|
|||
e->newCUID(), e.get(),
|
||||
std::chrono::seconds(op->getAsInt(PREF_SAVE_SESSION_INTERVAL))));
|
||||
}
|
||||
e->addRoutineCommand(make_unique<HaveEraseCommand>
|
||||
(e->newCUID(), e.get(), std::chrono::seconds(10)));
|
||||
e->addRoutineCommand(
|
||||
make_unique<HaveEraseCommand>(e->newCUID(), e.get(), 10_s));
|
||||
{
|
||||
auto stopSec = op->getAsInt(PREF_STOP);
|
||||
if(stopSec > 0) {
|
||||
|
|
|
@ -214,7 +214,7 @@ FileEntry::getRequest
|
|||
}
|
||||
|
||||
namespace {
|
||||
constexpr auto startupIdleTime = std::chrono::seconds(10);
|
||||
constexpr auto startupIdleTime = 10_s;
|
||||
} // namespace
|
||||
|
||||
std::shared_ptr<Request>
|
||||
|
|
|
@ -63,7 +63,7 @@ void HaveEraseCommand::process()
|
|||
for(auto & group : groups) {
|
||||
const auto& ps = group->getPieceStorage();
|
||||
if(ps) {
|
||||
ps->removeAdvertisedPiece(std::chrono::seconds(5));
|
||||
ps->removeAdvertisedPiece(5_s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ void HttpServerBodyCommand::addHttpServerResponseCommand(bool delayed)
|
|||
make_unique<HttpServerResponseCommand>(getCuid(), httpServer_, e_, socket_);
|
||||
if (delayed) {
|
||||
e_->addCommand(make_unique<DelayedCommand>(
|
||||
getCuid(), e_, std::chrono::seconds(1), std::move(resp), true));
|
||||
getCuid(), e_, 1_s, std::move(resp), true));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -320,8 +320,7 @@ bool HttpServerBodyCommand::execute()
|
|||
return false;
|
||||
}
|
||||
} else {
|
||||
if(timeoutTimer_.difference(global::wallclock()) >=
|
||||
std::chrono::seconds(30)) {
|
||||
if(timeoutTimer_.difference(global::wallclock()) >= 30_s) {
|
||||
A2_LOG_INFO("HTTP request body timeout.");
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -253,8 +253,7 @@ bool HttpServerCommand::execute()
|
|||
return true;
|
||||
}
|
||||
} else {
|
||||
if(timeoutTimer_.difference(global::wallclock()) >=
|
||||
std::chrono::seconds(30)) {
|
||||
if(timeoutTimer_.difference(global::wallclock()) >= 30_s) {
|
||||
A2_LOG_INFO("HTTP request timeout.");
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
LpdMessageDispatcher(
|
||||
const std::string& infoHash, uint16_t port,
|
||||
const std::string& multicastAddr, uint16_t multicastPort,
|
||||
std::chrono::seconds interval = std::chrono::minutes(5));
|
||||
std::chrono::seconds interval = 5_min);
|
||||
|
||||
~LpdMessageDispatcher();
|
||||
|
||||
|
|
|
@ -978,7 +978,7 @@ void RequestGroup::releaseRuntimeResource(DownloadEngine* e)
|
|||
peerStorage_ = nullptr;
|
||||
#endif // ENABLE_BITTORRENT
|
||||
if(pieceStorage_) {
|
||||
pieceStorage_->removeAdvertisedPiece(std::chrono::seconds(0));
|
||||
pieceStorage_->removeAdvertisedPiece(0_s);
|
||||
}
|
||||
// Don't reset segmentMan_ and pieceStorage_ here to provide
|
||||
// progress information via RPC
|
||||
|
|
|
@ -1306,8 +1306,8 @@ std::unique_ptr<ValueBase> goingShutdown
|
|||
{
|
||||
// Schedule shutdown after 3seconds to give time to client to
|
||||
// receive RPC response.
|
||||
e->addRoutineCommand(make_unique<TimedHaltCommand>(
|
||||
e->newCUID(), e, std::chrono::seconds(3), forceHalt));
|
||||
e->addRoutineCommand(
|
||||
make_unique<TimedHaltCommand>(e->newCUID(), e, 3_s, forceHalt));
|
||||
A2_LOG_INFO("Scheduled shutdown in 3 seconds.");
|
||||
return createOKResponse();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
namespace aria2 {
|
||||
|
||||
namespace {
|
||||
constexpr auto WINDOW_TIME = std::chrono::seconds(15);
|
||||
constexpr auto WINDOW_TIME = 15_s;
|
||||
} // namespace
|
||||
|
||||
SpeedCalc::SpeedCalc()
|
||||
|
@ -94,7 +94,7 @@ void SpeedCalc::update(size_t bytes)
|
|||
removeStaleTimeSlot(now);
|
||||
if(timeSlots_.empty() ||
|
||||
std::chrono::duration_cast<std::chrono::seconds>(
|
||||
timeSlots_.back().first.difference(now)) >= std::chrono::seconds(1)) {
|
||||
timeSlots_.back().first.difference(now)) >= 1_s) {
|
||||
timeSlots_.push_back(std::make_pair(now, bytes));
|
||||
} else {
|
||||
timeSlots_.back().second += bytes;
|
||||
|
|
|
@ -55,7 +55,7 @@ Timer::Clock::duration Timer::difference() const
|
|||
{
|
||||
auto now = Clock::now();
|
||||
if (now < tp_) {
|
||||
return Timer::Clock::duration(std::chrono::seconds(0));
|
||||
return Timer::Clock::duration(0_s);
|
||||
}
|
||||
|
||||
return now - tp_;
|
||||
|
@ -64,7 +64,7 @@ Timer::Clock::duration Timer::difference() const
|
|||
Timer::Clock::duration Timer::difference(const Timer& timer) const
|
||||
{
|
||||
if (timer.tp_ < tp_) {
|
||||
return Timer::Clock::duration(std::chrono::seconds(0));
|
||||
return Timer::Clock::duration(0_s);
|
||||
}
|
||||
|
||||
return timer.tp_ - tp_;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <chrono>
|
||||
|
||||
#include "a2time.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -92,7 +93,7 @@ public:
|
|||
|
||||
const Clock::time_point& getTime() const { return tp_; }
|
||||
|
||||
constexpr static Timer zero() { return Timer(std::chrono::seconds(0)); }
|
||||
constexpr static Timer zero() { return Timer(0_s); }
|
||||
|
||||
private:
|
||||
Clock::time_point tp_;
|
||||
|
|
|
@ -370,7 +370,7 @@ struct TimeoutCheck {
|
|||
{
|
||||
auto t = req->dispatched.difference(now);
|
||||
if(req->failCount == 0) {
|
||||
if(t >= std::chrono::seconds(15)) {
|
||||
if(t >= 15_s) {
|
||||
switch(req->action) {
|
||||
case UDPT_ACT_CONNECT:
|
||||
A2_LOG_INFO(fmt("UDPT resend CONNECT to %s:%u transaction_id=%u",
|
||||
|
@ -396,7 +396,7 @@ struct TimeoutCheck {
|
|||
return false;
|
||||
}
|
||||
} else {
|
||||
if(t >= std::chrono::minutes(1)) {
|
||||
if(t >= 1_min) {
|
||||
switch(req->action) {
|
||||
case UDPT_ACT_CONNECT:
|
||||
A2_LOG_INFO(fmt("UDPT timeout CONNECT to %s:%u transaction_id=%u",
|
||||
|
@ -475,7 +475,7 @@ UDPTrackerConnection* UDPTrackerClient::getConnectionId
|
|||
return nullptr;
|
||||
}
|
||||
if((*i).second.state == UDPT_CST_CONNECTED &&
|
||||
(*i).second.lastUpdated.difference(now) > std::chrono::minutes(1)) {
|
||||
(*i).second.lastUpdated.difference(now) > 1_min) {
|
||||
connectionIdCache_.erase(i);
|
||||
return nullptr;
|
||||
} else {
|
||||
|
|
|
@ -65,7 +65,7 @@ void UTMetadataRequestTracker::remove(size_t index)
|
|||
}
|
||||
|
||||
namespace {
|
||||
constexpr auto TIMEOUT = std::chrono::seconds(20);
|
||||
constexpr auto TIMEOUT = 20_s;
|
||||
} // namespace
|
||||
|
||||
std::vector<size_t> UTMetadataRequestTracker::removeTimeoutEntry()
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "a2time.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -120,7 +121,7 @@ public:
|
|||
return maxDroppedPeer_;
|
||||
}
|
||||
|
||||
constexpr static auto DEFAULT_INTERVAL = std::chrono::minutes(1);
|
||||
constexpr static auto DEFAULT_INTERVAL = 1_min;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -70,7 +70,7 @@ WatchProcessCommand::WatchProcessCommand
|
|||
DownloadEngine* e,
|
||||
unsigned int pid,
|
||||
bool forceHalt)
|
||||
: TimeBasedCommand(cuid, e, std::chrono::seconds(1), true),
|
||||
: TimeBasedCommand(cuid, e, 1_s, true),
|
||||
pid_(pid),
|
||||
forceHalt_(forceHalt)
|
||||
{}
|
||||
|
|
|
@ -290,8 +290,8 @@ void WebSocketSession::addTextMessage(const std::string& msg, bool delayed)
|
|||
auto e = getDownloadEngine();
|
||||
auto cuid = command_->getCuid();
|
||||
auto c = make_unique<TextMessageCommand>(cuid, command_->getSession(), msg);
|
||||
e->addCommand(make_unique<DelayedCommand>(cuid, e, std::chrono::seconds(1),
|
||||
std::move(c), false));
|
||||
e->addCommand(
|
||||
make_unique<DelayedCommand>(cuid, e, 1_s, std::move(c), false));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
#include "A2STR.h"
|
||||
|
||||
|
@ -187,6 +188,26 @@ make_unique(size_t size)
|
|||
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
|
||||
}
|
||||
|
||||
constexpr std::chrono::hours operator"" _h(unsigned long long h)
|
||||
{
|
||||
return std::chrono::hours(h);
|
||||
}
|
||||
|
||||
constexpr std::chrono::minutes operator"" _min(unsigned long long min)
|
||||
{
|
||||
return std::chrono::minutes(min);
|
||||
}
|
||||
|
||||
constexpr std::chrono::seconds operator"" _s(unsigned long long s)
|
||||
{
|
||||
return std::chrono::seconds(s);
|
||||
}
|
||||
|
||||
constexpr std::chrono::milliseconds operator"" _ms(unsigned long long ms)
|
||||
{
|
||||
return std::chrono::milliseconds(ms);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_A2_FUNCTIONAL_H
|
||||
|
|
|
@ -43,7 +43,7 @@ void DHTMessageTrackerEntryTest::testMatch()
|
|||
DHTMessageTrackerEntry entry(msg1->getRemoteNode(),
|
||||
msg1->getTransactionID(),
|
||||
msg1->getMessageType(),
|
||||
std::chrono::seconds(30));
|
||||
30_s);
|
||||
|
||||
CPPUNIT_ASSERT(entry.match(msg1->getTransactionID(),
|
||||
msg1->getRemoteNode()->getIPAddress(),
|
||||
|
|
|
@ -40,7 +40,7 @@ void DHTPeerAnnounceEntryTest::testRemoveStalePeerAddrEntry()
|
|||
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.3", 6883));
|
||||
entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.4", 6884, Timer::zero()));
|
||||
|
||||
entry.removeStalePeerAddrEntry(std::chrono::seconds(10));
|
||||
entry.removeStalePeerAddrEntry(10_s);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, entry.countPeerAddrEntry());
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing()
|
|||
CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(index));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
||||
|
||||
btMessageDispatcher->setRequestTimeout(std::chrono::minutes(1));
|
||||
btMessageDispatcher->setRequestTimeout(1_min);
|
||||
btMessageDispatcher->addOutstandingRequest
|
||||
(make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0, piece));
|
||||
|
||||
|
@ -228,7 +228,7 @@ testCheckRequestSlotAndDoNecessaryThing_timeout() {
|
|||
CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(index));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
||||
|
||||
btMessageDispatcher->setRequestTimeout(std::chrono::minutes(1));
|
||||
btMessageDispatcher->setRequestTimeout(1_min);
|
||||
auto slot = make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0, piece);
|
||||
// make this slot timeout
|
||||
slot->setDispatchedTime(Timer::zero());
|
||||
|
@ -247,7 +247,7 @@ void DefaultBtMessageDispatcherTest::
|
|||
testCheckRequestSlotAndDoNecessaryThing_completeBlock() {
|
||||
auto piece = std::make_shared<Piece>(0, MY_PIECE_LENGTH);
|
||||
piece->completeBlock(0);
|
||||
btMessageDispatcher->setRequestTimeout(std::chrono::minutes(1));
|
||||
btMessageDispatcher->setRequestTimeout(1_min);
|
||||
btMessageDispatcher->addOutstandingRequest
|
||||
(make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0, piece));
|
||||
|
||||
|
|
|
@ -915,7 +915,7 @@ void RpcMethodTest::testGatherStoppedDownload()
|
|||
d->fileEntries = fileEntries;
|
||||
d->inMemoryDownload = false;
|
||||
d->sessionDownloadLength = UINT64_MAX;
|
||||
d->sessionTime = std::chrono::seconds(1);
|
||||
d->sessionTime = 1_s;
|
||||
d->result = error_code::FINISHED;
|
||||
d->followedBy = followedBy;
|
||||
d->belongsTo = 2;
|
||||
|
|
|
@ -159,7 +159,7 @@ void ServerStatManTest::testRemoveStaleServerStat()
|
|||
CPPUNIT_ASSERT(ssm.add(localhost_ftp));
|
||||
CPPUNIT_ASSERT(ssm.add(mirror));
|
||||
|
||||
ssm.removeStaleServerStat(std::chrono::hours(24));
|
||||
ssm.removeStaleServerStat(24_h);
|
||||
|
||||
CPPUNIT_ASSERT(ssm.find("localhost", "http"));
|
||||
CPPUNIT_ASSERT(!ssm.find("localhost", "ftp"));
|
||||
|
|
|
@ -21,12 +21,12 @@ public:
|
|||
CPPUNIT_TEST_SUITE_REGISTRATION(TimeSeedCriteriaTest);
|
||||
|
||||
void TimeSeedCriteriaTest::testEvaluate() {
|
||||
TimeSeedCriteria cri(std::chrono::seconds(1));
|
||||
TimeSeedCriteria cri(1_s);
|
||||
global::wallclock().reset();
|
||||
global::wallclock().advance(std::chrono::seconds(2));
|
||||
global::wallclock().advance(2_s);
|
||||
CPPUNIT_ASSERT(cri.evaluate());
|
||||
cri.reset();
|
||||
cri.setDuration(std::chrono::seconds(10));
|
||||
cri.setDuration(10_s);
|
||||
CPPUNIT_ASSERT(!cri.evaluate());
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ void UDPTrackerClientTest::testConnectFollowedByAnnounce()
|
|||
req4->infohash = "bittorrent-infohash4";
|
||||
tr.addRequest(req4);
|
||||
Timer future = now;
|
||||
future.advance(std::chrono::hours(1));
|
||||
future.advance(1_h);
|
||||
rv = tr.createRequest(data, sizeof(data), remoteAddr, remotePort,
|
||||
future);
|
||||
// connection ID is stale because of the timeout
|
||||
|
@ -384,7 +384,7 @@ void UDPTrackerClientTest::testTimeout()
|
|||
CPPUNIT_ASSERT_EQUAL((int)UDPT_ACT_CONNECT,
|
||||
(int)bittorrent::getIntParam(data, 8));
|
||||
tr.requestSent(now);
|
||||
now.advance(std::chrono::seconds(20));
|
||||
now.advance(20_s);
|
||||
// 15 seconds 1st stage timeout passed
|
||||
tr.handleTimeout(now);
|
||||
CPPUNIT_ASSERT(tr.getConnectRequests().empty());
|
||||
|
@ -396,7 +396,7 @@ void UDPTrackerClientTest::testTimeout()
|
|||
CPPUNIT_ASSERT_EQUAL((int)UDPT_ACT_CONNECT,
|
||||
(int)bittorrent::getIntParam(data, 8));
|
||||
tr.requestSent(now);
|
||||
now.advance(std::chrono::seconds(65));
|
||||
now.advance(65_s);
|
||||
// 60 seconds 2nd stage timeout passed
|
||||
tr.handleTimeout(now);
|
||||
CPPUNIT_ASSERT(tr.getConnectRequests().empty());
|
||||
|
@ -428,7 +428,7 @@ void UDPTrackerClientTest::testTimeout()
|
|||
CPPUNIT_ASSERT_EQUAL((int)UDPT_ACT_ANNOUNCE,
|
||||
(int)bittorrent::getIntParam(data, 8));
|
||||
tr.requestSent(now);
|
||||
now.advance(std::chrono::seconds(20));
|
||||
now.advance(20_s);
|
||||
// 15 seconds 1st stage timeout passed
|
||||
tr.handleTimeout(now);
|
||||
CPPUNIT_ASSERT(tr.getConnectRequests().empty());
|
||||
|
@ -439,7 +439,7 @@ void UDPTrackerClientTest::testTimeout()
|
|||
CPPUNIT_ASSERT_EQUAL((int)UDPT_ACT_ANNOUNCE,
|
||||
(int)bittorrent::getIntParam(data, 8));
|
||||
tr.requestSent(now);
|
||||
now.advance(std::chrono::seconds(65));
|
||||
now.advance(65_s);
|
||||
// 60 seconds 2nd stage timeout passed
|
||||
tr.handleTimeout(now);
|
||||
CPPUNIT_ASSERT(tr.getConnectRequests().empty());
|
||||
|
|
|
@ -246,7 +246,7 @@ void UTPexExtensionMessageTest::testAddFreshPeer()
|
|||
std::shared_ptr<Peer> p1(new Peer("192.168.0.1", 6881));
|
||||
CPPUNIT_ASSERT(msg.addFreshPeer(p1));
|
||||
std::shared_ptr<Peer> p2(new Peer("10.1.1.2", 9999));
|
||||
p2->setFirstContactTime(Timer(Timer().getTime() - std::chrono::seconds(61)));
|
||||
p2->setFirstContactTime(Timer(Timer().getTime() - 61_s));
|
||||
CPPUNIT_ASSERT(!msg.addFreshPeer(p2));
|
||||
std::shared_ptr<Peer> p3(new Peer("10.1.1.3", 9999, true));
|
||||
CPPUNIT_ASSERT(!msg.addFreshPeer(p3));
|
||||
|
|
Loading…
Reference in New Issue