diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 884fa037..687e7881 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -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> usedHosts; if (getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) { diff --git a/src/AbstractHttpServerResponseCommand.cc b/src/AbstractHttpServerResponseCommand.cc index 07ae91be..057e74fa 100644 --- a/src/AbstractHttpServerResponseCommand.cc +++ b/src/AbstractHttpServerResponseCommand.cc @@ -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())); diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc index 3c9c8b3a..ebe7bd0b 100644 --- a/src/AdaptiveURISelector.cc +++ b/src/AdaptiveURISelector.cc @@ -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) diff --git a/src/BtAnnounce.cc b/src/BtAnnounce.cc index 1d77e4d6..7f1cce2b 100644 --- a/src/BtAnnounce.cc +++ b/src/BtAnnounce.cc @@ -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 diff --git a/src/BtAnnounce.h b/src/BtAnnounce.h index 2ee2131f..21688bb7 100644 --- a/src/BtAnnounce.h +++ b/src/BtAnnounce.h @@ -41,6 +41,7 @@ #include #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 diff --git a/src/BtLeecherStateChoke.cc b/src/BtLeecherStateChoke.cc index aab46561..a7ddd58f 100644 --- a/src/BtLeecherStateChoke.cc +++ b/src/BtLeecherStateChoke.cc @@ -56,9 +56,9 @@ BtLeecherStateChoke::PeerEntry::PeerEntry(const std::shared_ptr& 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) { } diff --git a/src/BtSeederStateChoke.cc b/src/BtSeederStateChoke.cc index 4e7c610f..c192f896 100644 --- a/src/BtSeederStateChoke.cc +++ b/src/BtSeederStateChoke.cc @@ -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 diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 7e9ec591..4cf4a6b5 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -126,8 +126,7 @@ void BtSetup::setup(std::vector>& commands, } { auto c = make_unique( - 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); diff --git a/src/BtStopDownloadCommand.cc b/src/BtStopDownloadCommand.cc index ba3ebcaf..74b3b89d 100644 --- a/src/BtStopDownloadCommand.cc +++ b/src/BtStopDownloadCommand.cc @@ -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)) {} diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index d90e6284..a633469e 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -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(); diff --git a/src/DHTConstants.h b/src/DHTConstants.h index a59b1db7..8d84046c 100644 --- a/src/DHTConstants.h +++ b/src/DHTConstants.h @@ -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 diff --git a/src/DHTGetPeersCommand.cc b/src/DHTGetPeersCommand.cc index c992ae1b..da52ce8e 100644 --- a/src/DHTGetPeersCommand.cc +++ b/src/DHTGetPeersCommand.cc @@ -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; diff --git a/src/DHTMessageDispatcherImpl.cc b/src/DHTMessageDispatcherImpl.cc index 027fb2ae..9f4a92c5 100644 --- a/src/DHTMessageDispatcherImpl.cc +++ b/src/DHTMessageDispatcherImpl.cc @@ -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)); } } diff --git a/src/DHTSetup.cc b/src/DHTSetup.cc index d369d935..64dbd596 100644 --- a/src/DHTSetup.cc +++ b/src/DHTSetup.cc @@ -235,7 +235,7 @@ std::vector> DHTSetup::setup } { auto command = make_unique(e->newCUID(), e, family, - std::chrono::minutes(30)); + 30_min); command->setLocalNode(localNode); command->setRoutingTable(routingTable.get()); tempCommands.push_back(std::move(command)); diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index 34042525..a32b1905 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -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), diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index 24dbbd78..fc640e91 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -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(); } diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index f320994b..b3cade14 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -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) 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; diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 377befe2..522c1b2e 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -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) @@ -312,8 +312,7 @@ void DownloadEngine::poolSocket(const std::string& key, std::multimap::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 newPool; diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index f6febb29..749092a2 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -269,24 +269,24 @@ public: const std::string& proxyhost, uint16_t proxyport, const std::shared_ptr& 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, const std::string& username, const std::shared_ptr& proxyRequest, const std::shared_ptr& 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& sock, - std::chrono::seconds timeout = std::chrono::seconds(15)); + std::chrono::seconds timeout = 15_s); void poolSocket(const std::shared_ptr& request, const std::shared_ptr& proxyRequest, const std::shared_ptr& socket, - std::chrono::seconds timeout = std::chrono::seconds(15)); + std::chrono::seconds timeout = 15_s); std::shared_ptr popPooledSocket (const std::string& ipaddr, diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index fe87507c..6f07c2f6 100644 --- a/src/DownloadEngineFactory.cc +++ b/src/DownloadEngineFactory.cc @@ -175,8 +175,8 @@ DownloadEngineFactory::newDownloadEngine e->newCUID(), e.get(), std::chrono::seconds(op->getAsInt(PREF_SAVE_SESSION_INTERVAL)))); } - e->addRoutineCommand(make_unique - (e->newCUID(), e.get(), std::chrono::seconds(10))); + e->addRoutineCommand( + make_unique(e->newCUID(), e.get(), 10_s)); { auto stopSec = op->getAsInt(PREF_STOP); if(stopSec > 0) { diff --git a/src/FileEntry.cc b/src/FileEntry.cc index 2ab1291c..35b660e8 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -214,7 +214,7 @@ FileEntry::getRequest } namespace { -constexpr auto startupIdleTime = std::chrono::seconds(10); +constexpr auto startupIdleTime = 10_s; } // namespace std::shared_ptr diff --git a/src/HaveEraseCommand.cc b/src/HaveEraseCommand.cc index ceca170e..b158c7eb 100644 --- a/src/HaveEraseCommand.cc +++ b/src/HaveEraseCommand.cc @@ -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); } } } diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index 7fb715c2..dea078a5 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -149,7 +149,7 @@ void HttpServerBodyCommand::addHttpServerResponseCommand(bool delayed) make_unique(getCuid(), httpServer_, e_, socket_); if (delayed) { e_->addCommand(make_unique( - 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 { diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc index f2fdb137..bab3ab29 100644 --- a/src/HttpServerCommand.cc +++ b/src/HttpServerCommand.cc @@ -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 { diff --git a/src/LpdMessageDispatcher.h b/src/LpdMessageDispatcher.h index 42cac417..868f3671 100644 --- a/src/LpdMessageDispatcher.h +++ b/src/LpdMessageDispatcher.h @@ -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(); diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index d43f4af3..cb23c9d7 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -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 diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index cdd51375..f8a043b1 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -1306,8 +1306,8 @@ std::unique_ptr goingShutdown { // Schedule shutdown after 3seconds to give time to client to // receive RPC response. - e->addRoutineCommand(make_unique( - e->newCUID(), e, std::chrono::seconds(3), forceHalt)); + e->addRoutineCommand( + make_unique(e->newCUID(), e, 3_s, forceHalt)); A2_LOG_INFO("Scheduled shutdown in 3 seconds."); return createOKResponse(); } diff --git a/src/SpeedCalc.cc b/src/SpeedCalc.cc index 4416c2af..c1ce3492 100644 --- a/src/SpeedCalc.cc +++ b/src/SpeedCalc.cc @@ -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( - 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; diff --git a/src/TimerA2.cc b/src/TimerA2.cc index 7c16ba9d..a07a16be 100644 --- a/src/TimerA2.cc +++ b/src/TimerA2.cc @@ -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_; diff --git a/src/TimerA2.h b/src/TimerA2.h index 3ca4722c..e229dcd7 100644 --- a/src/TimerA2.h +++ b/src/TimerA2.h @@ -40,6 +40,7 @@ #include #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_; diff --git a/src/UDPTrackerClient.cc b/src/UDPTrackerClient.cc index 41e52f37..11f39add 100644 --- a/src/UDPTrackerClient.cc +++ b/src/UDPTrackerClient.cc @@ -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 { diff --git a/src/UTMetadataRequestTracker.cc b/src/UTMetadataRequestTracker.cc index 0b517568..cbb20806 100644 --- a/src/UTMetadataRequestTracker.cc +++ b/src/UTMetadataRequestTracker.cc @@ -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 UTMetadataRequestTracker::removeTimeoutEntry() diff --git a/src/UTPexExtensionMessage.h b/src/UTPexExtensionMessage.h index 90eff9be..2bdae529 100644 --- a/src/UTPexExtensionMessage.h +++ b/src/UTPexExtensionMessage.h @@ -42,6 +42,7 @@ #include #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 diff --git a/src/WatchProcessCommand.cc b/src/WatchProcessCommand.cc index f3fa4923..6c58d59d 100644 --- a/src/WatchProcessCommand.cc +++ b/src/WatchProcessCommand.cc @@ -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) {} diff --git a/src/WebSocketSession.cc b/src/WebSocketSession.cc index 83a3f7f9..d51e789c 100644 --- a/src/WebSocketSession.cc +++ b/src/WebSocketSession.cc @@ -290,8 +290,8 @@ void WebSocketSession::addTextMessage(const std::string& msg, bool delayed) auto e = getDownloadEngine(); auto cuid = command_->getCuid(); auto c = make_unique(cuid, command_->getSession(), msg); - e->addCommand(make_unique(cuid, e, std::chrono::seconds(1), - std::move(c), false)); + e->addCommand( + make_unique(cuid, e, 1_s, std::move(c), false)); return; } diff --git a/src/a2functional.h b/src/a2functional.h index ce419f41..ff0bcb95 100644 --- a/src/a2functional.h +++ b/src/a2functional.h @@ -41,6 +41,7 @@ #include #include #include +#include #include "A2STR.h" @@ -187,6 +188,26 @@ make_unique(size_t size) return std::unique_ptr(new typename std::remove_extent::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 diff --git a/test/DHTMessageTrackerEntryTest.cc b/test/DHTMessageTrackerEntryTest.cc index 316e1e25..67147e66 100644 --- a/test/DHTMessageTrackerEntryTest.cc +++ b/test/DHTMessageTrackerEntryTest.cc @@ -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(), diff --git a/test/DHTPeerAnnounceEntryTest.cc b/test/DHTPeerAnnounceEntryTest.cc index 2d518bce..c2531d52 100644 --- a/test/DHTPeerAnnounceEntryTest.cc +++ b/test/DHTPeerAnnounceEntryTest.cc @@ -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()); diff --git a/test/DefaultBtMessageDispatcherTest.cc b/test/DefaultBtMessageDispatcherTest.cc index 5d49756a..ce792af7 100644 --- a/test/DefaultBtMessageDispatcherTest.cc +++ b/test/DefaultBtMessageDispatcherTest.cc @@ -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(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(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(0, MY_PIECE_LENGTH); piece->completeBlock(0); - btMessageDispatcher->setRequestTimeout(std::chrono::minutes(1)); + btMessageDispatcher->setRequestTimeout(1_min); btMessageDispatcher->addOutstandingRequest (make_unique(0, 0, MY_PIECE_LENGTH, 0, piece)); diff --git a/test/RpcMethodTest.cc b/test/RpcMethodTest.cc index 96127ee4..a85c0119 100644 --- a/test/RpcMethodTest.cc +++ b/test/RpcMethodTest.cc @@ -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; diff --git a/test/ServerStatManTest.cc b/test/ServerStatManTest.cc index e87805e4..dd5bab15 100644 --- a/test/ServerStatManTest.cc +++ b/test/ServerStatManTest.cc @@ -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")); diff --git a/test/TimeSeedCriteriaTest.cc b/test/TimeSeedCriteriaTest.cc index aa751b26..2b6a124f 100644 --- a/test/TimeSeedCriteriaTest.cc +++ b/test/TimeSeedCriteriaTest.cc @@ -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()); } diff --git a/test/UDPTrackerClientTest.cc b/test/UDPTrackerClientTest.cc index f3604aef..423032a8 100644 --- a/test/UDPTrackerClientTest.cc +++ b/test/UDPTrackerClientTest.cc @@ -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()); diff --git a/test/UTPexExtensionMessageTest.cc b/test/UTPexExtensionMessageTest.cc index 9cf87690..cdb4910a 100644 --- a/test/UTPexExtensionMessageTest.cc +++ b/test/UTPexExtensionMessageTest.cc @@ -246,7 +246,7 @@ void UTPexExtensionMessageTest::testAddFreshPeer() std::shared_ptr p1(new Peer("192.168.0.1", 6881)); CPPUNIT_ASSERT(msg.addFreshPeer(p1)); std::shared_ptr 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 p3(new Peer("10.1.1.3", 9999, true)); CPPUNIT_ASSERT(!msg.addFreshPeer(p3));