diff options
-rw-r--r-- | examples/network/torrent/peerwireclient.cpp | 12 | ||||
-rw-r--r-- | examples/network/torrent/torrentclient.cpp | 5 | ||||
-rw-r--r-- | examples/network/torrent/trackerclient.cpp | 2 | ||||
-rw-r--r-- | examples/network/torrent/trackerclient.h | 1 |
4 files changed, 11 insertions, 9 deletions
diff --git a/examples/network/torrent/peerwireclient.cpp b/examples/network/torrent/peerwireclient.cpp index 56feec5959..f6f81215a1 100644 --- a/examples/network/torrent/peerwireclient.cpp +++ b/examples/network/torrent/peerwireclient.cpp @@ -7,11 +7,13 @@ #include <QTimerEvent> #include <QtEndian> -static const int PendingRequestTimeout = 60 * 1000; -static const int ClientTimeout = 120 * 1000; -static const int ConnectTimeout = 60 * 1000; -static const int KeepAliveInterval = 30 * 1000; -static const int PeerRateControlTimerDelay = 2000; +#include <chrono> + +static constexpr std::chrono::seconds PendingRequestTimeout(60); +static constexpr std::chrono::seconds ClientTimeout(120); +static constexpr std::chrono::seconds ConnectTimeout(60); +static constexpr std::chrono::seconds KeepAliveInterval(30); +static constexpr std::chrono::seconds PeerRateControlTimerDelay(2); static const int MinimalHeaderSize = 48; static const char ProtocolId[] = "BitTorrent protocol"; static const char ProtocolIdSize = 19; diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index 6fefb3855c..4ae1debcb3 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -14,6 +14,7 @@ #include <QNetworkInterface> #include <algorithm> +#include <chrono> // These constants could also be configurable by the user. static const int ServerMinPort = 6881; @@ -23,10 +24,10 @@ static const int MaxBlocksInProgress = 5; static const int MaxBlocksInMultiMode = 2; static const int MaxConnectionPerPeer = 1; static const int RateControlWindowLength = 10; -static const int RateControlTimerDelay = 1000; +static const std::chrono::seconds RateControlTimerDelay(1); static const int MinimumTimeBeforeRevisit = 30; static const int MaxUploads = 4; -static const int UploadScheduleInterval = 10000; +static const std::chrono::seconds UploadScheduleInterval(10); struct TorrentPiece { QBitArray completedBlocks; diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index 77a4577074..12110ba0ae 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -153,7 +153,7 @@ void TrackerClient::httpRequestDone(QNetworkReply *reply) // Mandatory item if (requestIntervalTimer != -1) killTimer(requestIntervalTimer); - requestIntervalTimer = startTimer(dict.value("interval").toInt() * 1000); + requestIntervalTimer = startTimer(std::chrono::seconds(dict.value("interval").toInt())); } if (dict.contains("peers")) { diff --git a/examples/network/torrent/trackerclient.h b/examples/network/torrent/trackerclient.h index 63368ec499..334ce42332 100644 --- a/examples/network/torrent/trackerclient.h +++ b/examples/network/torrent/trackerclient.h @@ -51,7 +51,6 @@ private slots: private: TorrentClient *torrentDownloader; - int requestInterval = 5 * 60; int requestIntervalTimer = -1; QNetworkAccessManager http; MetaInfo metaInfo; |