summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-06-21 17:33:23 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-06-21 17:33:23 +0900
commitf5ff5da9daa659f651710fa557d0973356fa84d6 (patch)
treec95fc7beec6a9e60f3d6854686848f006d139934
parent95f2c00c71cff5c0b649f635185c3845773e763e (diff)
Use constexpr for macros defined in BtConstants.h
-rw-r--r--src/BtConstants.h29
-rw-r--r--src/bittorrent_helper.cc4
-rw-r--r--src/bittorrent_helper.h2
-rw-r--r--test/BittorrentHelperTest.cc6
4 files changed, 20 insertions, 21 deletions
diff --git a/src/BtConstants.h b/src/BtConstants.h
index 609f8f7e..12268664 100644
--- a/src/BtConstants.h
+++ b/src/BtConstants.h
@@ -36,33 +36,32 @@
#define D_BT_CONSTANTS_H
#include "common.h"
-#include <vector>
-#define INFO_HASH_LENGTH 20
+namespace aria2 {
-#define PIECE_HASH_LENGTH 20
+constexpr size_t INFO_HASH_LENGTH = 20;
-#define PEER_ID_LENGTH 20
+constexpr size_t PIECE_HASH_LENGTH = 20;
-#define INFO_HASH_LENGTH 20
+constexpr size_t PEER_ID_LENGTH = 20;
-#define MAX_BLOCK_LENGTH (16*1024)
+constexpr size_t MAX_BLOCK_LENGTH = 16 * 1024;
-#define DEFAULT_MAX_OUTSTANDING_REQUEST 6
-
-#define OUTSTANDING_REQUEST_STEP 6
+constexpr size_t DEFAULT_MAX_OUTSTANDING_REQUEST = 6;
// Upper Bound of the number of outstanding request
-#define UB_MAX_OUTSTANDING_REQUEST 256
+constexpr size_t UB_MAX_OUTSTANDING_REQUEST = 256;
+
+constexpr size_t METADATA_PIECE_SIZE = 16 * 1024;
-#define METADATA_PIECE_SIZE (16*1024)
+constexpr const char LPD_MULTICAST_ADDR[] = "239.192.152.143";
-#define LPD_MULTICAST_ADDR "239.192.152.143"
+constexpr uint16_t LPD_MULTICAST_PORT = 6771;
-#define LPD_MULTICAST_PORT 6771
+constexpr size_t COMPACT_LEN_IPV4 = 6;
-#define COMPACT_LEN_IPV4 6
+constexpr size_t COMPACT_LEN_IPV6 = 18;
-#define COMPACT_LEN_IPV6 18
+} // namespace aria2
#endif // D_BT_CONSTANTS_H
diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc
index 001f6275..77bbd457 100644
--- a/src/bittorrent_helper.cc
+++ b/src/bittorrent_helper.cc
@@ -794,7 +794,7 @@ void checkLength(int32_t length)
{
if(length > MAX_BLOCK_LENGTH) {
throw DL_ABORT_EX
- (fmt("Length too long: %d > %dKB", length, MAX_BLOCK_LENGTH/1024));
+ (fmt("Length too long: %d > %luKB", length, MAX_BLOCK_LENGTH/1024));
}
if(length == 0) {
throw DL_ABORT_EX(fmt("Invalid length: %d", length));
@@ -855,7 +855,7 @@ void createPeerMessageString
msg[4] = messageId;
}
-int packcompact
+size_t packcompact
(unsigned char* compact, const std::string& addr, uint16_t port)
{
size_t len = net::getBinAddr(compact, addr);
diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h
index 0462b380..c4dc94e1 100644
--- a/src/bittorrent_helper.h
+++ b/src/bittorrent_helper.h
@@ -213,7 +213,7 @@ void createPeerMessageString
* pre-allocated. Returns the number of written bytes; for IPv4
* address, it is 6 and for IPv6, it is 18. On failure, returns 0.
*/
-int packcompact
+size_t packcompact
(unsigned char* compact, const std::string& addr, uint16_t port);
/**
diff --git a/test/BittorrentHelperTest.cc b/test/BittorrentHelperTest.cc
index 2b6a7608..24f84c51 100644
--- a/test/BittorrentHelperTest.cc
+++ b/test/BittorrentHelperTest.cc
@@ -886,17 +886,17 @@ void BittorrentHelperTest::testExtract2PeersFromList()
void BittorrentHelperTest::testPackcompact()
{
unsigned char compact[COMPACT_LEN_IPV6];
- CPPUNIT_ASSERT_EQUAL(18,
+ CPPUNIT_ASSERT_EQUAL((size_t)18,
packcompact(compact,
"1002:1035:4527:3546:7854:1237:3247:3217",
6881));
CPPUNIT_ASSERT_EQUAL(std::string("100210354527354678541237324732171ae1"),
util::toHex(compact, 18));
- CPPUNIT_ASSERT_EQUAL(6, packcompact(compact, "192.168.0.1", 6881));
+ CPPUNIT_ASSERT_EQUAL((size_t)6, packcompact(compact, "192.168.0.1", 6881));
CPPUNIT_ASSERT_EQUAL(std::string("c0a800011ae1"), util::toHex(compact, 6));
- CPPUNIT_ASSERT_EQUAL(0, packcompact(compact, "badaddr", 6881));
+ CPPUNIT_ASSERT_EQUAL((size_t)0, packcompact(compact, "badaddr", 6881));
}
void BittorrentHelperTest::testUnpackcompact()