summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-07-21 08:56:16 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-07-21 08:56:16 +0000
commit6574e44f886740273676b6d73ef754385a36197f (patch)
treec13b2c6f1bb178bc5adae67f47549ea6a86d7ec4 /src
parentcd6b6e359135f88afffbaa31c126489aa9813571 (diff)
2007-07-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Converted int's to in32_t. long long int's are also converted to int64_t
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCommand.cc4
-rw-r--r--src/AbstractCommand.h8
-rw-r--r--src/AnnounceList.cc4
-rw-r--r--src/AnnounceList.h6
-rw-r--r--src/Base64.cc30
-rw-r--r--src/Base64.h10
-rw-r--r--src/BitfieldManFactory.h2
-rw-r--r--src/BtBitfieldMessageValidator.h4
-rw-r--r--src/BtHaveMessageValidator.h4
-rw-r--r--src/BtRequestFactory.h2
-rw-r--r--src/BtRuntime.h16
-rw-r--r--src/BtSuggestPieceMessageValidator.h4
-rw-r--r--src/ByteArrayDiskWriter.cc2
-rw-r--r--src/ByteArrayDiskWriter.h2
-rw-r--r--src/ChunkedEncoding.cc20
-rw-r--r--src/ChunkedEncoding.h20
-rw-r--r--src/Command.cc2
-rw-r--r--src/Command.h10
-rw-r--r--src/CompactPeerListProcessor.cc15
-rw-r--r--src/CompactPeerListProcessor.h6
-rw-r--r--src/ConsoleDownloadEngine.cc25
-rw-r--r--src/ConsoleDownloadEngine.h12
-rw-r--r--src/Data.cc10
-rw-r--r--src/Data.h10
-rw-r--r--src/DefaultBtAnnounce.cc4
-rw-r--r--src/DefaultBtAnnounce.h12
-rw-r--r--src/DefaultBtProgressInfoFile.cc8
-rw-r--r--src/DefaultBtRequestFactory.h2
-rw-r--r--src/DefaultPeerListProcessor.cc6
-rw-r--r--src/DefaultPeerListProcessor.h6
-rw-r--r--src/DefaultPeerStorage.cc8
-rw-r--r--src/DefaultPeerStorage.h14
-rw-r--r--src/DefaultPieceStorage.cc64
-rw-r--r--src/DefaultPieceStorage.h46
-rw-r--r--src/DelegatingPeerListProcessor.h6
-rw-r--r--src/DiskWriter.h5
-rw-r--r--src/DownloadEngine.cc10
-rw-r--r--src/DownloadEngine.h2
-rw-r--r--src/DownloadEngineFactory.cc4
-rw-r--r--src/FeatureConfig.cc6
-rw-r--r--src/FeatureConfig.h4
-rw-r--r--src/File.cc2
-rw-r--r--src/File.h6
-rw-r--r--src/FileEntry.cc4
-rw-r--r--src/FileEntry.h8
-rw-r--r--src/FtpConnection.cc32
-rw-r--r--src/FtpConnection.h16
-rw-r--r--src/FtpNegotiationCommand.cc26
-rw-r--r--src/FtpNegotiationCommand.h4
-rw-r--r--src/HaveEraseCommand.cc4
-rw-r--r--src/HaveEraseCommand.h6
-rw-r--r--src/HttpConnection.cc2
-rw-r--r--src/HttpConnection.h4
-rw-r--r--src/HttpHeader.cc6
-rw-r--r--src/HttpHeader.h4
-rw-r--r--src/HttpRequest.cc2
-rw-r--r--src/HttpRequest.h4
-rw-r--r--src/MetaFileUtil.cc10
-rw-r--r--src/MetaFileUtil.h2
-rw-r--r--src/MetalinkEntry.cc6
-rw-r--r--src/MetalinkEntry.h2
-rw-r--r--src/MetalinkRequestInfo.cc7
-rw-r--r--src/MetalinkResource.h4
-rw-r--r--src/MultiDiskAdaptor.cc2
-rw-r--r--src/MultiDiskAdaptor.h2
-rw-r--r--src/NameResolver.cc4
-rw-r--r--src/NameResolver.h6
-rw-r--r--src/Option.cc6
-rw-r--r--src/Option.h4
-rw-r--r--src/Peer.cc20
-rw-r--r--src/Peer.h52
-rw-r--r--src/PeerAbstractCommand.cc8
-rw-r--r--src/PeerAbstractCommand.h14
-rw-r--r--src/PeerChokeCommand.cc8
-rw-r--r--src/PeerChokeCommand.h8
-rw-r--r--src/PeerInteractionCommand.cc8
-rw-r--r--src/PeerInteractionCommand.h25
-rw-r--r--src/PeerListenCommand.cc12
-rw-r--r--src/PeerListenCommand.h6
-rw-r--r--src/PeerStat.h18
-rw-r--r--src/Piece.cc14
-rw-r--r--src/Piece.h38
-rw-r--r--src/PieceStorage.h24
-rw-r--r--src/Randomizer.h4
-rw-r--r--src/Request.cc4
-rw-r--r--src/Request.h30
-rw-r--r--src/RequestGroupEntry.h6
-rw-r--r--src/RequestSlot.cc2
-rw-r--r--src/RequestSlot.h2
-rw-r--r--src/Segment.h10
-rw-r--r--src/SegmentMan.cc22
-rw-r--r--src/SegmentMan.h14
-rw-r--r--src/ShareRatioSeedCriteria.h2
-rw-r--r--src/SimpleBtMessage.cc4
-rw-r--r--src/SimpleBtMessage.h2
-rw-r--r--src/SimpleLogger.cc6
-rw-r--r--src/SimpleLogger.h8
-rw-r--r--src/SimpleRandomizer.h6
-rw-r--r--src/SleepCommand.cc2
-rw-r--r--src/SleepCommand.h6
-rw-r--r--src/Socket.cc18
-rw-r--r--src/SocketCore.cc62
-rw-r--r--src/SocketCore.h38
-rw-r--r--src/TimeA2.cc12
-rw-r--r--src/TimeA2.h22
-rw-r--r--src/TimeSeedCriteria.h8
-rw-r--r--src/TimeoutException.h6
-rw-r--r--src/TorrentAutoSaveCommand.cc4
-rw-r--r--src/TorrentAutoSaveCommand.h6
-rw-r--r--src/TorrentDownloadEngine.cc4
-rw-r--r--src/TorrentDownloadEngine.h20
-rw-r--r--src/TrackerUpdateCommand.cc4
-rw-r--r--src/TransferEncoding.h2
-rw-r--r--src/UrlRequestInfo.h6
-rw-r--r--src/Util.cc107
-rw-r--r--src/Util.h26
-rw-r--r--src/main.cc8
-rw-r--r--src/messageDigest.h26
118 files changed, 682 insertions, 702 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index af49291f..38a49a01 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -43,7 +43,7 @@
#include "DNSCache.h"
#include "FatalException.h"
-AbstractCommand::AbstractCommand(int cuid,
+AbstractCommand::AbstractCommand(int32_t cuid,
const RequestHandle& req,
RequestGroup* requestGroup,
DownloadEngine* e,
@@ -147,7 +147,7 @@ void AbstractCommand::tryReserved() {
e->addCommand(commands);
}
-bool AbstractCommand::prepareForRetry(int wait) {
+bool AbstractCommand::prepareForRetry(int32_t wait) {
_requestGroup->getSegmentMan()->cancelSegment(cuid);
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, _requestGroup, e);
if(wait == 0) {
diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h
index 7e6bcd7a..89f1d975 100644
--- a/src/AbstractCommand.h
+++ b/src/AbstractCommand.h
@@ -46,7 +46,7 @@
class AbstractCommand : public Command {
private:
Time checkPoint;
- int timeout;
+ int32_t timeout;
protected:
RequestHandle req;
RequestGroup* _requestGroup;
@@ -55,7 +55,7 @@ protected:
SegmentHandle segment;
void tryReserved();
- virtual bool prepareForRetry(int wait);
+ virtual bool prepareForRetry(int32_t wait);
virtual void onAbort(Exception* ex);
virtual bool executeInternal() = 0;
@@ -69,7 +69,7 @@ protected:
void disableNameResolverCheck(const NameResolverHandle& resolver);
virtual bool nameResolveFinished() const;
#endif // ENABLE_ASYNC_DNS
- void setTimeout(int timeout) { this->timeout = timeout; }
+ void setTimeout(int32_t timeout) { this->timeout = timeout; }
private:
bool checkSocketIsReadable;
bool checkSocketIsWritable;
@@ -77,7 +77,7 @@ private:
SocketHandle writeCheckTarget;
bool nameResolverCheck;
public:
- AbstractCommand(int cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e, const SocketHandle& s = SocketHandle());
+ AbstractCommand(int32_t cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e, const SocketHandle& s = SocketHandle());
virtual ~AbstractCommand();
bool execute();
};
diff --git a/src/AnnounceList.cc b/src/AnnounceList.cc
index fbe8025a..a7166252 100644
--- a/src/AnnounceList.cc
+++ b/src/AnnounceList.cc
@@ -176,11 +176,11 @@ public:
}
};
-int AnnounceList::countStoppedAllowedTier() const {
+int32_t AnnounceList::countStoppedAllowedTier() const {
return count_if(tiers.begin(), tiers.end(), FindStoppedAllowedTier());
}
-int AnnounceList::countCompletedAllowedTier() const {
+int32_t AnnounceList::countCompletedAllowedTier() const {
return count_if(tiers.begin(), tiers.end(), FindCompletedAllowedTier());
}
diff --git a/src/AnnounceList.h b/src/AnnounceList.h
index fdd19a49..c0123d67 100644
--- a/src/AnnounceList.h
+++ b/src/AnnounceList.h
@@ -57,7 +57,7 @@ public:
void reconfigure(const MetaEntry* announceListEntry);
void reconfigure(const string& url);
- int countTier() const {
+ int32_t countTier() const {
return tiers.size();
}
@@ -98,12 +98,12 @@ public:
/**
* Counts the number of tiers to which the "stopped" event can be sent.
*/
- int countStoppedAllowedTier() const;
+ int32_t countStoppedAllowedTier() const;
/**
* Counts the number of tiers to which the "completed" event can be sent.
*/
- int countCompletedAllowedTier() const;
+ int32_t countCompletedAllowedTier() const;
/**
* Moves current tier pointer to the tier to which the "stopped" event can
diff --git a/src/Base64.cc b/src/Base64.cc
index 0bf1d575..97d620d0 100644
--- a/src/Base64.cc
+++ b/src/Base64.cc
@@ -45,34 +45,34 @@ static char base64_table[64] = {
'4', '5', '6', '7', '8', '9', '+', '/',
};
-void Base64::part_encode(const unsigned char* sub, int subLength,
+void Base64::part_encode(const unsigned char* sub, int32_t subLength,
unsigned char* buf)
{
- int shift = 2;
+ int32_t shift = 2;
unsigned char carry = 0;
- int index;
+ int32_t index;
for(index = 0; index < subLength; index++) {
unsigned char cur = sub[index] >> shift | carry;
carry = (sub[index] << (6-shift)) & 0x3f;
shift += 2;
- buf[index] = base64_table[(unsigned int)cur];
+ buf[index] = base64_table[(uint32_t)cur];
}
if(subLength == 1) {
- buf[index] = base64_table[(unsigned int)carry];
+ buf[index] = base64_table[(uint32_t)carry];
buf[index+1] = buf[index+2] = '=';
} else if(subLength == 2) {
- buf[index] = base64_table[(unsigned int)carry];
+ buf[index] = base64_table[(uint32_t)carry];
buf[index+1] = '=';
} else {
unsigned char cur = sub[subLength-1] & 0x3f;
- buf[index] = base64_table[(unsigned int)cur];
+ buf[index] = base64_table[(uint32_t)cur];
}
}
string Base64::encode(const string& plainSrc)
{
unsigned char* result = 0;
- int resultLength = 0;
+ int32_t resultLength = 0;
encode((const unsigned char*)plainSrc.c_str(), plainSrc.size(),
result, resultLength);
@@ -81,12 +81,12 @@ string Base64::encode(const string& plainSrc)
return encoded;
}
-void Base64::encode(const unsigned char* src, int srcLength,
- unsigned char*& result, int& resultLength) {
+void Base64::encode(const unsigned char* src, int32_t srcLength,
+ unsigned char*& result, int32_t& resultLength) {
resultLength = (srcLength+(srcLength%3 == 0 ? 0 : 3-srcLength%3))/3*4;
result = new unsigned char[resultLength];
unsigned char* tail = result;
- for(int index = 0; srcLength > index; index += 3) {
+ for(int32_t index = 0; srcLength > index; index += 3) {
unsigned char temp[4];
part_encode(&src[index],
srcLength >= index+3 ? 3 : srcLength-index,
@@ -119,10 +119,10 @@ char Base64::getValue(char ch)
string Base64::part_decode(const string& subCrypted)
{
- int shift = 2;
+ int32_t shift = 2;
string plain;
- for(unsigned int index = 0; index < subCrypted.size()-1; ++index) {
+ for(uint32_t index = 0; index < subCrypted.size()-1; ++index) {
if(subCrypted.at(index) == '=') break;
char cur = getValue(subCrypted.at(index)) << shift;
char carry = getValue(subCrypted.at(index+1)) >> (6-shift);
@@ -136,8 +136,8 @@ string Base64::part_decode(const string& subCrypted)
string Base64::decode(const string& crypted)
{
string plain;
- int sIndex = 0;
- for(int index = 0; crypted.size() > (unsigned int)index; index +=4) {
+ int32_t sIndex = 0;
+ for(int32_t index = 0; crypted.size() > (uint32_t)index; index +=4) {
string subCrypted = crypted.substr(sIndex, 4);
string subPlain = part_decode(subCrypted);
sIndex += 4;
diff --git a/src/Base64.h b/src/Base64.h
index 03636bc9..4d363a66 100644
--- a/src/Base64.h
+++ b/src/Base64.h
@@ -41,7 +41,7 @@ using namespace std;
class Base64
{
private:
- static void part_encode(const unsigned char* sub, int subLength,
+ static void part_encode(const unsigned char* sub, int32_t subLength,
unsigned char* buf);
static string part_encode(const string& subplain);
@@ -50,12 +50,12 @@ private:
public:
static string encode(const string& plain);
// caller must deallocate the memory used by result.
- static void encode(const unsigned char* src, int srcLength,
- unsigned char*& result, int& resultLength);
+ static void encode(const unsigned char* src, int32_t srcLength,
+ unsigned char*& result, int32_t& resultLength);
static string decode(const string& crypted);
// caller must deallocate the memory used by result.
- static void decode(const unsigned char* src, int srcLength,
- unsigned char*& result, int& resultLength);
+ static void decode(const unsigned char* src, int32_t srcLength,
+ unsigned char*& result, int32_t& resultLength);
};
#endif // _BASE64_H_
diff --git a/src/BitfieldManFactory.h b/src/BitfieldManFactory.h
index 8b7d9ca8..dfc86487 100644
--- a/src/BitfieldManFactory.h
+++ b/src/BitfieldManFactory.h
@@ -60,7 +60,7 @@ public:
return factory;
}
- BitfieldMan* createBitfieldMan(int blockLength, long long int totalLength) {
+ BitfieldMan* createBitfieldMan(int32_t blockLength, int64_t totalLength) {
BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength);
bitfieldMan->setRandomizer(randomizer);
return bitfieldMan;
diff --git a/src/BtBitfieldMessageValidator.h b/src/BtBitfieldMessageValidator.h
index d7a8ddb0..6d69d622 100644
--- a/src/BtBitfieldMessageValidator.h
+++ b/src/BtBitfieldMessageValidator.h
@@ -41,10 +41,10 @@
class BtBitfieldMessageValidator : public BtMessageValidator {
private:
const BtBitfieldMessage* message;
- int numPiece;
+ int32_t numPiece;
public:
BtBitfieldMessageValidator(const BtBitfieldMessage* message,
- int numPiece):
+ int32_t numPiece):
message(message),
numPiece(numPiece) {}
diff --git a/src/BtHaveMessageValidator.h b/src/BtHaveMessageValidator.h
index acf2b351..0f7017cf 100644
--- a/src/BtHaveMessageValidator.h
+++ b/src/BtHaveMessageValidator.h
@@ -42,10 +42,10 @@
class BtHaveMessageValidator : public BtMessageValidator {
private:
const BtHaveMessage* message;
- int numPiece;
+ int32_t numPiece;
public:
BtHaveMessageValidator(const BtHaveMessage* message,
- int numPiece):
+ int32_t numPiece):
message(message),
numPiece(numPiece) {}
diff --git a/src/BtRequestFactory.h b/src/BtRequestFactory.h
index d3e17ad3..9cc07fcf 100644
--- a/src/BtRequestFactory.h
+++ b/src/BtRequestFactory.h
@@ -49,7 +49,7 @@ public:
virtual void removeAllTargetPiece() = 0;
- virtual int countTargetPiece() = 0;
+ virtual int32_t countTargetPiece() = 0;
virtual void removeCompletedPiece() = 0;
diff --git a/src/BtRuntime.h b/src/BtRuntime.h
index 7c2313e7..4e1b7892 100644
--- a/src/BtRuntime.h
+++ b/src/BtRuntime.h
@@ -42,10 +42,10 @@
class BtRuntime {
private:
- long long int uploadLengthAtStartup;
- int port;
+ int64_t uploadLengthAtStartup;
+ int32_t port;
bool halt;
- int connections;
+ int32_t connections;
public:
BtRuntime():
uploadLengthAtStartup(0),
@@ -55,19 +55,19 @@ public:
{}
~BtRuntime() {}
- long long int getUploadLengthAtStartup() const {
+ int64_t getUploadLengthAtStartup() const {
return uploadLengthAtStartup;
}
- void setUploadLengthAtStartup(long long int length) {
+ void setUploadLengthAtStartup(int64_t length) {
this->uploadLengthAtStartup = length;
}
- void setListenPort(int port) {
+ void setListenPort(int32_t port) {
this->port = port;
}
- int getListenPort() const { return port; }
+ int32_t getListenPort() const { return port; }
bool isHalt() const { return halt; }
@@ -75,7 +75,7 @@ public:
this->halt = halt;
}
- int getConnections() const { return connections; }
+ int32_t getConnections() const { return connections; }
void increaseConnections() { connections++; }
diff --git a/src/BtSuggestPieceMessageValidator.h b/src/BtSuggestPieceMessageValidator.h
index 293b3c71..4274f1de 100644
--- a/src/BtSuggestPieceMessageValidator.h
+++ b/src/BtSuggestPieceMessageValidator.h
@@ -41,10 +41,10 @@
class BtSuggestPieceMessageValidator : public BtMessageValidator {
private:
const BtSuggestPieceMessage* message;
- int numPiece;
+ int32_t numPiece;
public:
BtSuggestPieceMessageValidator(const BtSuggestPieceMessage* message,
- int numPiece):
+ int32_t numPiece):
message(message),
numPiece(numPiece) {}
diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc
index 2a71ed38..dc284160 100644
--- a/src/ByteArrayDiskWriter.cc
+++ b/src/ByteArrayDiskWriter.cc
@@ -77,7 +77,7 @@ void ByteArrayDiskWriter::writeData(const char* data, int32_t dataLength, int64_
buf.write(data, dataLength);
}
-int ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) {
+int32_t ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) {
buf.seekg(position, ios_base::beg);
buf.read(data, len);
// TODO we have to call buf.clear() here? YES
diff --git a/src/ByteArrayDiskWriter.h b/src/ByteArrayDiskWriter.h
index 4e60bcda..227cac74 100644
--- a/src/ByteArrayDiskWriter.h
+++ b/src/ByteArrayDiskWriter.h
@@ -57,7 +57,7 @@ public:
// position is ignored
virtual void writeData(const char* data, int32_t len, int64_t position = 0);
- virtual int readData(char* data, int32_t len, int64_t position);
+ virtual int32_t readData(char* data, int32_t len, int64_t position);
// Not implemented yet
virtual void truncate(int64_t length) {}
diff --git a/src/ChunkedEncoding.cc b/src/ChunkedEncoding.cc
index 31522378..b66439a4 100644
--- a/src/ChunkedEncoding.cc
+++ b/src/ChunkedEncoding.cc
@@ -64,10 +64,10 @@ bool ChunkedEncoding::finished() {
void ChunkedEncoding::end() {}
-void ChunkedEncoding::inflate(char* outbuf, int& outlen, const char* inbuf, int inlen) {
+void ChunkedEncoding::inflate(char* outbuf, int32_t& outlen, const char* inbuf, int32_t inlen) {
addBuffer(inbuf, inlen);
char* p = strbuf;
- int clen = 0;
+ int32_t clen = 0;
while(1) {
if(state == READ_SIZE) {
if(readChunkSize(&p) == 0) {
@@ -98,7 +98,7 @@ void ChunkedEncoding::inflate(char* outbuf, int& outlen, const char* inbuf, int
strbufTail = strbuf;
} else {
// copy string between [p, strbufTail]
- int unreadSize = strbufTail-p;
+ int32_t unreadSize = strbufTail-p;
char* temp = new char[strbufSize];
memcpy(temp, p, unreadSize);
delete [] strbuf;
@@ -108,14 +108,14 @@ void ChunkedEncoding::inflate(char* outbuf, int& outlen, const char* inbuf, int
outlen = clen;
}
-int ChunkedEncoding::readData(char** pp, char* buf, int& len, int maxlen) {
+int32_t ChunkedEncoding::readData(char** pp, char* buf, int32_t& len, int32_t maxlen) {
if(buf+len == buf+maxlen) {
return -1;
}
if(chunkSize == 0) {
return readDataEOL(pp);
}
- int wsize;
+ int32_t wsize;
if(strbufTail-*pp < chunkSize) {
wsize = strbufTail-*pp <= maxlen-len ? strbufTail-*pp : maxlen-len;
} else {
@@ -132,7 +132,7 @@ int ChunkedEncoding::readData(char** pp, char* buf, int& len, int maxlen) {
}
}
-int ChunkedEncoding::readDataEOL(char** pp) {
+int32_t ChunkedEncoding::readDataEOL(char** pp) {
char* np = (char*)memchr(*pp, '\n', strbufTail-*pp);
char* rp = (char*)memchr(*pp, '\r', strbufTail-*pp);
if(np != NULL && rp != NULL && np-rp == 1 && *pp == rp) {
@@ -145,7 +145,7 @@ int ChunkedEncoding::readDataEOL(char** pp) {
}
}
-int ChunkedEncoding::readChunkSize(char** pp) {
+int32_t ChunkedEncoding::readChunkSize(char** pp) {
// we read chunk-size from *pp
char* p;
char* np = (char*)memchr(*pp, '\n', strbufTail-*pp);
@@ -170,15 +170,15 @@ int ChunkedEncoding::readChunkSize(char** pp) {
delete [] temp;
if(chunkSize < 0) {
throw new DlAbortEx(EX_INVALID_CHUNK_SIZE);
- } else if(errno == ERANGE && (chunkSize == LONG_MAX || chunkSize == LONG_MIN)) {
+ } else if(errno == ERANGE && (chunkSize == INT32_MAX || chunkSize == INT32_MIN)) {
throw new DlAbortEx(strerror(errno));
}
*pp = p+2;
return 0;
}
-void ChunkedEncoding::addBuffer(const char* inbuf, int inlen) {
- int realbufSize = strbufTail-strbuf;
+void ChunkedEncoding::addBuffer(const char* inbuf, int32_t inlen) {
+ int32_t realbufSize = strbufTail-strbuf;
if(realbufSize+inlen >= strbufSize) {
if(realbufSize+inlen > MAX_BUFSIZE) {
throw new DlAbortEx(EX_TOO_LARGE_CHUNK, realbufSize+inlen);
diff --git a/src/ChunkedEncoding.h b/src/ChunkedEncoding.h
index 44bb72cb..2e73ed5b 100644
--- a/src/ChunkedEncoding.h
+++ b/src/ChunkedEncoding.h
@@ -44,16 +44,20 @@ private:
READ_DATA,
FINISH
};
- long int chunkSize;
- int state;
+ int32_t chunkSize;
+ int32_t state;
char* strbuf;
- int strbufSize;
+ int32_t strbufSize;
char* strbufTail;
- int readChunkSize(char** pp);
- int readData(char** pp, char* buf, int& len, int maxlen);
- void addBuffer(const char* inbuf, int inlen);
- int readDataEOL(char** pp);
+ /**
+ * Returns 0 if the size of chunk is retrieved successfully,
+ * otherwise returns non-zero value.
+ */
+ int32_t readChunkSize(char** pp);
+ int32_t readData(char** pp, char* buf, int32_t& len, int32_t maxlen);
+ void addBuffer(const char* inbuf, int32_t inlen);
+ int32_t readDataEOL(char** pp);
public:
@@ -61,7 +65,7 @@ public:
~ChunkedEncoding();
void init();
- void inflate(char* outbuf, int& outlen, const char* inbuf, int inlen);
+ void inflate(char* outbuf, int32_t& outlen, const char* inbuf, int32_t inlen);
bool finished();
void end();
};
diff --git a/src/Command.cc b/src/Command.cc
index 7f701883..b24d74fd 100644
--- a/src/Command.cc
+++ b/src/Command.cc
@@ -34,4 +34,4 @@
/* copyright --> */
#include "Command.h"
-int Command::uuidGen = 0;
+int32_t Command::uuidGen = 0;
diff --git a/src/Command.h b/src/Command.h
index 49f4b3d4..c83be85c 100644
--- a/src/Command.h
+++ b/src/Command.h
@@ -38,7 +38,7 @@
#include "common.h"
#include "LogFactory.h"
-typedef int CommandUuid;
+typedef int32_t CommandUuid;
class Command {
public:
@@ -50,19 +50,19 @@ public:
};
private:
CommandUuid uuid;
- static int uuidGen;
+ static int32_t uuidGen;
STATUS status;
protected:
- int cuid;
+ int32_t cuid;
const Logger* logger;
public:
- Command(int cuid):uuid(uuidGen++), status(STATUS_INACTIVE), cuid(cuid) {
+ Command(int32_t cuid):uuid(uuidGen++), status(STATUS_INACTIVE), cuid(cuid) {
logger = LogFactory::getInstance();
}
virtual ~Command() {}
virtual bool execute() = 0;
- int getCuid() const { return cuid; }
+ int32_t getCuid() const { return cuid; }
const CommandUuid& getUuid() const { return uuid; }
void setStatusActive() { this->status = STATUS_ACTIVE; }
diff --git a/src/CompactPeerListProcessor.cc b/src/CompactPeerListProcessor.cc
index bae88c2b..0d597c36 100644
--- a/src/CompactPeerListProcessor.cc
+++ b/src/CompactPeerListProcessor.cc
@@ -44,18 +44,17 @@ Peers CompactPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
const Data* peersData = (const Data*)peersEntry;
if(peersData->getLen() > 0) {
- for(int i = 0; i < peersData->getLen(); i += 6) {
- unsigned int ipaddr1 = (unsigned char)*(peersData->getData()+i);
- unsigned int ipaddr2 = (unsigned char)*(peersData->getData()+i+1);
- unsigned int ipaddr3 = (unsigned char)*(peersData->getData()+i+2);
- unsigned int ipaddr4 = (unsigned char)*(peersData->getData()+i+3);
- unsigned int port = ntohs(*(unsigned short int*)(peersData->getData()+i+4));
+ for(int32_t i = 0; i < peersData->getLen(); i += 6) {
+ uint32_t ipaddr1 = (unsigned char)*(peersData->getData()+i);
+ uint32_t ipaddr2 = (unsigned char)*(peersData->getData()+i+1);
+ uint32_t ipaddr3 = (unsigned char)*(peersData->getData()+i+2);
+ uint32_t ipaddr4 = (unsigned char)*(peersData->getData()+i+3);
+ int32_t port = ntohs(*(uint16_t*)(peersData->getData()+i+4));
char ipaddr[16];
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
- PeerHandle peer =
- PeerHandle(new Peer(ipaddr, port, pieceLength, totalLength));
+ PeerHandle peer = new Peer(ipaddr, port, pieceLength, totalLength);
peers.push_back(peer);
}
diff --git a/src/CompactPeerListProcessor.h b/src/CompactPeerListProcessor.h
index 31f64f86..e81cfae8 100644
--- a/src/CompactPeerListProcessor.h
+++ b/src/CompactPeerListProcessor.h
@@ -38,10 +38,10 @@
class CompactPeerListProcessor : public PeerListProcessor {
private:
- int pieceLength;
- long long int totalLength;
+ int32_t pieceLength;
+ int64_t totalLength;
public:
- CompactPeerListProcessor(int pieceLength, long long int totalLength)
+ CompactPeerListProcessor(int32_t pieceLength, int64_t totalLength)
:pieceLength(pieceLength),
totalLength(totalLength) {}
diff --git a/src/ConsoleDownloadEngine.cc b/src/ConsoleDownloadEngine.cc
index 486e5b32..5237ba16 100644
--- a/src/ConsoleDownloadEngine.cc
+++ b/src/ConsoleDownloadEngine.cc
@@ -43,20 +43,7 @@ ConsoleDownloadEngine::ConsoleDownloadEngine() {}
ConsoleDownloadEngine::~ConsoleDownloadEngine() {}
-void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long int totalSize) {
- /*
- printf("\r ");
- printf("\r");
- printf("%s/%s Bytes %d%% %s %.2f KB/s %d connections",
- Util::llitos(currentSize, true).c_str(),
- Util::llitos(totalSize, true).c_str(),
- (totalSize == 0 ? 0 : (int)((currentSize*100)/totalSize)),
- avgSpeed == 0 ? "-" : Util::secfmt(eta).c_str(),
- speed/1024.0,
- commands.size());
- fflush(stdout);
- */
-
+void ConsoleDownloadEngine::sendStatistics(int64_t currentSize, int64_t totalSize) {
cout << "\r ";
cout << "\r";
if(_requestGroupMan->countRequestGroup() > 0) {
@@ -166,15 +153,15 @@ void ConsoleDownloadEngine::initStatistics() {
}
void ConsoleDownloadEngine::calculateStatistics() {
- long long int dlSize = _requestGroupMan->getDownloadLength();
+ int64_t dlSize = _requestGroupMan->getDownloadLength();
if(!isStartupLengthSet && dlSize > 0) {
startupLength = dlSize;
psize = dlSize;
isStartupLengthSet = true;
}
- int elapsed = cp.difference();
+ int32_t elapsed = cp.difference();
if(elapsed >= 1) {
- int nspeed = (int)((dlSize-psize)/elapsed);
+ int32_t nspeed = (dlSize-psize)/elapsed;
if(nspeed < 0) {
nspeed = 0;
}
@@ -182,9 +169,9 @@ void ConsoleDownloadEngine::calculateStatistics() {
cp.reset();
psize = dlSize;
- int elapsedFromStartup = startup.difference();
+ int32_t elapsedFromStartup = startup.difference();
if(elapsedFromStartup > 0) {
- avgSpeed = (int)((dlSize-startupLength)/elapsedFromStartup);
+ avgSpeed = (dlSize-startupLength)/elapsedFromStartup;
}
int64_t totalLength = _requestGroupMan->getTotalLength();
if(avgSpeed < 0) {
diff --git a/src/ConsoleDownloadEngine.h b/src/ConsoleDownloadEngine.h
index 0a0fae80..a1f61fcd 100644
--- a/src/ConsoleDownloadEngine.h
+++ b/src/ConsoleDownloadEngine.h
@@ -41,19 +41,19 @@
class ConsoleDownloadEngine : public DownloadEngine {
private:
Time cp;
- long long int psize;
- int speed;
+ int64_t psize;
+ int32_t speed;
// The time when startup
Time startup;
// The number of bytes downloaded at startup
- long long int startupLength;
+ int64_t startupLength;
bool isStartupLengthSet;
// The average speed(bytes per second) since startup
- int avgSpeed;
+ int32_t avgSpeed;
// The estimated remaining time to complete the download.
- int eta;
+ int32_t eta;
protected:
- void sendStatistics(long long int currentSize, long long int totalSize);
+ void sendStatistics(int64_t currentSize, int64_t totalSize);
virtual void initStatistics();
virtual void calculateStatistics();
virtual void onEndOfRun();
diff --git a/src/Data.cc b/src/Data.cc
index 40f15867..e57873aa 100644
--- a/src/Data.cc
+++ b/src/Data.cc
@@ -35,7 +35,7 @@
#include "Data.h"
#include "MetaEntryVisitor.h"
-Data::Data(const char* data, int len, bool number):number(number) {
+Data::Data(const char* data, int32_t len, bool number):number(number) {
if(data == NULL) {
this->data = NULL;
this->len = 0;
@@ -71,15 +71,15 @@ const char* Data::getData() const {
}
}
-int Data::getLen() const {
+int32_t Data::getLen() const {
return len;
}
-int Data::toInt() const {
- return (int)toLLInt();
+int32_t Data::toInt() const {
+ return toLLInt();
}
-long long int Data::toLLInt() const {
+int64_t Data::toLLInt() const {
if(len == 0) {
return 0;
} else {
diff --git a/src/Data.h b/src/Data.h
index 116bc442..46905933 100644
--- a/src/Data.h
+++ b/src/Data.h
@@ -42,7 +42,7 @@ using namespace std;
class Data : public MetaEntry {
private:
- int len;
+ int32_t len;
char* data;
bool number;
public:
@@ -50,15 +50,15 @@ public:
* This class stores the copy of data. So caller must take care of freeing
* memory of data.
*/
- Data(const char* data, int len, bool number = false);
+ Data(const char* data, int32_t len, bool number = false);
~Data();
string toString() const;
- int toInt() const;
- long long int toLLInt() const;
+ int32_t toInt() const;
+ int64_t toLLInt() const;
const char* getData() const;
- int getLen() const;
+ int32_t getLen() const;
bool isNumber() const;
void accept(MetaEntryVisitor* v) const;
diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc
index fd286af4..9345eb7d 100644
--- a/src/DefaultBtAnnounce.cc
+++ b/src/DefaultBtAnnounce.cc
@@ -111,13 +111,13 @@ string DefaultBtAnnounce::getAnnounceUrl() {
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
}
}
- int numWant = 50;
+ int32_t numWant = 50;
if(!btRuntime->lessThanEqMinPeer() ||
btRuntime->isHalt()) {
numWant = 0;
}
TransferStat stat = peerStorage->calculateStat();
- long long int left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
+ int64_t left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
if(left < 0) {
left = 0;
}
diff --git a/src/DefaultBtAnnounce.h b/src/DefaultBtAnnounce.h
index 128c02fd..03a873ff 100644
--- a/src/DefaultBtAnnounce.h
+++ b/src/DefaultBtAnnounce.h
@@ -50,16 +50,16 @@
class DefaultBtAnnounce : public BtAnnounce {
private:
BtContextHandle btContext;
- int trackers;
+ int32_t trackers;
Time prevAnnounceTime;
- int interval;
- int minInterval;
- int complete;
- int incomplete;
+ int32_t interval;
+ int32_t minInterval;
+ int32_t complete;
+ int32_t incomplete;
AnnounceList announceList;
string trackerId;
string key;
- int trackerNumTry;
+ int32_t trackerNumTry;
const Option* option;
Logger* logger;
BtRuntimeHandle btRuntime;
diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc
index f0286c52..d8ff303f 100644
--- a/src/DefaultBtProgressInfoFile.cc
+++ b/src/DefaultBtProgressInfoFile.cc
@@ -70,12 +70,12 @@ void DefaultBtProgressInfoFile::save() {
throw string("writeError:bitfield");
}
TransferStat stat = peerStorage->calculateStat();
- long long int allTimeDownloadLength = pieceStorage->getCompletedLength();
+ int64_t allTimeDownloadLength = pieceStorage->getCompletedLength();
if(fwrite(&allTimeDownloadLength,
sizeof(allTimeDownloadLength), 1, file) < 1) {
throw string("writeError:download length");
}
- long long int allTimeUploadLength =
+ int64_t allTimeUploadLength =
btRuntime->getUploadLengthAtStartup()+
stat.getSessionUploadLength();
if(fwrite(&allTimeUploadLength,
@@ -112,12 +112,12 @@ void DefaultBtProgressInfoFile::load() {
pieceStorage->setBitfield(savedBitfield,
pieceStorage->getBitfieldLength());
// allTimeDownloadLength exists for only a compatibility reason.
- long long int allTimeDownloadLength;
+ int64_t allTimeDownloadLength;
if(fread(&allTimeDownloadLength,
sizeof(allTimeDownloadLength), 1, file) < 1) {
throw string("readError");
}
- long long int allTimeUploadLength;
+ int64_t allTimeUploadLength;
if(fread(&allTimeUploadLength,
sizeof(allTimeUploadLength), 1, file) < 1) {
throw string("readError");
diff --git a/src/DefaultBtRequestFactory.h b/src/DefaultBtRequestFactory.h
index 8ca99ef9..ab93d6aa 100644
--- a/src/DefaultBtRequestFactory.h
+++ b/src/DefaultBtRequestFactory.h
@@ -77,7 +77,7 @@ public:
virtual void removeAllTargetPiece();
- virtual int countTargetPiece() {
+ virtual int32_t countTargetPiece() {
return pieces.size();
}
diff --git a/src/DefaultPeerListProcessor.cc b/src/DefaultPeerListProcessor.cc
index 9f79f3fd..e731be03 100644
--- a/src/DefaultPeerListProcessor.cc
+++ b/src/DefaultPeerListProcessor.cc
@@ -60,10 +60,8 @@ Peers DefaultPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
if(!ip || !port || !port->isNumber()) {
continue;
}
- PeerHandle peer = PeerHandle(new Peer(ip->toString(),
- port->toInt(),
- pieceLength,
- totalLength));
+ PeerHandle peer = new Peer(ip->toString(), port->toInt(), pieceLength,
+ totalLength);
peers.push_back(peer);
}
return peers;
diff --git a/src/DefaultPeerListProcessor.h b/src/DefaultPeerListProcessor.h
index 659e168c..223322d0 100644
--- a/src/DefaultPeerListProcessor.h
+++ b/src/DefaultPeerListProcessor.h
@@ -39,10 +39,10 @@
class DefaultPeerListProcessor : public PeerListProcessor {
private:
- int pieceLength;
- long long int totalLength;
+ int32_t pieceLength;
+ int64_t totalLength;
public:
- DefaultPeerListProcessor(int pieceLength, long long int totalLength)
+ DefaultPeerListProcessor(int32_t pieceLength, int64_t totalLength)
:pieceLength(pieceLength),
totalLength(totalLength) {}
diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc
index 5a18bf82..1d53b42e 100644
--- a/src/DefaultPeerStorage.cc
+++ b/src/DefaultPeerStorage.cc
@@ -111,9 +111,9 @@ PeerHandle DefaultPeerStorage::getUnusedPeer() {
class FindPeer {
private:
string ipaddr;
- int port;
+ int32_t port;
public:
- FindPeer(const string& ipaddr, int port):ipaddr(ipaddr), port(port) {}
+ FindPeer(const string& ipaddr, int32_t port):ipaddr(ipaddr), port(port) {}
bool operator()(const PeerHandle& peer) const {
return ipaddr == peer->ipaddr && port == peer->port;
@@ -121,7 +121,7 @@ public:
};
PeerHandle DefaultPeerStorage::getPeer(const string& ipaddr,
- int port) const {
+ int32_t port) const {
Peers::const_iterator itr = find_if(peers.begin(), peers.end(),
FindPeer(ipaddr, port));
if(itr == peers.end()) {
@@ -194,7 +194,7 @@ TransferStat DefaultPeerStorage::calculateStat() {
return stat;
}
-void DefaultPeerStorage::deleteUnusedPeer(int delSize) {
+void DefaultPeerStorage::deleteUnusedPeer(int32_t delSize) {
Peers temp;
for(Peers::reverse_iterator itr = peers.rbegin();
itr != peers.rend(); ++itr) {
diff --git a/src/DefaultPeerStorage.h b/src/DefaultPeerStorage.h
index 05ad4940..3b9c0071 100644
--- a/src/DefaultPeerStorage.h
+++ b/src/DefaultPeerStorage.h
@@ -50,11 +50,11 @@ private:
const Option* option;
Peers peers;
Peers incomingPeers;
- int maxPeerListSize;
+ int32_t maxPeerListSize;
Logger* logger;
BtRuntimeHandle btRuntime;
- long long int removedPeerSessionDownloadLength;
- long long int removedPeerSessionUploadLength;
+ int64_t removedPeerSessionDownloadLength;
+ int64_t removedPeerSessionUploadLength;
public:
DefaultPeerStorage(BtContextHandle btContext, const Option* option);
virtual ~DefaultPeerStorage();
@@ -72,7 +72,7 @@ public:
virtual PeerHandle getUnusedPeer();
- PeerHandle getPeer(const string& ipaddr, int port) const;
+ PeerHandle getPeer(const string& ipaddr, int32_t port) const;
virtual void addPeer(const Peers& peers);
@@ -86,11 +86,11 @@ public:
virtual void returnPeer(const PeerHandle& peer);
- void setMaxPeerListSize(int size) { this->maxPeerListSize = size; }
+ void setMaxPeerListSize(int32_t size) { this->maxPeerListSize = size; }
- int getMaxPeerListSize() const { return maxPeerListSize; }
+ int32_t getMaxPeerListSize() const { return maxPeerListSize; }
- void deleteUnusedPeer(int delSize);
+ void deleteUnusedPeer(int32_t delSize);
void onErasingPeer(const PeerHandle& peer);
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 143b671d..00c8c65d 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -72,8 +72,8 @@ bool DefaultPieceStorage::isEndGame() {
return bitfieldMan->countMissingBlock() <= endGamePieceNum;
}
-int DefaultPieceStorage::getMissingPieceIndex(const PeerHandle& peer) {
- int index = -1;
+int32_t DefaultPieceStorage::getMissingPieceIndex(const PeerHandle& peer) {
+ int32_t index = -1;
if(isEndGame()) {
index = bitfieldMan->getMissingIndex(peer->getBitfield(),
peer->getBitfieldLength());
@@ -84,7 +84,7 @@ int DefaultPieceStorage::getMissingPieceIndex(const PeerHandle& peer) {
return index;
}
-PieceHandle DefaultPieceStorage::checkOutPiece(int index) {
+PieceHandle DefaultPieceStorage::checkOutPiece(int32_t index) {
if(index == -1) {
return 0;
}
@@ -104,7 +104,7 @@ PieceHandle DefaultPieceStorage::checkOutPiece(int index) {
* Newly instantiated piece is not added to usedPieces.
* Because it is waste of memory and there is no chance to use them later.
*/
-PieceHandle DefaultPieceStorage::getPiece(int index) {
+PieceHandle DefaultPieceStorage::getPiece(int32_t index) {
if(0 <= index && index <= bitfieldMan->getMaxIndex()) {
PieceHandle piece = findUsedPiece(index);
if(piece.isNull()) {
@@ -125,16 +125,16 @@ void DefaultPieceStorage::addUsedPiece(const PieceHandle& piece) {
class FindPiece {
private:
- int index;
+ int32_t index;
public:
- FindPiece(int index):index(index) {}
+ FindPiece(int32_t index):index(index) {}
bool operator()(const PieceHandle& piece) {
return piece->getIndex() == index;
}
};
-PieceHandle DefaultPieceStorage::findUsedPiece(int index) const {
+PieceHandle DefaultPieceStorage::findUsedPiece(int32_t index) const {
Pieces::const_iterator itr = find_if(usedPieces.begin(),
usedPieces.end(),
FindPiece(index));
@@ -146,12 +146,12 @@ PieceHandle DefaultPieceStorage::findUsedPiece(int index) const {
}
PieceHandle DefaultPieceStorage::getMissingPiece(const PeerHandle& peer) {
- int index = getMissingPieceIndex(peer);
+ int32_t index = getMissingPieceIndex(peer);
return checkOutPiece(index);
}
-int DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer) {
- int index = -1;
+int32_t DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer) {
+ int32_t index = -1;
if(peer->isFastExtensionEnabled() && peer->countFastSet() > 0) {
BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
bitfieldMan->getTotalLength());
@@ -173,7 +173,7 @@ int DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer) {
}
PieceHandle DefaultPieceStorage::getMissingFastPiece(const PeerHandle& peer) {
- int index = getMissingFastPieceIndex(peer);
+ int32_t index = getMissingFastPieceIndex(peer);
return checkOutPiece(index);
}
@@ -187,14 +187,14 @@ void DefaultPieceStorage::deleteUsedPiece(const PieceHandle& piece) {
}
}
-void DefaultPieceStorage::reduceUsedPieces(int delMax) {
- int toDelete = usedPieces.size()-delMax;
+void DefaultPieceStorage::reduceUsedPieces(int32_t delMax) {
+ int32_t toDelete = usedPieces.size()-delMax;
if(toDelete <= 0) {
return;
}
- int fillRate = 10;
+ int32_t fillRate = 10;
while(fillRate < 50) {
- int deleted = deleteUsedPiecesByFillRate(fillRate, toDelete);
+ int32_t deleted = deleteUsedPiecesByFillRate(fillRate, toDelete);
if(deleted == 0) {
break;
}
@@ -203,9 +203,9 @@ void DefaultPieceStorage::reduceUsedPieces(int delMax) {
}
}
-int DefaultPieceStorage::deleteUsedPiecesByFillRate(int fillRate,
- int toDelete) {
- int deleted = 0;
+int32_t DefaultPieceStorage::deleteUsedPiecesByFillRate(int32_t fillRate,
+ int32_t toDelete) {
+ int32_t deleted = 0;
for(Pieces::iterator itr = usedPieces.begin();
itr != usedPieces.end() && deleted < toDelete;) {
PieceHandle& piece = *itr;
@@ -272,23 +272,23 @@ void DefaultPieceStorage::cancelPiece(const PieceHandle& piece) {
}
}
-bool DefaultPieceStorage::hasPiece(int index) {
+bool DefaultPieceStorage::hasPiece(int32_t index) {
return bitfieldMan->isBitSet(index);
}
-long long int DefaultPieceStorage::getTotalLength() {
+int64_t DefaultPieceStorage::getTotalLength() {
return bitfieldMan->getTotalLength();
}
-long long int DefaultPieceStorage::getFilteredTotalLength() {
+int64_t DefaultPieceStorage::getFilteredTotalLength() {
return bitfieldMan->getFilteredTotalLength();
}
-long long int DefaultPieceStorage::getCompletedLength() {
+int64_t DefaultPieceStorage::getCompletedLength() {
return bitfieldMan->getCompletedLength();
}
-long long int DefaultPieceStorage::getFilteredCompletedLength() {
+int64_t DefaultPieceStorage::getFilteredCompletedLength() {
return bitfieldMan->getFilteredCompletedLength();
}
@@ -312,7 +312,7 @@ void DefaultPieceStorage::setFileFilter(const Strings& filePaths) {
void DefaultPieceStorage::setFileFilter(const Integers& fileIndexes) {
Strings filePaths;
const FileEntries& entries = diskAdaptor->getFileEntries();
- for(int i = 0; i < (int)entries.size(); i++) {
+ for(int32_t i = 0; i < (int32_t)entries.size(); i++) {
if(find(fileIndexes.begin(), fileIndexes.end(), i+1) != fileIndexes.end()) {
logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str());
filePaths.push_back(entries[i]->getPath());
@@ -373,11 +373,11 @@ void DefaultPieceStorage::initStorage() {
}
void DefaultPieceStorage::setBitfield(const unsigned char* bitfield,
- int bitfieldLength) {
+ int32_t bitfieldLength) {
bitfieldMan->setBitfield(bitfield, bitfieldLength);
}
-int DefaultPieceStorage::getBitfieldLength() {
+int32_t DefaultPieceStorage::getBitfieldLength() {
return bitfieldMan->getBitfieldLength();
}
@@ -389,16 +389,16 @@ DiskAdaptorHandle DefaultPieceStorage::getDiskAdaptor() {
return diskAdaptor;
}
-int DefaultPieceStorage::getPieceLength(int index) {
+int32_t DefaultPieceStorage::getPieceLength(int32_t index) {
return bitfieldMan->getBlockLength(index);
}
-void DefaultPieceStorage::advertisePiece(int cuid, int index) {
+void DefaultPieceStorage::advertisePiece(int32_t cuid, int32_t index) {
HaveEntry entry(cuid, index);
haves.push_front(entry);
}
-Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int myCuid,
+Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int32_t myCuid,
const Time& lastCheckTime) {
Integers indexes;
for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) {
@@ -417,9 +417,9 @@ Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int myCuid,
class FindElapsedHave
{
private:
- int elapsed;
+ int32_t elapsed;
public:
- FindElapsedHave(int elapsed):elapsed(elapsed) {}
+ FindElapsedHave(int32_t elapsed):elapsed(elapsed) {}
bool operator()(const HaveEntry& have) {
if(have.getRegisteredTime().elapsed(elapsed)) {
@@ -430,7 +430,7 @@ public:
}
};
-void DefaultPieceStorage::removeAdvertisedPiece(int elapsed) {
+void DefaultPieceStorage::removeAdvertisedPiece(int32_t elapsed) {
Haves::iterator itr =
find_if(haves.begin(), haves.end(), FindElapsedHave(elapsed));
if(itr != haves.end()) {
diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h
index 33834b34..97ae031e 100644
--- a/src/DefaultPieceStorage.h
+++ b/src/DefaultPieceStorage.h
@@ -48,17 +48,17 @@
class HaveEntry {
private:
- int cuid;
- int index;
+ int32_t cuid;
+ int32_t index;
Time registeredTime;
public:
- HaveEntry(int cuid, int index):
+ HaveEntry(int32_t cuid, int32_t index):
cuid(cuid),
index(index) {}
- int getCuid() const { return cuid; }
+ int32_t getCuid() const { return cuid; }
- int getIndex() const { return index; }
+ int32_t getIndex() const { return index; }
const Time& getRegisteredTime() const { return registeredTime; }
};
@@ -77,13 +77,13 @@ private:
Haves haves;
FileAllocatorHandle createFileAllocator();
- int getMissingPieceIndex(const PeerHandle& peer);
- int getMissingFastPieceIndex(const PeerHandle& peer);
- PieceHandle checkOutPiece(int index);
- int deleteUsedPiecesByFillRate(int fillRate, int toDelete);
- void reduceUsedPieces(int delMax);
+ int32_t getMissingPieceIndex(const PeerHandle& peer);
+ int32_t getMissingFastPieceIndex(const PeerHandle& peer);
+ PieceHandle checkOutPiece(int32_t index);
+ int32_t deleteUsedPiecesByFillRate(int32_t fillRate, int32_t toDelete);
+ void reduceUsedPieces(int32_t delMax);
void deleteUsedPiece(const PieceHandle& piece);
- PieceHandle findUsedPiece(int index) const;
+ PieceHandle findUsedPiece(int32_t index) const;
public:
DefaultPieceStorage(BtContextHandle btContext, const Option* option);
virtual ~DefaultPieceStorage();
@@ -94,21 +94,21 @@ public:
virtual PieceHandle getMissingFastPiece(const PeerHandle& peer);
- virtual PieceHandle getPiece(int index);
+ virtual PieceHandle getPiece(int32_t index);
virtual void completePiece(const PieceHandle& piece);
virtual void cancelPiece(const PieceHandle& piece);
- virtual bool hasPiece(int index);
+ virtual bool hasPiece(int32_t index);
- virtual long long int getTotalLength();
+ virtual int64_t getTotalLength();
- virtual long long int getFilteredTotalLength();
+ virtual int64_t getFilteredTotalLength();
- virtual long long int getCompletedLength();
+ virtual int64_t getCompletedLength();
- virtual long long int getFilteredCompletedLength();
+ virtual int64_t getFilteredCompletedLength();
virtual void initStorage();
@@ -123,9 +123,9 @@ public:
virtual bool allDownloadFinished();
virtual void setBitfield(const unsigned char* bitfield,
- int bitfieldLength);
+ int32_t bitfieldLength);
- virtual int getBitfieldLength();
+ virtual int32_t getBitfieldLength();
virtual const unsigned char* getBitfield();
@@ -145,14 +145,14 @@ public:
virtual DiskAdaptorHandle getDiskAdaptor();
- virtual int getPieceLength(int index);
+ virtual int32_t getPieceLength(int32_t index);
- virtual void advertisePiece(int cuid, int index);
+ virtual void advertisePiece(int32_t cuid, int32_t index);
- virtual Integers getAdvertisedPieceIndexes(int myCuid,
+ virtual Integers getAdvertisedPieceIndexes(int32_t myCuid,
const Time& lastCheckTime);
- virtual void removeAdvertisedPiece(int elapsed);
+ virtual void removeAdvertisedPiece(int32_t elapsed);
virtual void markAllPiecesDone();
diff --git a/src/DelegatingPeerListProcessor.h b/src/DelegatingPeerListProcessor.h
index 19ff37ea..a0688641 100644
--- a/src/DelegatingPeerListProcessor.h
+++ b/src/DelegatingPeerListProcessor.h
@@ -42,11 +42,11 @@ typedef deque<PeerListProcessorHandle> PeerListProcessors;
class DelegatingPeerListProcessor : public PeerListProcessor {
private:
- int pieceLength;
- long long int totalLength;
+ int32_t pieceLength;
+ int64_t totalLength;
PeerListProcessors processors;
public:
- DelegatingPeerListProcessor(int pieceLength, long long int totalLength)
+ DelegatingPeerListProcessor(int32_t pieceLength, int64_t totalLength)
:pieceLength(pieceLength),
totalLength(totalLength) {
processors.push_back(new DefaultPeerListProcessor(pieceLength, totalLength));
diff --git a/src/DiskWriter.h b/src/DiskWriter.h
index 785c20f7..9ff7602f 100644
--- a/src/DiskWriter.h
+++ b/src/DiskWriter.h
@@ -35,7 +35,6 @@
#ifndef _D_DISK_WRITER_H_
#define _D_DISK_WRITER_H_
-#include <string>
#include "common.h"
#ifdef ENABLE_MESSAGE_DIGEST
#include "messageDigest.h"
@@ -87,8 +86,8 @@ public:
writeData((const char*)data, len, position);
}
- virtual int readData(char* data, int32_t len, int64_t position) = 0;
- virtual int readData(unsigned char* data, int32_t len, int64_t position) {
+ virtual int32_t readData(char* data, int32_t len, int64_t position) = 0;
+ virtual int32_t readData(unsigned char* data, int32_t len, int64_t position) {
return readData((char*)data, len, position);
}
#ifdef ENABLE_MESSAGE_DIGEST
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 04296697..62dd7637 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -66,8 +66,8 @@ void DownloadEngine::cleanQueue() {
void DownloadEngine::executeCommand(Command::STATUS statusFilter)
{
- int max = commands.size();
- for(int i = 0; i < max; i++) {
+ int32_t max = commands.size();
+ for(int32_t i = 0; i < max; i++) {
Command* com = commands.front();
commands.pop_front();
if(com->statusMatch(statusFilter)) {
@@ -116,7 +116,7 @@ void DownloadEngine::shortSleep() const {
void DownloadEngine::waitData() {
fd_set rfds;
fd_set wfds;
- int retval = 0;
+ int32_t retval = 0;
struct timeval tv;
memcpy(&rfds, &rfdset, sizeof(fd_set));
@@ -160,7 +160,7 @@ void DownloadEngine::updateFdSet() {
for(NameResolverEntries::iterator itr = nameResolverEntries.begin();
itr != nameResolverEntries.end(); ++itr) {
NameResolverEntry& entry = *itr;
- int fd = entry.nameResolver->getFds(&rfdset, &wfdset);
+ int32_t fd = entry.nameResolver->getFds(&rfdset, &wfdset);
if(fdmax < fd) {
fdmax = fd;
}
@@ -169,7 +169,7 @@ void DownloadEngine::updateFdSet() {
for(SocketEntries::iterator itr = socketEntries.begin();
itr != socketEntries.end(); ++itr) {
SocketEntry& entry = *itr;
- int fd = entry.socket->getSockfd();
+ int32_t fd = entry.socket->getSockfd();
switch(entry.type) {
case SocketEntry::TYPE_RD:
FD_SET(fd, &rfdset);
diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h
index f60679c8..2ce84dcb 100644
--- a/src/DownloadEngine.h
+++ b/src/DownloadEngine.h
@@ -106,7 +106,7 @@ private:
#endif // ENABLE_ASYNC_DNS
fd_set rfdset;
fd_set wfdset;
- int fdmax;
+ int32_t fdmax;
void shortSleep() const;
bool addSocket(const SocketEntry& socketEntry);
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc
index 1ab26688..eb3ea985 100644
--- a/src/DownloadEngineFactory.cc
+++ b/src/DownloadEngineFactory.cc
@@ -184,8 +184,8 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
PeerListenCommand* listenCommand =
new PeerListenCommand(CUIDCounterSingletonHolder::instance()->newID(),
te, btContext);
- int port;
- int listenPort = op->getAsInt(PREF_LISTEN_PORT);
+ int32_t port;
+ int32_t listenPort = op->getAsInt(PREF_LISTEN_PORT);
if(listenPort == -1) {
port = listenCommand->bindPort(6881, 6999);
} else {
diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc
index 24b4a3f2..6bbc6a85 100644
--- a/src/FeatureConfig.cc
+++ b/src/FeatureConfig.cc
@@ -50,7 +50,7 @@ FeatureConfig::FeatureConfig() {
PortMap::value_type("https", 443),
PortMap::value_type("ftp", 21),
};
- int portArraySize = sizeof(portArray)/sizeof(PortMap::value_type);
+ int32_t portArraySize = sizeof(portArray)/sizeof(PortMap::value_type);
defaultPorts.insert(&portArray[0],
&portArray[portArraySize]);
@@ -94,11 +94,11 @@ FeatureConfig::FeatureConfig() {
),
};
- int featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type);
+ int32_t featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type);
supportedFeatures.insert(&featureArray[0],
&featureArray[featureArraySize]);
- for(int i = 0; i < featureArraySize; i++) {
+ for(int32_t i = 0; i < featureArraySize; i++) {
features.push_back(featureArray[i].first);
}
}
diff --git a/src/FeatureConfig.h b/src/FeatureConfig.h
index ee1ef5c4..788912b3 100644
--- a/src/FeatureConfig.h
+++ b/src/FeatureConfig.h
@@ -38,7 +38,7 @@
#include "common.h"
#include <map>
-typedef map<string, int> PortMap;
+typedef map<string, int32_t> PortMap;
typedef map<string, bool> FeatureMap;
class FeatureConfig {
@@ -64,7 +64,7 @@ public:
featureConfig = 0;
}
- int getDefaultPort(const string& protocol) const {
+ int32_t getDefaultPort(const string& protocol) const {
PortMap::const_iterator itr = defaultPorts.find(protocol);
if(itr == defaultPorts.end()) {
return 0;
diff --git a/src/File.cc b/src/File.cc
index 0d55a250..a3d80dd9 100644
--- a/src/File.cc
+++ b/src/File.cc
@@ -43,7 +43,7 @@ File::File(const string& name):name(name) {}
File::~File() {}
-int File::fillStat(struct stat& fstat) {
+int32_t File::fillStat(struct stat& fstat) {
return stat(name.c_str(), &fstat);
}
diff --git a/src/File.h b/src/File.h
index 32519089..8ab22044 100644
--- a/src/File.h
+++ b/src/File.h
@@ -48,7 +48,11 @@ using namespace std;
class File {
private:
string name;
- int fillStat(struct stat& fstat);
+
+ /**
+ * Returns the return value of stat(...)
+ */
+ int32_t fillStat(struct stat& fstat);
public:
File(const string& name);
~File();
diff --git a/src/FileEntry.cc b/src/FileEntry.cc
index 1e74ffa8..d0c72de0 100644
--- a/src/FileEntry.cc
+++ b/src/FileEntry.cc
@@ -38,8 +38,8 @@
#include <libgen.h>
FileEntry::FileEntry(const string& path,
- long long int length,
- long long int offset):
+ int64_t length,
+ int64_t offset):
path(path), length(length), offset(offset),
extracted(false), requested(true) {}
diff --git a/src/FileEntry.h b/src/FileEntry.h
index eb162bfe..b395ce84 100644
--- a/src/FileEntry.h
+++ b/src/FileEntry.h
@@ -48,7 +48,7 @@ private:
public:
FileEntry():length(0), offset(0), extracted(false), requested(false) {}
- FileEntry(const string& path, long long int length, long long int offset);
+ FileEntry(const string& path, int64_t length, int64_t offset);
FileEntry& operator=(const FileEntry& entry)
{
@@ -80,11 +80,11 @@ public:
int64_t getLength() const { return length; }
- void setLength(long long int length) { this->length = length; }
+ void setLength(int64_t length) { this->length = length; }
- long long int getOffset() const { return offset; }
+ int64_t getOffset() const { return offset; }
- void setOffset(long long int offset) { this->offset = offset; }
+ void setOffset(int64_t offset) { this->offset = offset; }
bool isExtracted() const { return extracted; }
diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc
index 82a97d48..a40c0303 100644
--- a/src/FtpConnection.cc
+++ b/src/FtpConnection.cc
@@ -40,7 +40,7 @@
#include "prefs.h"
#include "LogFactory.h"
-FtpConnection::FtpConnection(int cuid, const SocketHandle& socket,
+FtpConnection::FtpConnection(int32_t cuid, const SocketHandle& socket,
const RequestHandle req, const Option* op)
:cuid(cuid), socket(socket), req(req), option(op) {
logger = LogFactory::getInstance();
@@ -94,9 +94,9 @@ SocketHandle FtpConnection::sendPort() const {
SocketHandle serverSocket;
serverSocket->beginListen();
- pair<string, int> addrinfo;
+ pair<string, int32_t> addrinfo;
socket->getAddrInfo(addrinfo);
- int ipaddr[4];
+ int32_t ipaddr[4];
sscanf(addrinfo.first.c_str(), "%d.%d.%d.%d",
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
serverSocket->getAddrInfo(addrinfo);
@@ -121,8 +121,8 @@ void FtpConnection::sendRetr() const {
socket->writeData(request);
}
-int FtpConnection::getStatus(const string& response) const {
- int status;
+int32_t FtpConnection::getStatus(const string& response) const {
+ int32_t status;
// When the response is not like "%d %*s",
// we return 0.
if(response.find_first_not_of("0123456789") != 3
@@ -136,7 +136,7 @@ int FtpConnection::getStatus(const string& response) const {
}
}
-bool FtpConnection::isEndOfResponse(int status, const string& response) const {
+bool FtpConnection::isEndOfResponse(int32_t status, const string& response) const {
if(response.size() <= 4) {
return false;
}
@@ -156,10 +156,10 @@ bool FtpConnection::isEndOfResponse(int status, const string& response) const {
}
}
-bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
+bool FtpConnection::bulkReceiveResponse(pair<int32_t, string>& response) {
char buf[1024];
while(socket->isReadable(0)) {
- int size = sizeof(buf)-1;
+ int32_t size = sizeof(buf)-1;
socket->readData(buf, size);
if(size == 0) {
throw new DlRetryEx(EX_GOT_EOF);
@@ -167,7 +167,7 @@ bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
buf[size] = '\0';
strbuf += buf;
}
- int status;
+ int32_t status;
if(strbuf.size() >= 4) {
status = getStatus(strbuf);
if(status == 0) {
@@ -188,8 +188,8 @@ bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
}
}
-int FtpConnection::receiveResponse() {
- pair<int, string> response;
+int32_t FtpConnection::receiveResponse() {
+ pair<int32_t, string> response;
if(bulkReceiveResponse(response)) {
return response.first;
} else {
@@ -197,8 +197,8 @@ int FtpConnection::receiveResponse() {
}
}
-int FtpConnection::receiveSizeResponse(long long int& size) {
- pair<int, string> response;
+int32_t FtpConnection::receiveSizeResponse(int64_t& size) {
+ pair<int32_t, string> response;
if(bulkReceiveResponse(response)) {
if(response.first == 213) {
sscanf(response.second.c_str(), "%*d %Ld", &size);
@@ -209,12 +209,12 @@ int FtpConnection::receiveSizeResponse(long long int& size) {
}
}
-int FtpConnection::receivePasvResponse(pair<string, int>& dest) {
- pair<int, string> response;
+int32_t FtpConnection::receivePasvResponse(pair<string, int32_t>& dest) {
+ pair<int32_t, string> response;
if(bulkReceiveResponse(response)) {
if(response.first == 227) {
// we assume the format of response is "227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)."
- int h1, h2, h3, h4, p1, p2;
+ int32_t h1, h2, h3, h4, p1, p2;
string::size_type p = response.second.find("(");
if(p >= 4) {
sscanf(response.second.substr(response.second.find("(")).c_str(),
diff --git a/src/FtpConnection.h b/src/FtpConnection.h
index ed3697a6..766d3720 100644
--- a/src/FtpConnection.h
+++ b/src/FtpConnection.h
@@ -47,7 +47,7 @@ using namespace std;
class FtpConnection {
private:
- int cuid;
+ int32_t cuid;
SocketHandle socket;
RequestHandle req;
const Option* option;
@@ -55,11 +55,11 @@ private:
string strbuf;
- int getStatus(const string& response) const;
- bool isEndOfResponse(int status, const string& response) const;
- bool bulkReceiveResponse(pair<int, string>& response);
+ int32_t getStatus(const string& response) const;
+ bool isEndOfResponse(int32_t status, const string& response) const;
+ bool bulkReceiveResponse(pair<int32_t, string>& response);
public:
- FtpConnection(int cuid, const SocketHandle& socket,
+ FtpConnection(int32_t cuid, const SocketHandle& socket,
const RequestHandle req, const Option* op);
~FtpConnection();
void sendUser() const;
@@ -72,9 +72,9 @@ public:
void sendRest(const SegmentHandle& segment) const;
void sendRetr() const;
- int receiveResponse();
- int receiveSizeResponse(long long int& size);
- int receivePasvResponse(pair<string, int>& dest);
+ int32_t receiveResponse();
+ int32_t receiveSizeResponse(int64_t& size);
+ int32_t receivePasvResponse(pair<string, int32_t>& dest);
};
#endif // _D_FTP_CONNECTION_H_
diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc
index ef39ce35..b9c03440 100644
--- a/src/FtpNegotiationCommand.cc
+++ b/src/FtpNegotiationCommand.cc
@@ -41,7 +41,7 @@
#include "Util.h"
#include "FatalException.h"
-FtpNegotiationCommand::FtpNegotiationCommand(int cuid,
+FtpNegotiationCommand::FtpNegotiationCommand(int32_t cuid,
const RequestHandle& req,
RequestGroup* requestGroup,
DownloadEngine* e,
@@ -82,7 +82,7 @@ bool FtpNegotiationCommand::recvGreeting() {
disableWriteCheckSocket();
setReadCheckSocket(socket);
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
@@ -101,7 +101,7 @@ bool FtpNegotiationCommand::sendUser() {
}
bool FtpNegotiationCommand::recvUser() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
switch(status) {
case 0:
return false;
@@ -124,7 +124,7 @@ bool FtpNegotiationCommand::sendPass() {
}
bool FtpNegotiationCommand::recvPass() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
@@ -142,7 +142,7 @@ bool FtpNegotiationCommand::sendType() {
}
bool FtpNegotiationCommand::recvType() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
@@ -160,7 +160,7 @@ bool FtpNegotiationCommand::sendCwd() {
}
bool FtpNegotiationCommand::recvCwd() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
@@ -178,8 +178,8 @@ bool FtpNegotiationCommand::sendSize() {
}
bool FtpNegotiationCommand::recvSize() {
- long long int size = 0;
- int status = ftp->receiveSizeResponse(size);
+ int64_t size = 0;
+ int32_t status = ftp->receiveSizeResponse(size);
if(status == 0) {
return false;
}
@@ -253,7 +253,7 @@ bool FtpNegotiationCommand::sendPort() {
}
bool FtpNegotiationCommand::recvPort() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
@@ -271,8 +271,8 @@ bool FtpNegotiationCommand::sendPasv() {
}
bool FtpNegotiationCommand::recvPasv() {
- pair<string, int> dest;
- int status = ftp->receivePasvResponse(dest);
+ pair<string, int32_t> dest;
+ int32_t status = ftp->receivePasvResponse(dest);
if(status == 0) {
return false;
}
@@ -306,7 +306,7 @@ bool FtpNegotiationCommand::sendRest(const SegmentHandle& segment) {
}
bool FtpNegotiationCommand::recvRest() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
@@ -325,7 +325,7 @@ bool FtpNegotiationCommand::sendRetr() {
}
bool FtpNegotiationCommand::recvRetr() {
- int status = ftp->receiveResponse();
+ int32_t status = ftp->receiveResponse();
if(status == 0) {
return false;
}
diff --git a/src/FtpNegotiationCommand.h b/src/FtpNegotiationCommand.h
index 2413f586..6b9fc8c6 100644
--- a/src/FtpNegotiationCommand.h
+++ b/src/FtpNegotiationCommand.h
@@ -91,12 +91,12 @@ private:
SocketHandle dataSocket;
SocketHandle serverSocket;
- int sequence;
+ int32_t sequence;
FtpConnection* ftp;
protected:
virtual bool executeInternal();
public:
- FtpNegotiationCommand(int cuid,
+ FtpNegotiationCommand(int32_t cuid,
const RequestHandle& req,
RequestGroup* requestGroup,
DownloadEngine* e,
diff --git a/src/HaveEraseCommand.cc b/src/HaveEraseCommand.cc
index 0758d10a..ecb209c9 100644
--- a/src/HaveEraseCommand.cc
+++ b/src/HaveEraseCommand.cc
@@ -34,10 +34,10 @@
/* copyright --> */
#include "HaveEraseCommand.h"
-HaveEraseCommand::HaveEraseCommand(int cuid,
+HaveEraseCommand::HaveEraseCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
- int interval)
+ int32_t interval)
:BtContextAwareCommand(cuid, btContext),
e(e),
interval(interval) {}
diff --git a/src/HaveEraseCommand.h b/src/HaveEraseCommand.h
index 59a663bf..4875df23 100644
--- a/src/HaveEraseCommand.h
+++ b/src/HaveEraseCommand.h
@@ -42,12 +42,12 @@ class HaveEraseCommand : public BtContextAwareCommand {
private:
TorrentDownloadEngine* e;
Time cp;
- int interval;
+ int32_t interval;
public:
- HaveEraseCommand(int cuid,
+ HaveEraseCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
- int interval);
+ int32_t interval);
virtual ~HaveEraseCommand() {}
diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc
index bc989cde..6f0e2c67 100644
--- a/src/HttpConnection.cc
+++ b/src/HttpConnection.cc
@@ -42,7 +42,7 @@
#include "LogFactory.h"
#include <sstream>
-HttpConnection::HttpConnection(int cuid,
+HttpConnection::HttpConnection(int32_t cuid,
const SocketHandle& socket,
const Option* op):
cuid(cuid), socket(socket), option(op), logger(LogFactory::getInstance())
diff --git a/src/HttpConnection.h b/src/HttpConnection.h
index 96ab0f77..87384b44 100644
--- a/src/HttpConnection.h
+++ b/src/HttpConnection.h
@@ -75,7 +75,7 @@ typedef deque<HttpRequestEntryHandle> HttpRequestEntries;
class HttpConnection {
private:
- int cuid;
+ int32_t cuid;
SocketHandle socket;
const Option* option;
const Logger* logger;
@@ -84,7 +84,7 @@ private:
string eraseConfidentialInfo(const string& request);
public:
- HttpConnection(int cuid,
+ HttpConnection(int32_t cuid,
const SocketHandle& socket,
const Option* op);
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index 9cf6b002..630fcec1 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -61,11 +61,11 @@ Strings HttpHeader::get(const string& name) const {
return v;
}
-int HttpHeader::getFirstAsInt(const string& name) const {
- return (int)getFirstAsLLInt(name);
+int32_t HttpHeader::getFirstAsInt(const string& name) const {
+ return getFirstAsLLInt(name);
}
-long long int HttpHeader::getFirstAsLLInt(const string& name) const {
+int64_t HttpHeader::getFirstAsLLInt(const string& name) const {
string value = getFirst(name);
if(value == "") {
return 0;
diff --git a/src/HttpHeader.h b/src/HttpHeader.h
index d2cacce8..8b90f985 100644
--- a/src/HttpHeader.h
+++ b/src/HttpHeader.h
@@ -52,8 +52,8 @@ public:
bool defined(const string& name) const;
string getFirst(const string& name) const;
Strings get(const string& name) const;
- int getFirstAsInt(const string& name) const;
- long long int getFirstAsLLInt(const string& name) const;
+ int32_t getFirstAsInt(const string& name) const;
+ int64_t getFirstAsLLInt(const string& name) const;
RangeHandle getRange() const;
};
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index 851ebdc5..603523d8 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -63,7 +63,7 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const
}
}
-string HttpRequest::getHostText(const string& host, in_port_t port) const
+string HttpRequest::getHostText(const string& host, int32_t port) const
{
return host+(port == 80 || port == 443 ? "" : ":"+Util::llitos(port));
}
diff --git a/src/HttpRequest.h b/src/HttpRequest.h
index 8cfe45d9..753302b3 100644
--- a/src/HttpRequest.h
+++ b/src/HttpRequest.h
@@ -59,7 +59,7 @@ private:
string userAgent;
- string getHostText(const string& host, in_port_t port) const;
+ string getHostText(const string& host, int32_t port) const;
string getProxyAuthString() const;
@@ -106,7 +106,7 @@ public:
return request->getHost();
}
- in_port_t getPort() const
+ int32_t getPort() const
{
return request->getPort();
}
diff --git a/src/MetaFileUtil.cc b/src/MetaFileUtil.cc
index 58ab78c3..35c84d38 100644
--- a/src/MetaFileUtil.cc
+++ b/src/MetaFileUtil.cc
@@ -41,7 +41,7 @@
MetaEntry* MetaFileUtil::parseMetaFile(const string& file) {
File f(file);
- int len = f.size();
+ int32_t len = f.size();
char* buf = new char[len];
FILE* fp = fopen(file.c_str(), "r+");
try {
@@ -66,7 +66,7 @@ MetaEntry* MetaFileUtil::parseMetaFile(const string& file) {
}
}
-MetaEntry* MetaFileUtil::bdecoding(const char* buf, int len) {
+MetaEntry* MetaFileUtil::bdecoding(const char* buf, int32_t len) {
MetaEntry* entry = NULL;
try{
const char* p = buf;
@@ -157,7 +157,7 @@ Data* MetaFileUtil::decodeInt(const char** pp, const char* end) {
if(endTerm == NULL) {
throw new DlAbortEx(EX_MULFORMED_META_INFO);
}
- int numSize = endTerm-*pp;
+ int32_t numSize = endTerm-*pp;
Data* data = new Data(*pp, numSize, true);
*pp += numSize+1;
@@ -173,12 +173,12 @@ Data* MetaFileUtil::decodeWord(const char** pp, const char* end) {
if(delim == *pp || delim == NULL) {
throw new DlAbortEx(EX_MULFORMED_META_INFO);
}
- int numSize = delim-*pp;
+ int32_t numSize = delim-*pp;
char* temp = new char[numSize+1];
memcpy(temp, *pp, numSize);
temp[numSize] = '\0';
char* endptr;
- int size = strtol(temp, &endptr, 10);
+ int32_t size = strtol(temp, &endptr, 10);
if(*endptr != '\0') {
delete [] temp;
throw new DlAbortEx(EX_MULFORMED_META_INFO);
diff --git a/src/MetaFileUtil.h b/src/MetaFileUtil.h
index 593cc563..48693b7f 100644
--- a/src/MetaFileUtil.h
+++ b/src/MetaFileUtil.h
@@ -57,7 +57,7 @@ private:
public:
static MetaEntry* parseMetaFile(const string& file);
- static MetaEntry* bdecoding(const char* buf, int len);
+ static MetaEntry* bdecoding(const char* buf, int32_t len);
};
#endif // _D_META_FILE_UTIL_H_
diff --git a/src/MetalinkEntry.cc b/src/MetalinkEntry.cc
index e4c1497d..b82129fa 100644
--- a/src/MetalinkEntry.cc
+++ b/src/MetalinkEntry.cc
@@ -48,9 +48,9 @@ MetalinkEntry::~MetalinkEntry() {}
class AddLocationPreference {
private:
string location;
- int preferenceToAdd;
+ int32_t preferenceToAdd;
public:
- AddLocationPreference(const string& location, int preferenceToAdd):
+ AddLocationPreference(const string& location, int32_t preferenceToAdd):
location(location), preferenceToAdd(preferenceToAdd) {}
void operator()(MetalinkResourceHandle& res) {
@@ -60,7 +60,7 @@ public:
}
};
-void MetalinkEntry::setLocationPreference(const string& location, int preferenceToAdd) {
+void MetalinkEntry::setLocationPreference(const string& location, int32_t preferenceToAdd) {
for_each(resources.begin(), resources.end(),
AddLocationPreference(location, preferenceToAdd));
}
diff --git a/src/MetalinkEntry.h b/src/MetalinkEntry.h
index dd68720b..783e9d1f 100644
--- a/src/MetalinkEntry.h
+++ b/src/MetalinkEntry.h
@@ -94,7 +94,7 @@ public:
void reorderResourcesByPreference();
- void setLocationPreference(const string& location, int preferenceToAdd);
+ void setLocationPreference(const string& location, int32_t preferenceToAdd);
static FileEntries toFileEntry(const MetalinkEntries& metalinkEntries);
};
diff --git a/src/MetalinkRequestInfo.cc b/src/MetalinkRequestInfo.cc
index af991a0a..abacfd4d 100644
--- a/src/MetalinkRequestInfo.cc
+++ b/src/MetalinkRequestInfo.cc
@@ -43,10 +43,9 @@
class AccumulateNonP2PUrl {
private:
Strings* urlsPtr;
- int split;
+ int32_t split;
public:
- AccumulateNonP2PUrl(Strings* urlsPtr,
- int split)
+ AccumulateNonP2PUrl(Strings* urlsPtr, int32_t split)
:urlsPtr(urlsPtr),
split(split) {}
@@ -55,7 +54,7 @@ public:
case MetalinkResource::TYPE_HTTP:
case MetalinkResource::TYPE_HTTPS:
case MetalinkResource::TYPE_FTP:
- for(int s = 1; s <= split; s++) {
+ for(int32_t s = 1; s <= split; s++) {
urlsPtr->push_back(resource->url);
}
break;
diff --git a/src/MetalinkResource.h b/src/MetalinkResource.h
index 8fca4c20..6ea68a48 100644
--- a/src/MetalinkResource.h
+++ b/src/MetalinkResource.h
@@ -48,9 +48,9 @@ public:
};
public:
string url;
- int type;
+ TYPE type;
string location;
- int preference;
+ int32_t preference;
public:
MetalinkResource();
~MetalinkResource();
diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc
index 86a45df5..7d96d29a 100644
--- a/src/MultiDiskAdaptor.cc
+++ b/src/MultiDiskAdaptor.cc
@@ -145,7 +145,7 @@ int32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry,
return length;
}
-int MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset)
+int32_t MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset)
{
int64_t fileOffset = offset;
bool reading = false;
diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h
index bcb363a6..0610517e 100644
--- a/src/MultiDiskAdaptor.h
+++ b/src/MultiDiskAdaptor.h
@@ -140,7 +140,7 @@ public:
virtual void writeData(const unsigned char* data, int32_t len,
int64_t offset);
- virtual int readData(unsigned char* data, int32_t len, int64_t offset);
+ virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset);
virtual string messageDigest(int64_t offset, int64_t length,
const MessageDigestContext::DigestAlgo& algo);
diff --git a/src/NameResolver.cc b/src/NameResolver.cc
index 657a621a..6015bade 100644
--- a/src/NameResolver.cc
+++ b/src/NameResolver.cc
@@ -36,7 +36,7 @@
#ifdef ENABLE_ASYNC_DNS
-void callback(void* arg, int status, struct hostent* host) {
+void callback(void* arg, int32_t status, struct hostent* host) {
NameResolver* resolverPtr = (NameResolver*)arg;
#ifdef HAVE_LIBARES
// This block is required since the assertion in ares_strerror fails
@@ -75,7 +75,7 @@ void NameResolver::resolve(const string& hostname)
ai.ai_socktype = SOCK_STREAM;
ai.ai_protocol = 0;
struct addrinfo* res;
- int ec;
+ int32_t ec;
if((ec = getaddrinfo(hostname.c_str(), 0, &ai, &res)) != 0) {
throw new DlAbortEx(EX_RESOLVE_HOSTNAME,
hostname.c_str(), gai_strerror(ec));
diff --git a/src/NameResolver.h b/src/NameResolver.h
index 3a7d8477..e4da707c 100644
--- a/src/NameResolver.h
+++ b/src/NameResolver.h
@@ -51,10 +51,10 @@ extern "C" {
} /* end of extern "C" */
#endif
-void callback(void* arg, int status, struct hostent* host);
+void callback(void* arg, int32_t status, struct hostent* host);
class NameResolver {
- friend void callback(void* arg, int status, struct hostent* host);
+ friend void callback(void* arg, int32_t status, struct hostent* host);
public:
enum STATUS {
@@ -100,7 +100,7 @@ public:
return status;
}
- int getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const {
+ int32_t getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const {
return ares_fds(channel, rfdsPtr, wfdsPtr);
}
diff --git a/src/Option.cc b/src/Option.cc
index b8758af1..67ecb047 100644
--- a/src/Option.cc
+++ b/src/Option.cc
@@ -56,16 +56,16 @@ string Option::get(const string& name) const {
}
}
-int Option::getAsInt(const string& name) const {
+int32_t Option::getAsInt(const string& name) const {
string value = get(name);
if(value == "") {
return 0;
} else {
- return (int)strtol(value.c_str(), NULL, 10);
+ return strtol(value.c_str(), NULL, 10);
}
}
-long long int Option::getAsLLInt(const string& name) const {
+int64_t Option::getAsLLInt(const string& name) const {
string value = get(name);
if(value == "") {
return 0;
diff --git a/src/Option.h b/src/Option.h
index df1c1694..9552ccad 100644
--- a/src/Option.h
+++ b/src/Option.h
@@ -51,8 +51,8 @@ public:
void put(const string& name, const string& value);
bool defined(const string& name) const;
string get(const string& name) const;
- int getAsInt(const string& name) const;
- long long int getAsLLInt(const string& name) const;
+ int32_t getAsInt(const string& name) const;
+ int64_t getAsLLInt(const string& name) const;
bool getAsBool(const string& name) const;
double getAsDouble(const string& name) const;
diff --git a/src/Peer.cc b/src/Peer.cc
index d4b64452..685b1b36 100644
--- a/src/Peer.cc
+++ b/src/Peer.cc
@@ -36,7 +36,7 @@
#include "BitfieldManFactory.h"
#include "Util.h"
-Peer::Peer(string ipaddr, int port, int pieceLength, long long int totalLength):
+Peer::Peer(string ipaddr, int32_t port, int32_t pieceLength, int64_t totalLength):
ipaddr(ipaddr),
port(port),
sessionUploadLength(0),
@@ -62,7 +62,7 @@ Peer::Peer():entryId(0), ipaddr(""), port(0), bitfield(0),
}
*/
-void Peer::updateBitfield(int index, int operation) {
+void Peer::updateBitfield(int32_t index, int32_t operation) {
if(operation == 1) {
bitfield->setBit(index);
} else if(operation == 0) {
@@ -79,7 +79,7 @@ bool Peer::shouldBeChoking() const {
return chokingRequired;
}
-bool Peer::hasPiece(int index) const {
+bool Peer::hasPiece(int32_t index) const {
return bitfield->isBitSet(index);
}
@@ -105,33 +105,33 @@ void Peer::resetStatus() {
peerStat.reset();
}
-bool Peer::isInFastSet(int index) const {
+bool Peer::isInFastSet(int32_t index) const {
return find(fastSet.begin(), fastSet.end(), index) != fastSet.end();
}
-void Peer::addFastSetIndex(int index) {
+void Peer::addFastSetIndex(int32_t index) {
if(!isInFastSet(index)) {
fastSet.push_back(index);
}
}
-bool Peer::isInPeerAllowedIndexSet(int index) const {
+bool Peer::isInPeerAllowedIndexSet(int32_t index) const {
return find(peerAllowedIndexSet.begin(), peerAllowedIndexSet.end(),
index) != peerAllowedIndexSet.end();
}
-void Peer::addPeerAllowedIndex(int index) {
+void Peer::addPeerAllowedIndex(int32_t index) {
if(!isInPeerAllowedIndexSet(index)) {
peerAllowedIndexSet.push_back(index);
}
}
-bool Peer::isInAmAllowedIndexSet(int index) const {
+bool Peer::isInAmAllowedIndexSet(int32_t index) const {
return find(amAllowedIndexSet.begin(), amAllowedIndexSet.end(),
index) != amAllowedIndexSet.end();
}
-void Peer::addAmAllowedIndex(int index) {
+void Peer::addAmAllowedIndex(int32_t index) {
if(!isInAmAllowedIndexSet(index)) {
amAllowedIndexSet.push_back(index);
}
@@ -141,7 +141,7 @@ void Peer::setAllBitfield() {
bitfield->setAllBit();
}
-void Peer::updateLatency(int latency) {
+void Peer::updateLatency(int32_t latency) {
this->latency = (this->latency*20+latency*80)/200;
}
diff --git a/src/Peer.h b/src/Peer.h
index a15464f2..63b5f07c 100644
--- a/src/Peer.h
+++ b/src/Peer.h
@@ -53,13 +53,13 @@ class Peer {
friend bool operator!=(const Peer& p1, const Peer& p2);
public:
string ipaddr;
- int port;
+ int32_t port;
bool amChoking;
bool amInterested;
bool peerChoking;
bool peerInterested;
- int tryCount;
- int cuid;
+ int32_t tryCount;
+ int32_t cuid;
bool chokingRequired;
bool optUnchoking;
bool snubbing;
@@ -74,16 +74,16 @@ private:
// fast index set which localhost has sent to a peer.
Integers amAllowedIndexSet;
PeerStat peerStat;
- long long int sessionUploadLength;
- long long int sessionDownloadLength;
- int pieceLength;
- int latency;
+ int64_t sessionUploadLength;
+ int64_t sessionDownloadLength;
+ int32_t pieceLength;
+ int32_t latency;
bool active;
string id;
Time _badConditionStartTime;
- int _badConditionInterval;
+ int32_t _badConditionInterval;
public:
- Peer(string ipaddr, int port, int pieceLength, long long int totalLength);
+ Peer(string ipaddr, int32_t port, int32_t pieceLength, int64_t totalLength);
~Peer() {
delete bitfield;
@@ -100,12 +100,12 @@ public:
void resetStatus();
- void updateUploadLength(int bytes) {
+ void updateUploadLength(int32_t bytes) {
peerStat.updateUploadLength(bytes);
sessionUploadLength += bytes;
}
- void updateDownloadLength(int bytes) {
+ void updateDownloadLength(int32_t bytes) {
peerStat.updateDownloadLength(bytes);
sessionDownloadLength += bytes;
}
@@ -135,14 +135,14 @@ public:
/**
* Returns the number of bytes uploaded to the remote host.
*/
- long long int getSessionUploadLength() const {
+ int64_t getSessionUploadLength() const {
return sessionUploadLength;
}
/**
* Returns the number of bytes downloaded from the remote host.
*/
- long long int getSessionDownloadLength() const {
+ int64_t getSessionDownloadLength() const {
return sessionDownloadLength;
}
@@ -165,43 +165,43 @@ public:
}
const unsigned char* getPeerId() const { return this->peerId; }
- void setBitfield(const unsigned char* bitfield, int bitfieldLength) {
+ void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
this->bitfield->setBitfield(bitfield, bitfieldLength);
}
const unsigned char* getBitfield() const { return bitfield->getBitfield(); }
- int getBitfieldLength() const { return bitfield->getBitfieldLength(); }
+ int32_t getBitfieldLength() const { return bitfield->getBitfieldLength(); }
void setAllBitfield();
/**
* operation = 1: set index-th bit to 1
* operation = 0: set index-th bit to 0
*/
- void updateBitfield(int index, int operation);
+ void updateBitfield(int32_t index, int32_t operation);
void setFastExtensionEnabled(bool enabled) {
fastExtensionEnabled = enabled;
}
bool isFastExtensionEnabled() const { return fastExtensionEnabled; }
- void addFastSetIndex(int index);
+ void addFastSetIndex(int32_t index);
const Integers& getFastSet() const { return fastSet; }
- bool isInFastSet(int index) const;
- int countFastSet() const { return fastSet.size(); }
+ bool isInFastSet(int32_t index) const;
+ int32_t countFastSet() const { return fastSet.size(); }
- void addPeerAllowedIndex(int index);
- bool isInPeerAllowedIndexSet(int index) const;
+ void addPeerAllowedIndex(int32_t index);
+ bool isInPeerAllowedIndexSet(int32_t index) const;
- void addAmAllowedIndex(int index);
- bool isInAmAllowedIndexSet(int index) const;
+ void addAmAllowedIndex(int32_t index);
+ bool isInAmAllowedIndexSet(int32_t index) const;
bool shouldBeChoking() const;
- bool hasPiece(int index) const;
+ bool hasPiece(int32_t index) const;
bool isSeeder() const;
- void updateLatency(int latency);
- int getLatency() const { return latency; }
+ void updateLatency(int32_t latency);
+ int32_t getLatency() const { return latency; }
const string& getId() const {
return id;
diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc
index 0fdf317e..86c44338 100644
--- a/src/PeerAbstractCommand.cc
+++ b/src/PeerAbstractCommand.cc
@@ -39,7 +39,7 @@
#include "message.h"
#include "prefs.h"
-PeerAbstractCommand::PeerAbstractCommand(int cuid, const PeerHandle& peer,
+PeerAbstractCommand::PeerAbstractCommand(int32_t cuid, const PeerHandle& peer,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
const SocketHandle& s)
@@ -88,11 +88,11 @@ bool PeerAbstractCommand::execute() {
}
// TODO this method removed when PeerBalancerCommand is implemented
-bool PeerAbstractCommand::prepareForNextPeer(int wait) {
+bool PeerAbstractCommand::prepareForNextPeer(int32_t wait) {
return true;
}
-bool PeerAbstractCommand::prepareForRetry(int wait) {
+bool PeerAbstractCommand::prepareForRetry(int32_t wait) {
return true;
}
@@ -152,7 +152,7 @@ void PeerAbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
}
}
-void PeerAbstractCommand::setUploadLimit(int uploadLimit) {
+void PeerAbstractCommand::setUploadLimit(int32_t uploadLimit) {
this->uploadLimit = uploadLimit;
}
diff --git a/src/PeerAbstractCommand.h b/src/PeerAbstractCommand.h
index 0aed6824..e50aabde 100644
--- a/src/PeerAbstractCommand.h
+++ b/src/PeerAbstractCommand.h
@@ -44,22 +44,22 @@
class PeerAbstractCommand : public BtContextAwareCommand {
private:
Time checkPoint;
- int timeout;
+ int32_t timeout;
protected:
TorrentDownloadEngine* e;
SocketHandle socket;
PeerHandle peer;
- void setTimeout(int timeout) { this->timeout = timeout; }
- virtual bool prepareForNextPeer(int wait);
- virtual bool prepareForRetry(int wait);
+ void setTimeout(int32_t timeout) { this->timeout = timeout; }
+ virtual bool prepareForNextPeer(int32_t wait);
+ virtual bool prepareForRetry(int32_t wait);
virtual void onAbort(Exception* ex);
virtual bool executeInternal() = 0;
void setReadCheckSocket(const SocketHandle& socket);
void setWriteCheckSocket(const SocketHandle& socket);
void disableReadCheckSocket();
void disableWriteCheckSocket();
- void setUploadLimit(int uploadLimit);
+ void setUploadLimit(int32_t uploadLimit);
void setUploadLimitCheck(bool check);
void setNoCheck(bool check);
private:
@@ -68,10 +68,10 @@ private:
SocketHandle readCheckTarget;
SocketHandle writeCheckTarget;
bool uploadLimitCheck;
- int uploadLimit;
+ int32_t uploadLimit;
bool noCheck;
public:
- PeerAbstractCommand(int cuid, const PeerHandle& peer,
+ PeerAbstractCommand(int32_t cuid, const PeerHandle& peer,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
const SocketHandle& s = SocketHandle());
diff --git a/src/PeerChokeCommand.cc b/src/PeerChokeCommand.cc
index 5094a1b0..de06502b 100644
--- a/src/PeerChokeCommand.cc
+++ b/src/PeerChokeCommand.cc
@@ -35,10 +35,10 @@
#include "PeerChokeCommand.h"
#include "Util.h"
-PeerChokeCommand::PeerChokeCommand(int cuid,
+PeerChokeCommand::PeerChokeCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
- int interval):
+ int32_t interval):
BtContextAwareCommand(cuid, btContext),
interval(interval),
e(e),
@@ -59,7 +59,7 @@ void PeerChokeCommand::optUnchokingPeer(Peers& peers) const {
return;
}
random_shuffle(peers.begin(), peers.end());
- int optUnchokCount = 1;
+ int32_t optUnchokCount = 1;
for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) {
Peers::value_type peer = *itr;
if(optUnchokCount > 0 && !peer->snubbing) {
@@ -108,7 +108,7 @@ bool PeerChokeCommand::execute() {
} else {
orderByDownloadRate(peers);
}
- int unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size();
+ int32_t unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size();
for(Peers::iterator itr = peers.begin(); itr != peers.end() && unchokingCount > 0; ) {
PeerHandle peer = *itr;
if(peer->peerInterested && !peer->snubbing) {
diff --git a/src/PeerChokeCommand.h b/src/PeerChokeCommand.h
index 6b03ccac..687f405c 100644
--- a/src/PeerChokeCommand.h
+++ b/src/PeerChokeCommand.h
@@ -41,9 +41,9 @@
class PeerChokeCommand : public BtContextAwareCommand {
private:
- int interval;
+ int32_t interval;
TorrentDownloadEngine* e;
- int rotate;
+ int32_t rotate;
Time checkPoint;
void orderByUploadRate(Peers& peers) const;
@@ -51,10 +51,10 @@ private:
void optUnchokingPeer(Peers& peers) const;
public:
- PeerChokeCommand(int cuid,
+ PeerChokeCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
- int interval);
+ int32_t interval);
virtual ~PeerChokeCommand();
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc
index 9ed21cf7..522b02ab 100644
--- a/src/PeerInteractionCommand.cc
+++ b/src/PeerInteractionCommand.cc
@@ -49,12 +49,12 @@
#include "CUIDCounter.h"
#include <algorithm>
-PeerInteractionCommand::PeerInteractionCommand(int cuid,
+PeerInteractionCommand::PeerInteractionCommand(int32_t cuid,
const PeerHandle& p,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
const SocketHandle& s,
- int sequence)
+ Seq sequence)
:PeerAbstractCommand(cuid, p, e, btContext, s),
sequence(sequence),
btInteractive(0),
@@ -199,7 +199,7 @@ bool PeerInteractionCommand::executeInternal() {
}
// TODO this method removed when PeerBalancerCommand is implemented
-bool PeerInteractionCommand::prepareForNextPeer(int wait) {
+bool PeerInteractionCommand::prepareForNextPeer(int32_t wait) {
if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
PeerHandle peer = peerStorage->getUnusedPeer();
peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
@@ -213,7 +213,7 @@ bool PeerInteractionCommand::prepareForNextPeer(int wait) {
return true;
}
-bool PeerInteractionCommand::prepareForRetry(int wait) {
+bool PeerInteractionCommand::prepareForRetry(int32_t wait) {
e->commands.push_back(this);
return false;
}
diff --git a/src/PeerInteractionCommand.h b/src/PeerInteractionCommand.h
index ebb62359..0f999611 100644
--- a/src/PeerInteractionCommand.h
+++ b/src/PeerInteractionCommand.h
@@ -39,31 +39,32 @@
#include "BtInteractive.h"
class PeerInteractionCommand : public PeerAbstractCommand {
+public:
+ enum Seq {
+ INITIATOR_SEND_HANDSHAKE,
+ INITIATOR_WAIT_HANDSHAKE,
+ //RECEIVER_SEND_HANDSHAKE,
+ RECEIVER_WAIT_HANDSHAKE,
+ WIRED};
private:
- int sequence;
+ Seq sequence;
BtInteractiveHandle btInteractive;
int32_t maxDownloadSpeedLimit;
protected:
virtual bool executeInternal();
- virtual bool prepareForRetry(int wait);
- virtual bool prepareForNextPeer(int wait);
+ virtual bool prepareForRetry(int32_t wait);
+ virtual bool prepareForNextPeer(int32_t wait);
virtual void onAbort(Exception* ex);
public:
- PeerInteractionCommand(int cuid,
+ PeerInteractionCommand(int32_t cuid,
const PeerHandle& peer,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
const SocketHandle& s,
- int sequence);
+ Seq sequence);
- ~PeerInteractionCommand();
+ virtual ~PeerInteractionCommand();
- enum Seq {
- INITIATOR_SEND_HANDSHAKE,
- INITIATOR_WAIT_HANDSHAKE,
- RECEIVER_SEND_HANDSHAKE,
- RECEIVER_WAIT_HANDSHAKE,
- WIRED};
};
#endif // _D_PEER_INTERACTION_COMMAND_H_
diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc
index 1eab4818..e9e7b11c 100644
--- a/src/PeerListenCommand.cc
+++ b/src/PeerListenCommand.cc
@@ -38,7 +38,7 @@
#include "CUIDCounter.h"
#include "message.h"
-PeerListenCommand::PeerListenCommand(int cuid,
+PeerListenCommand::PeerListenCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext)
:BtContextAwareCommand(cuid, btContext),
@@ -47,11 +47,11 @@ PeerListenCommand::PeerListenCommand(int cuid,
PeerListenCommand::~PeerListenCommand() {}
-int PeerListenCommand::bindPort(int portRangeStart, int portRangeEnd) {
+int32_t PeerListenCommand::bindPort(int32_t portRangeStart, int32_t portRangeEnd) {
if(portRangeStart > portRangeEnd) {
return -1;
}
- for(int port = portRangeStart; port <= portRangeEnd; port++) {
+ for(int32_t port = portRangeStart; port <= portRangeEnd; port++) {
try {
socket->beginListen(port);
logger->info(MSG_LISTENING_PORT,
@@ -71,13 +71,13 @@ bool PeerListenCommand::execute() {
if(btRuntime->isHalt()) {
return true;
}
- for(int i = 0; i < 3 && socket->isReadable(0); i++) {
+ for(int32_t i = 0; i < 3 && socket->isReadable(0); i++) {
SocketHandle peerSocket;
try {
peerSocket = socket->acceptConnection();
- pair<string, int> peerInfo;
+ pair<string, int32_t> peerInfo;
peerSocket->getPeerInfo(peerInfo);
- pair<string, int> localInfo;
+ pair<string, int32_t> localInfo;
peerSocket->getAddrInfo(localInfo);
TransferStat tstat = peerStorage->calculateStat();
diff --git a/src/PeerListenCommand.h b/src/PeerListenCommand.h
index 815b622f..e385da2d 100644
--- a/src/PeerListenCommand.h
+++ b/src/PeerListenCommand.h
@@ -44,15 +44,15 @@ private:
SocketHandle socket;
int32_t _lowestSpeedLimit;
public:
- PeerListenCommand(int cuid,
+ PeerListenCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext);
- ~PeerListenCommand();
+ virtual ~PeerListenCommand();
bool execute();
- int bindPort(int portRangeStart, int portRangeEnd);
+ int32_t bindPort(int32_t portRangeStart, int32_t portRangeEnd);
void setLowestSpeedLimit(int32_t speed)
{
diff --git a/src/PeerStat.h b/src/PeerStat.h
index 9b90eac0..176cf9b0 100644
--- a/src/PeerStat.h
+++ b/src/PeerStat.h
@@ -48,14 +48,14 @@ public:
REQUEST_IDLE,
};
private:
- int cuid;
+ int32_t cuid;
SpeedCalc downloadSpeed;
SpeedCalc uploadSpeed;
Time downloadStartTime;
PeerStat::STATUS status;
public:
- PeerStat(int cuid = 0):cuid(cuid), status(PeerStat::IDLE) {}
+ PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE) {}
~PeerStat() {}
@@ -78,27 +78,27 @@ public:
return uploadSpeed.calculateSpeed(now);
}
- void updateDownloadLength(int bytes) {
+ void updateDownloadLength(int32_t bytes) {
downloadSpeed.update(bytes);
}
- void updateUploadLength(int bytes) {
+ void updateUploadLength(int32_t bytes) {
uploadSpeed.update(bytes);
}
- int getMaxDownloadSpeed() const {
+ int32_t getMaxDownloadSpeed() const {
return downloadSpeed.getMaxSpeed();
}
- int getMaxUploadSpeed() const {
+ int32_t getMaxUploadSpeed() const {
return uploadSpeed.getMaxSpeed();
}
- int getAvgDownloadSpeed() const {
+ int32_t getAvgDownloadSpeed() const {
return downloadSpeed.getAvgSpeed();
}
- int getAvgUploadSpeed() const {
+ int32_t getAvgUploadSpeed() const {
return uploadSpeed.getAvgSpeed();
}
@@ -130,7 +130,7 @@ public:
return status;
}
- int getCuid() const {
+ int32_t getCuid() const {
return cuid;
}
};
diff --git a/src/Piece.cc b/src/Piece.cc
index f73cf83c..e227bbaa 100644
--- a/src/Piece.cc
+++ b/src/Piece.cc
@@ -38,7 +38,7 @@
Piece::Piece():index(0), length(0), bitfield(0) {}
-Piece::Piece(int index, int length):index(index), length(length) {
+Piece::Piece(int32_t index, int32_t length):index(index), length(length) {
bitfield =
BitfieldManFactory::getFactoryInstance()->createBitfieldMan(BLOCK_LENGTH, length);
}
@@ -54,7 +54,7 @@ Piece::Piece(const Piece& piece) {
}
-void Piece::completeBlock(int blockIndex) {
+void Piece::completeBlock(int32_t blockIndex) {
bitfield->setBit(blockIndex);
bitfield->unsetUseBit(blockIndex);
}
@@ -72,12 +72,12 @@ bool Piece::pieceComplete() const {
return bitfield->isAllBitSet();
}
-void Piece::cancelBlock(int blockIndex) {
+void Piece::cancelBlock(int32_t blockIndex) {
bitfield->unsetUseBit(blockIndex);
}
-int Piece::getMissingUnusedBlockIndex() const {
- int blockIndex = bitfield->getFirstMissingUnusedIndex();
+int32_t Piece::getMissingUnusedBlockIndex() const {
+ int32_t blockIndex = bitfield->getFirstMissingUnusedIndex();
if(blockIndex == -1) {
return blockIndex;
}
@@ -85,8 +85,8 @@ int Piece::getMissingUnusedBlockIndex() const {
return blockIndex;
}
-int Piece::getMissingBlockIndex() const {
- int blockIndex = bitfield->getMissingIndex();
+int32_t Piece::getMissingBlockIndex() const {
+ int32_t blockIndex = bitfield->getMissingIndex();
if(blockIndex == -1) {
return blockIndex;
}
diff --git a/src/Piece.h b/src/Piece.h
index 26d83bd3..8b779560 100644
--- a/src/Piece.h
+++ b/src/Piece.h
@@ -42,13 +42,13 @@
class Piece {
private:
- int index;
- int length;
+ int32_t index;
+ int32_t length;
BitfieldMan* bitfield;
public:
Piece();
- Piece(int index, int length);
+ Piece(int32_t index, int32_t length);
Piece(const Piece& piece);
@@ -76,15 +76,15 @@ public:
return index == piece.index;
}
- int getMissingUnusedBlockIndex() const;
- int getMissingBlockIndex() const;
+ int32_t getMissingUnusedBlockIndex() const;
+ int32_t getMissingBlockIndex() const;
BlockIndexes getAllMissingBlockIndexes() const;
- void completeBlock(int blockIndex);
- void cancelBlock(int blockIndex);
- int countCompleteBlock() const {
+ void completeBlock(int32_t blockIndex);
+ void cancelBlock(int32_t blockIndex);
+ int32_t countCompleteBlock() const {
return bitfield->countBlock()-bitfield->countMissingBlock();
}
- bool hasBlock(int blockIndex) const {
+ bool hasBlock(int32_t blockIndex) const {
return bitfield->isBitSet(blockIndex);
}
/**
@@ -92,20 +92,20 @@ public:
* returns false.
*/
bool pieceComplete() const;
- int countBlock() const { return bitfield->countBlock(); }
- int getBlockLength(int index) const {
+ int32_t countBlock() const { return bitfield->countBlock(); }
+ int32_t getBlockLength(int32_t index) const {
return bitfield->getBlockLength(index);
}
- int getBlockLength() const { return bitfield->getBlockLength(); }
- int getIndex() const { return index; }
- void setIndex(int index) { this->index = index; }
- int getLength() const { return length; }
- void setLength(int index) { this->length = length; }
+ int32_t getBlockLength() const { return bitfield->getBlockLength(); }
+ int32_t getIndex() const { return index; }
+ void setIndex(int32_t index) { this->index = index; }
+ int32_t getLength() const { return length; }
+ void setLength(int32_t index) { this->length = length; }
const unsigned char* getBitfield() const { return bitfield->getBitfield(); }
- void setBitfield(const unsigned char* bitfield, int len);
+ void setBitfield(const unsigned char* bitfield, int32_t len);
- int getBitfieldLength() const {
+ int32_t getBitfieldLength() const {
return bitfield->getBitfieldLength();
}
@@ -114,7 +114,7 @@ public:
string toString() const;
- bool isBlockUsed(int index) const {
+ bool isBlockUsed(int32_t index) const {
return bitfield->isUseBitSet(index);
}
};
diff --git a/src/PieceStorage.h b/src/PieceStorage.h
index b96d70bf..e41aeea6 100644
--- a/src/PieceStorage.h
+++ b/src/PieceStorage.h
@@ -70,7 +70,7 @@ public:
* Returns the piece denoted by index.
* No status of the piece is changed in this method.
*/
- virtual PieceHandle getPiece(int index) = 0;
+ virtual PieceHandle getPiece(int32_t index) = 0;
/**
* Tells that the download of the specfied piece completes.
@@ -86,15 +86,15 @@ public:
* Returns true if the specified piece is already downloaded.
* Otherwise returns false.
*/
- virtual bool hasPiece(int index) = 0;
+ virtual bool hasPiece(int32_t index) = 0;
- virtual long long int getTotalLength() = 0;
+ virtual int64_t getTotalLength() = 0;
- virtual long long int getFilteredTotalLength() = 0;
+ virtual int64_t getFilteredTotalLength() = 0;
- virtual long long int getCompletedLength() = 0;
+ virtual int64_t getCompletedLength() = 0;
- virtual long long int getFilteredCompletedLength() = 0;
+ virtual int64_t getFilteredCompletedLength() = 0;
virtual void setFileFilter(const Strings& filePaths) = 0;
@@ -124,9 +124,9 @@ public:
virtual const unsigned char* getBitfield() = 0;
virtual void setBitfield(const unsigned char* bitfield,
- int bitfieldLength) = 0;
+ int32_t bitfieldLength) = 0;
- virtual int getBitfieldLength() = 0;
+ virtual int32_t getBitfieldLength() = 0;
virtual bool isSelectiveDownloadingMode() = 0;
@@ -136,26 +136,26 @@ public:
virtual DiskAdaptorHandle getDiskAdaptor() = 0;
- virtual int getPieceLength(int index) = 0;
+ virtual int32_t getPieceLength(int32_t index) = 0;
/**
* Adds piece index to advertise to other commands. They send have message
* based on this information.
*/
- virtual void advertisePiece(int cuid, int index) = 0;
+ virtual void advertisePiece(int32_t cuid, int32_t index) = 0;
/**
* Returns piece index which is not advertised by the caller command and
* newer than lastCheckTime.
*/
- virtual Integers getAdvertisedPieceIndexes(int myCuid,
+ virtual Integers getAdvertisedPieceIndexes(int32_t myCuid,
const Time& lastCheckTime) = 0;
/**
* Removes have entry if specified seconds have elapsed since its
* registration.
*/
- virtual void removeAdvertisedPiece(int elapsed) = 0;
+ virtual void removeAdvertisedPiece(int32_t elapsed) = 0;
/**
* Sets all bits in bitfield to 1.
diff --git a/src/Randomizer.h b/src/Randomizer.h
index cbfcc8bb..aa4be677 100644
--- a/src/Randomizer.h
+++ b/src/Randomizer.h
@@ -41,9 +41,9 @@ class Randomizer {
public:
virtual ~Randomizer() {}
- virtual int getRandomNumber() = 0;
+ virtual long int getRandomNumber() = 0;
- virtual int getMaxRandomNumber() = 0;
+ virtual long int getMaxRandomNumber() = 0;
};
typedef SharedHandle<Randomizer> RandomizerHandle;
diff --git a/src/Request.cc b/src/Request.cc
index ffc9455e..938c6186 100644
--- a/src/Request.cc
+++ b/src/Request.cc
@@ -95,7 +95,7 @@ bool Request::parseUrl(const string& url) {
string::size_type hp = tempUrl.find("://");
if(hp == string::npos) return false;
protocol = tempUrl.substr(0, hp);
- int defPort;
+ int32_t defPort;
if((defPort = FeatureConfig::getInstance()->getDefaultPort(protocol)) == 0) {
return false;
}
@@ -109,7 +109,7 @@ bool Request::parseUrl(const string& url) {
Util::split(hostAndPort, tempUrl.substr(hp, hep-hp), ':');
host = hostAndPort.first;
if(hostAndPort.second != "") {
- port = (int)strtol(hostAndPort.second.c_str(), NULL, 10);
+ port = strtol(hostAndPort.second.c_str(), NULL, 10);
if(!(0 < port && port <= 65535)) {
return false;
}
diff --git a/src/Request.h b/src/Request.h
index 0b4f71c7..73fdd833 100644
--- a/src/Request.h
+++ b/src/Request.h
@@ -51,6 +51,14 @@
#define METALINK_MARK "#!metalink3!"
class Request {
+public:
+ enum TRACKER_EVENT {
+ AUTO,
+ STARTED,
+ STOPPED,
+ COMPLETED,
+ AFTER_COMPLETED
+ };
private:
string url;
string currentUrl;
@@ -64,11 +72,11 @@ private:
string referer;
string protocol;
string host;
- int port;
+ int32_t port;
string dir;
string file;
- int tryCount;
- int trackerEvent;
+ int32_t tryCount;
+ TRACKER_EVENT trackerEvent;
bool keepAlive;
string method;
@@ -95,7 +103,7 @@ public:
bool resetUrl();
void resetTryCount() { tryCount = 0; }
void addTryCount() { tryCount++; }
- int getTryCount() const { return tryCount; }
+ int32_t getTryCount() const { return tryCount; }
//bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
string getUrl() const { return url; }
@@ -105,13 +113,13 @@ public:
void setReferer(const string& url) { referer = previousUrl = url; }
string getProtocol() const { return protocol; }
string getHost() const { return host; }
- int getPort() const { return port; }
+ int32_t getPort() const { return port; }
string getDir() const { return dir; }
string getFile() const { return file;}
bool isKeepAlive() const { return keepAlive; }
void setKeepAlive(bool keepAlive) { this->keepAlive = keepAlive; }
- void setTrackerEvent(int event) { trackerEvent = event; }
- int getTrackerEvent() const { return trackerEvent; }
+ void setTrackerEvent(TRACKER_EVENT event) { trackerEvent = event; }
+ TRACKER_EVENT getTrackerEvent() const { return trackerEvent; }
void setMethod(const string& method) {
this->method = method;
@@ -145,14 +153,6 @@ public:
static const string METHOD_GET;
static const string METHOD_HEAD;
- enum TRACKER_EVENT {
- AUTO,
- STARTED,
- STOPPED,
- COMPLETED,
- AFTER_COMPLETED
- };
-
};
typedef SharedHandle<Request> RequestHandle;
diff --git a/src/RequestGroupEntry.h b/src/RequestGroupEntry.h
index a294d7fc..157f3048 100644
--- a/src/RequestGroupEntry.h
+++ b/src/RequestGroupEntry.h
@@ -43,13 +43,13 @@ class DownloadCommand;
class RequestGroupEntry : public ProgressAwareEntry {
protected:
- int _cuid;
+ int32_t _cuid;
RequestHandle _currentRequest;
RequestGroup* _requestGroup;
DownloadCommand* _nextDownloadCommand;
bool _shouldAddNumConnection;
public:
- RequestGroupEntry(int cuid,
+ RequestGroupEntry(int32_t cuid,
const RequestHandle& currentRequest,
RequestGroup* requestGroup,
DownloadCommand* nextDownloadCommand = 0):
@@ -73,7 +73,7 @@ public:
return _requestGroup->getTotalLength();
}
- int getCUID() const
+ int32_t getCUID() const
{
return _cuid;
}
diff --git a/src/RequestSlot.cc b/src/RequestSlot.cc
index eae5de48..bba41f5a 100644
--- a/src/RequestSlot.cc
+++ b/src/RequestSlot.cc
@@ -64,7 +64,7 @@ bool RequestSlot::isTimeout(time_t timeoutSec) const {
return dispatchedTime.elapsed(timeoutSec);
}
-int RequestSlot::getLatencyInMillis() const {
+int32_t RequestSlot::getLatencyInMillis() const {
return dispatchedTime.differenceInMillis();
}
diff --git a/src/RequestSlot.h b/src/RequestSlot.h
index d457b9ff..aaa2c307 100644
--- a/src/RequestSlot.h
+++ b/src/RequestSlot.h
@@ -68,7 +68,7 @@ public:
void setDispatchedTime(time_t secFromEpoch);
bool isTimeout(time_t timeoutSec) const;
- int getLatencyInMillis() const;
+ int32_t getLatencyInMillis() const;
int32_t getIndex() const { return index; }
void setIndex(int32_t index) { this->index = index; }
diff --git a/src/Segment.h b/src/Segment.h
index 20e72a58..d082fbc1 100644
--- a/src/Segment.h
+++ b/src/Segment.h
@@ -42,12 +42,12 @@ using namespace std;
class Segment {
public:
- int index;
- int length;
- int segmentLength;
- int writtenLength;
+ int32_t index;
+ int32_t length;
+ int32_t segmentLength;
+ int32_t writtenLength;
- Segment(int index, int length, int segmentLength, int writtenLength = 0)
+ Segment(int32_t index, int32_t length, int32_t segmentLength, int32_t writtenLength = 0)
:index(index), length(length), segmentLength(segmentLength),
writtenLength(writtenLength) {}
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index 0664fe81..60547d8b 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -111,12 +111,12 @@ void SegmentMan::save() const {
if(fwrite(&totalSize, sizeof(totalSize), 1, segFile) < 1) {
throw string("writeError");
}
- int segmentLength = bitfield->getBlockLength();
+ int32_t segmentLength = bitfield->getBlockLength();
if(fwrite(&segmentLength, sizeof(segmentLength), 1, segFile) < 1) {
throw string("writeError");
}
if(bitfield) {
- int bitfieldLength = bitfield->getBitfieldLength();
+ int32_t bitfieldLength = bitfield->getBitfieldLength();
if(fwrite(&bitfieldLength, sizeof(bitfieldLength), 1, segFile) < 1) {
throw string("writeError");
}
@@ -125,12 +125,12 @@ void SegmentMan::save() const {
throw string("writeError");
}
} else {
- int i = 0;
+ int32_t i = 0;
if(fwrite(&i, sizeof(i), 1, segFile) < 1) {
throw string("writeError");
}
}
- int usedSegmentCount = usedSegmentEntries.size();
+ int32_t usedSegmentCount = usedSegmentEntries.size();
if(fwrite(&usedSegmentCount, sizeof(usedSegmentCount), 1, segFile) < 1) {
throw string("writeError");
}
@@ -163,11 +163,11 @@ void SegmentMan::read(FILE* file) {
if(fread(&totalSize, sizeof(totalSize), 1, file) < 1) {
throw string("readError");
}
- int segmentSize;
+ int32_t segmentSize;
if(fread(&segmentSize, sizeof(segmentSize), 1, file) < 1) {
throw string("readError");
}
- int bitfieldLength;
+ int32_t bitfieldLength;
if(fread(&bitfieldLength, sizeof(bitfieldLength), 1, file) < 1) {
throw string("readError");
}
@@ -182,7 +182,7 @@ void SegmentMan::read(FILE* file) {
delete [] savedBitfield;
}
}
- int segmentCount;
+ int32_t segmentCount;
if(fread(&segmentCount, sizeof(segmentCount), 1, file) < 1) {
throw string("readError");
}
@@ -277,7 +277,7 @@ SegmentHandle SegmentMan::onNullBitfield(int32_t cuid) {
}
SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peerStat) const {
- int speed = (int)(peerStat->getAvgDownloadSpeed()*0.8);
+ int32_t speed = (int32_t)(peerStat->getAvgDownloadSpeed()*0.8);
SegmentEntryHandle slowSegmentEntry(0);
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
itr != usedSegmentEntries.end(); ++itr) {
@@ -291,7 +291,7 @@ SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peer
!p->getDownloadStartTime().elapsed(option->getAsInt(PREF_STARTUP_IDLE_TIME))) {
continue;
}
- int pSpeed = p->calculateDownloadSpeed();
+ int32_t pSpeed = p->calculateDownloadSpeed();
if(pSpeed < speed) {
speed = pSpeed;
slowSegmentEntry = segmentEntry;
@@ -308,7 +308,7 @@ SegmentHandle SegmentMan::getSegment(int32_t cuid) {
if(!segmentEntry.isNull()) {
return segmentEntry->segment;
}
- int index = bitfield->getSparseMissingUnusedIndex();
+ int32_t index = bitfield->getSparseMissingUnusedIndex();
if(index == -1) {
PeerStatHandle myPeerStat = getPeerStat(cuid);
if(!myPeerStat.get()) {
@@ -423,7 +423,7 @@ void SegmentMan::registerPeerStat(const PeerStatHandle& peerStat) {
}
int32_t SegmentMan::calculateDownloadSpeed() const {
- int speed = 0;
+ int32_t speed = 0;
for(PeerStats::const_iterator itr = peerStats.begin();
itr != peerStats.end(); itr++) {
const PeerStatHandle& peerStat = *itr;
diff --git a/src/SegmentMan.h b/src/SegmentMan.h
index 33f84cfc..1dc869c2 100644
--- a/src/SegmentMan.h
+++ b/src/SegmentMan.h
@@ -50,10 +50,10 @@ using namespace std;
class SegmentEntry {
public:
- int cuid;
+ int32_t cuid;
SegmentHandle segment;
public:
- SegmentEntry(int cuid, const SegmentHandle& segment)
+ SegmentEntry(int32_t cuid, const SegmentHandle& segment)
:cuid(cuid), segment(segment) {}
~SegmentEntry() {}
};
@@ -77,7 +77,7 @@ private:
SegmentHandle onNullBitfield(int32_t cuid);
SegmentHandle checkoutSegment(int32_t cuid, int32_t index);
SegmentEntryHandle findSlowerSegmentEntry(const PeerStatHandle& peerStat) const;
- SegmentEntryHandle getSegmentEntryByIndex(int index) {
+ SegmentEntryHandle getSegmentEntryByIndex(int32_t index) {
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
itr != usedSegmentEntries.end(); ++itr) {
const SegmentEntryHandle& segmentEntry = *itr;
@@ -88,7 +88,7 @@ private:
return 0;
}
- SegmentEntryHandle getSegmentEntryByCuid(int cuid) {
+ SegmentEntryHandle getSegmentEntryByCuid(int32_t cuid) {
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
itr != usedSegmentEntries.end(); ++itr) {
const SegmentEntryHandle& segmentEntry = *itr;
@@ -99,7 +99,7 @@ private:
return 0;
}
- SegmentEntries::iterator getSegmentEntryIteratorByCuid(int cuid) {
+ SegmentEntries::iterator getSegmentEntryIteratorByCuid(int32_t cuid) {
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
itr != usedSegmentEntries.end(); ++itr) {
const SegmentEntryHandle& segmentEntry = *itr;
@@ -151,7 +151,7 @@ public:
/**
* Represents the number of failures(usually, DlAbortEx) in downloads.
*/
- int errors;
+ int32_t errors;
const Option* option;
DiskWriterHandle diskWriter;
@@ -268,7 +268,7 @@ public:
* Returns peerStat whose cuid is given cuid. If it is not found, returns
* 0.
*/
- PeerStatHandle getPeerStat(int cuid) const {
+ PeerStatHandle getPeerStat(int32_t cuid) const {
for(PeerStats::const_iterator itr = peerStats.begin(); itr != peerStats.end(); ++itr) {
const PeerStatHandle& peerStat = *itr;
if(peerStat->getCuid() == cuid) {
diff --git a/src/ShareRatioSeedCriteria.h b/src/ShareRatioSeedCriteria.h
index 8a7b9a27..0b5b9f55 100644
--- a/src/ShareRatioSeedCriteria.h
+++ b/src/ShareRatioSeedCriteria.h
@@ -66,7 +66,7 @@ public:
return false;
}
TransferStat stat = peerStorage->calculateStat();
- long long int allTimeUploadLength =
+ int64_t allTimeUploadLength =
btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength();
return ratio <=
((double)allTimeUploadLength)/pieceStorage->getCompletedLength();
diff --git a/src/SimpleBtMessage.cc b/src/SimpleBtMessage.cc
index 587c3c9e..d9b24195 100644
--- a/src/SimpleBtMessage.cc
+++ b/src/SimpleBtMessage.cc
@@ -46,14 +46,14 @@ void SimpleBtMessage::send() {
}
if(sendPredicate() || sendingInProgress) {
const unsigned char* msg = getMessage();
- int msgLength = getMessageLength();
+ int32_t msgLength = getMessageLength();
if(!sendingInProgress) {
logger->info(MSG_SEND_PEER_MESSAGE,
cuid, peer->ipaddr.c_str(), peer->port, toString().c_str());
leftDataLength = getMessageLength();
}
sendingInProgress = false;
- int writtenLength = peerConnection->sendMessage(msg+msgLength-leftDataLength, leftDataLength);
+ int32_t writtenLength = peerConnection->sendMessage(msg+msgLength-leftDataLength, leftDataLength);
if(writtenLength == leftDataLength) {
onSendComplete();
} else {
diff --git a/src/SimpleBtMessage.h b/src/SimpleBtMessage.h
index 241398a8..6747d95b 100644
--- a/src/SimpleBtMessage.h
+++ b/src/SimpleBtMessage.h
@@ -39,7 +39,7 @@
class SimpleBtMessage : public AbstractBtMessage {
private:
- int leftDataLength;
+ int32_t leftDataLength;
public:
SimpleBtMessage();
diff --git a/src/SimpleLogger.cc b/src/SimpleLogger.cc
index cddead03..68c56e5c 100644
--- a/src/SimpleLogger.cc
+++ b/src/SimpleLogger.cc
@@ -72,7 +72,7 @@ void SimpleLogger::closeFile() {
}
}
-void SimpleLogger::setStdout(int level, bool enabled) {
+void SimpleLogger::setStdout(Logger::LEVEL level, bool enabled) {
if(enabled) {
stdoutField |= level;
} else {
@@ -84,7 +84,7 @@ void SimpleLogger::writeHeader(FILE* file, string date, string level) const {
fprintf(file, "%s %s - ", date.c_str(), level.c_str());
}
-void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e, bool printHeader) const
+void SimpleLogger::writeLog(FILE* file, Logger::LEVEL level, const char* msg, va_list ap, Exception* e, bool printHeader) const
{
string levelStr;
switch(level) {
@@ -125,7 +125,7 @@ void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap,
fflush(file);
}
-void SimpleLogger::writeFile(int level, const char* msg, va_list ap, Exception* e) const {
+void SimpleLogger::writeFile(Logger::LEVEL level, const char* msg, va_list ap, Exception* e) const {
writeLog(file, level, msg, ap, e);
if(stdoutField&level) {
fprintf(stdout, "\n");
diff --git a/src/SimpleLogger.h b/src/SimpleLogger.h
index e3e83c30..1773a79e 100644
--- a/src/SimpleLogger.h
+++ b/src/SimpleLogger.h
@@ -39,11 +39,11 @@
class SimpleLogger:public Logger {
private:
- void writeFile(int level, const char* msg, va_list ap, Exception* e = 0) const;
+ void writeFile(Logger::LEVEL level, const char* msg, va_list ap, Exception* e = 0) const;
void writeHeader(FILE* file, string date, string level) const;
- void writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e = 0, bool printHeader = true) const;
+ void writeLog(FILE* file, Logger::LEVEL level, const char* msg, va_list ap, Exception* e = 0, bool printHeader = true) const;
FILE* file;
- int stdoutField;
+ int32_t stdoutField;
public:
SimpleLogger(FILE* logfile = 0);
~SimpleLogger();
@@ -61,7 +61,7 @@ public:
virtual void error(const char* msg, ...) const;
virtual void error(const char* msg, Exception* ex, ...) const;
- void setStdout(int level, bool enabled);
+ void setStdout(Logger::LEVEL level, bool enabled);
};
#endif // _D_SIMPLE_LOGGER_H_
diff --git a/src/SimpleRandomizer.h b/src/SimpleRandomizer.h
index 13534034..bdbcfc57 100644
--- a/src/SimpleRandomizer.h
+++ b/src/SimpleRandomizer.h
@@ -59,12 +59,12 @@ public:
virtual ~SimpleRandomizer() {}
- virtual int getRandomNumber() {
+ virtual long int getRandomNumber() {
return random();
}
- virtual int getMaxRandomNumber() {
- return RAND_MAX;
+ virtual long int getMaxRandomNumber() {
+ return RAND_MAX;
}
};
diff --git a/src/SleepCommand.cc b/src/SleepCommand.cc
index 5390c70f..aa13c07f 100644
--- a/src/SleepCommand.cc
+++ b/src/SleepCommand.cc
@@ -35,7 +35,7 @@
#include "SleepCommand.h"
#include "Util.h"
-SleepCommand::SleepCommand(int cuid, DownloadEngine* e, Command* nextCommand, int wait):
+SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, int32_t wait):
Command(cuid), engine(e), nextCommand(nextCommand), wait(wait) {}
SleepCommand::~SleepCommand() {
diff --git a/src/SleepCommand.h b/src/SleepCommand.h
index 33d9f4d1..f4f1ee20 100644
--- a/src/SleepCommand.h
+++ b/src/SleepCommand.h
@@ -43,11 +43,11 @@ class SleepCommand:public Command {
private:
DownloadEngine* engine;
Command* nextCommand;
- int wait;
+ int32_t wait;
Time checkPoint;
public:
- SleepCommand(int cuid, DownloadEngine* e, Command* nextCommand, int wait);
- ~SleepCommand();
+ SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, int32_t wait);
+ virtual ~SleepCommand();
bool execute();
};
diff --git a/src/Socket.cc b/src/Socket.cc
index c94dc696..b8a01f6d 100644
--- a/src/Socket.cc
+++ b/src/Socket.cc
@@ -66,15 +66,15 @@ Socket& Socket::operator=(const Socket& s) {
return *this;
}
-void Socket::beginListen(int port) const {
+void Socket::beginListen(int32_t port) const {
core->beginListen(port);
}
-void Socket::getAddrInfo(pair<string, int>& addrinfo) const {
+void Socket::getAddrInfo(pair<string, int32_t>& addrinfo) const {
core->getAddrInfo(addrinfo);
}
-void Socket::getPeerInfo(pair<string, int>& peerinfo) const {
+void Socket::getPeerInfo(pair<string, int32_t>& peerinfo) const {
core->getPeerInfo(peerinfo);
}
@@ -82,7 +82,7 @@ Socket* Socket::acceptConnection() const {
return new Socket(core->acceptConnection());
}
-void Socket::establishConnection(const string& host, int port) const {
+void Socket::establishConnection(const string& host, int32_t port) const {
core->establishConnection(host, port);
}
@@ -94,15 +94,15 @@ void Socket::closeConnection() const {
core->closeConnection();
}
-bool Socket::isWritable(int timeout) const {
+bool Socket::isWritable(int32_t timeout) const {
return core->isWritable(timeout);
}
-bool Socket::isReadable(int timeout) const {
+bool Socket::isReadable(int32_t timeout) const {
return core->isReadable(timeout);
}
-void Socket::writeData(const char* data, int len) const {
+void Socket::writeData(const char* data, int32_t len) const {
core->writeData(data, len);
}
@@ -110,11 +110,11 @@ void Socket::writeData(const string& str) const {
core->writeData(str.c_str(), str.size());
}
-void Socket::readData(char* data, int& len) const {
+void Socket::readData(char* data, int32_t& len) const {
core->readData(data, len);
}
-void Socket::peekData(char* data, int& len) const {
+void Socket::peekData(char* data, int32_t& len) const {
core->peekData(data, len);
}
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
index 2c67a66d..8422ed74 100644
--- a/src/SocketCore.cc
+++ b/src/SocketCore.cc
@@ -51,7 +51,7 @@ SocketCore::SocketCore():sockfd(-1) {
init();
}
-SocketCore::SocketCore(int sockfd):sockfd(sockfd) {
+SocketCore::SocketCore(int32_t sockfd):sockfd(sockfd) {
init();
}
@@ -79,7 +79,7 @@ SocketCore::~SocketCore() {
#endif // HAVE_LIBGNUTLS
}
-void SocketCore::beginListen(int port) {
+void SocketCore::beginListen(int32_t port) {
closeConnection();
//sockfd = socket(AF_UNSPEC, SOCK_STREAM, PF_UNSPEC);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -114,7 +114,7 @@ SocketCore* SocketCore::acceptConnection() const {
struct sockaddr_in sockaddr;
socklen_t len = sizeof(sockaddr);
memset((char*)&sockaddr, 0, sizeof(sockaddr));
- int fd;
+ int32_t fd;
if((fd = accept(sockfd, (struct sockaddr*)&sockaddr, &len)) == -1) {
throw new DlAbortEx(EX_SOCKET_ACCEPT, strerror(errno));
}
@@ -123,7 +123,7 @@ SocketCore* SocketCore::acceptConnection() const {
return s;
}
-void SocketCore::getAddrInfo(pair<string, int>& addrinfo) const {
+void SocketCore::getAddrInfo(pair<string, int32_t>& addrinfo) const {
struct sockaddr_in listenaddr;
memset((char*)&listenaddr, 0, sizeof(listenaddr));
socklen_t len = sizeof(listenaddr);
@@ -134,10 +134,10 @@ void SocketCore::getAddrInfo(pair<string, int>& addrinfo) const {
addrinfo.second = ntohs(listenaddr.sin_port);
}
-void SocketCore::getPeerInfo(pair<string, int>& peerinfo) const {
+void SocketCore::getPeerInfo(pair<string, int32_t>& peerinfo) const {
struct sockaddr_in peerin;
memset(&peerin, 0, sizeof(peerin));
- int len = sizeof(peerin);
+ int32_t len = sizeof(peerin);
if(getpeername(sockfd, (struct sockaddr*)&peerin, (socklen_t*)&len) < 0) {
throw new DlAbortEx(EX_SOCKET_GET_PEER, strerror(errno));
}
@@ -145,7 +145,7 @@ void SocketCore::getPeerInfo(pair<string, int>& peerinfo) const {
peerinfo.second = ntohs(peerin.sin_port);
}
-void SocketCore::establishConnection(const string& host, int port) {
+void SocketCore::establishConnection(const string& host, int32_t port) {
closeConnection();
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == -1) {
@@ -172,7 +172,7 @@ void SocketCore::establishConnection(const string& host, int port) {
ai.ai_socktype = SOCK_STREAM;
ai.ai_protocol = 0;
struct addrinfo* res;
- int ec;
+ int32_t ec;
if((ec = getaddrinfo(host.c_str(), NULL, &ai, &res)) != 0) {
throw new DlAbortEx(EX_RESOLVE_HOSTNAME,
host.c_str(), gai_strerror(ec));
@@ -188,13 +188,13 @@ void SocketCore::establishConnection(const string& host, int port) {
}
void SocketCore::setNonBlockingMode() const {
- int flags = fcntl(sockfd, F_GETFL, 0);
+ int32_t flags = fcntl(sockfd, F_GETFL, 0);
// TODO add error handling
fcntl(sockfd, F_SETFL, flags|O_NONBLOCK);
}
void SocketCore::setBlockingMode() const {
- int flags = fcntl(sockfd, F_GETFL, 0);
+ int32_t flags = fcntl(sockfd, F_GETFL, 0);
// TODO add error handling
fcntl(sockfd, F_SETFL, flags&(~O_NONBLOCK));
}
@@ -230,7 +230,7 @@ void SocketCore::closeConnection() {
#endif // HAVE_LIBGNUTLS
}
-bool SocketCore::isWritable(int timeout) const {
+bool SocketCore::isWritable(int32_t timeout) const {
fd_set fds;
FD_ZERO(&fds);
FD_SET(sockfd, &fds);
@@ -239,7 +239,7 @@ bool SocketCore::isWritable(int timeout) const {
tv.tv_sec = timeout;
tv.tv_usec = 0;
- int r = select(sockfd+1, NULL, &fds, NULL, &tv);
+ int32_t r = select(sockfd+1, NULL, &fds, NULL, &tv);
if(r == 1) {
return true;
} else if(r == 0) {
@@ -254,7 +254,7 @@ bool SocketCore::isWritable(int timeout) const {
}
}
-bool SocketCore::isReadable(int timeout) const {
+bool SocketCore::isReadable(int32_t timeout) const {
#ifdef HAVE_LIBGNUTLS
if(secure && peekBufLength > 0) {
return true;
@@ -268,7 +268,7 @@ bool SocketCore::isReadable(int timeout) const {
tv.tv_sec = timeout;
tv.tv_usec = 0;
- int r = select(sockfd+1, &fds, NULL, NULL, &tv);
+ int32_t r = select(sockfd+1, &fds, NULL, NULL, &tv);
if(r == 1) {
return true;
} else if(r == 0) {
@@ -283,8 +283,8 @@ bool SocketCore::isReadable(int timeout) const {
}
}
-void SocketCore::writeData(const char* data, int len) {
- int ret = 0;
+void SocketCore::writeData(const char* data, int32_t len) {
+ int32_t ret = 0;
if(!secure && (ret = send(sockfd, data, (size_t)len, 0)) != len
#ifdef HAVE_LIBSSL
// for SSL
@@ -309,8 +309,8 @@ void SocketCore::writeData(const char* data, int len) {
}
}
-void SocketCore::readData(char* data, int& len) {
- int ret = 0;
+void SocketCore::readData(char* data, int32_t& len) {
+ int32_t ret = 0;
if(!secure && (ret = recv(sockfd, data, (size_t)len, 0)) < 0
#ifdef HAVE_LIBSSL
// for SSL
@@ -336,8 +336,8 @@ void SocketCore::readData(char* data, int& len) {
len = ret;
}
-void SocketCore::peekData(char* data, int& len) {
- int ret = 0;
+void SocketCore::peekData(char* data, int32_t& len) {
+ int32_t ret = 0;
if(!secure && (ret = recv(sockfd, data, (size_t)len, MSG_PEEK)) < 0
#ifdef HAVE_LIBSSL
// for SSL
@@ -364,10 +364,10 @@ void SocketCore::peekData(char* data, int& len) {
}
#ifdef HAVE_LIBGNUTLS
-int SocketCore::shiftPeekData(char* data, int len) {
+int32_t SocketCore::shiftPeekData(char* data, int32_t len) {
if(peekBufLength <= len) {
memcpy(data, peekBuf, peekBufLength);
- int ret = peekBufLength;
+ int32_t ret = peekBufLength;
peekBufLength = 0;
return ret;
} else {
@@ -382,7 +382,7 @@ int SocketCore::shiftPeekData(char* data, int len) {
}
-void SocketCore::addPeekData(char* data, int len) {
+void SocketCore::addPeekData(char* data, int32_t len) {
if(peekBufLength+len > peekBufMax) {
char* temp = new char[peekBufMax+len];
memcpy(temp, peekBuf, peekBufLength);
@@ -394,10 +394,10 @@ void SocketCore::addPeekData(char* data, int len) {
peekBufLength += len;
}
-int SocketCore::gnutlsRecv(char* data, int len) {
- int plen = shiftPeekData(data, len);
+int32_t SocketCore::gnutlsRecv(char* data, int32_t len) {
+ int32_t plen = shiftPeekData(data, len);
if(plen < len) {
- int ret = gnutls_record_recv(sslSession, data+plen, len-plen);
+ int32_t ret = gnutls_record_recv(sslSession, data+plen, len-plen);
if(ret < 0) {
throw new DlRetryEx(EX_SOCKET_RECV, gnutls_strerror(ret));
}
@@ -407,13 +407,13 @@ int SocketCore::gnutlsRecv(char* data, int len) {
}
}
-int SocketCore::gnutlsPeek(char* data, int len) {
+int32_t SocketCore::gnutlsPeek(char* data, int32_t len) {
if(peekBufLength >= len) {
memcpy(data, peekBuf, len);
return len;
} else {
memcpy(data, peekBuf, peekBufLength);
- int ret = gnutls_record_recv(sslSession, data+peekBufLength, len-peekBufLength);
+ int32_t ret = gnutls_record_recv(sslSession, data+peekBufLength, len-peekBufLength);
if(ret < 0) {
throw new DlRetryEx(EX_SOCKET_PEEK, gnutls_strerror(ret));
}
@@ -448,8 +448,8 @@ void SocketCore::initiateSecureConnection() {
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
if(!secure) {
- const int cert_type_priority[3] = { GNUTLS_CRT_X509,
- GNUTLS_CRT_OPENPGP, 0
+ const int32_t cert_type_priority[3] = { GNUTLS_CRT_X509,
+ GNUTLS_CRT_OPENPGP, 0
};
// while we do not support X509 certificate, most web servers require
// X509 stuff.
@@ -460,7 +460,7 @@ void SocketCore::initiateSecureConnection() {
// put the x509 credentials to the current session
gnutls_credentials_set(sslSession, GNUTLS_CRD_CERTIFICATE, sslXcred);
gnutls_transport_set_ptr(sslSession, (gnutls_transport_ptr_t)sockfd);
- int ret = gnutls_handshake(sslSession);
+ int32_t ret = gnutls_handshake(sslSession);
if(ret < 0) {
throw new DlAbortEx(gnutls_strerror(ret));
}
diff --git a/src/SocketCore.h b/src/SocketCore.h
index a5711191..4ec5f36d 100644
--- a/src/SocketCore.h
+++ b/src/SocketCore.h
@@ -55,9 +55,9 @@ class SocketCore {
friend bool operator<(const SocketCore& s1, const SocketCore& s2);
private:
// socket endpoint descriptor
- int sockfd;
+ int32_t sockfd;
// reference counter for this object.
- int use;
+ int32_t use;
bool secure;
#ifdef HAVE_LIBSSL
// for SSL
@@ -68,22 +68,22 @@ private:
gnutls_session_t sslSession;
gnutls_certificate_credentials_t sslXcred;
char* peekBuf;
- int peekBufLength;
- int peekBufMax;
+ int32_t peekBufLength;
+ int32_t peekBufMax;
- int shiftPeekData(char* data, int len);
- void addPeekData(char* data, int len);
- int gnutlsRecv(char* data, int len);
- int gnutlsPeek(char* data, int len);
+ int32_t shiftPeekData(char* data, int32_t len);
+ void addPeekData(char* data, int32_t len);
+ int32_t gnutlsRecv(char* data, int32_t len);
+ int32_t gnutlsPeek(char* data, int32_t len);
#endif // HAVE_LIBGNUTLS
void init();
- SocketCore(int sockfd);
+ SocketCore(int32_t sockfd);
public:
SocketCore();
~SocketCore();
- int getSockfd() const { return sockfd; }
+ int32_t getSockfd() const { return sockfd; }
bool isOpen() const { return sockfd != -1; }
@@ -92,19 +92,19 @@ public:
* @param port port to listen. If 0 is specified, os automaticaly
* choose avaiable port.
*/
- void beginListen(int port = 0);
+ void beginListen(int32_t port = 0);
/**
* Stores host address and port of this socket to addrinfo.
* @param addrinfo placeholder to store host address and port.
*/
- void getAddrInfo(pair<string, int>& addrinfo) const;
+ void getAddrInfo(pair<string, int32_t>& addrinfo) const;
/**
* Stores peer's address and port to peerinfo.
* @param peerinfo placeholder to store peer's address and port.
*/
- void getPeerInfo(pair<string, int>& peerinfo) const;
+ void getPeerInfo(pair<string, int32_t>& peerinfo) const;
/**
* Accepts incoming connection on this socket.
@@ -121,7 +121,7 @@ public:
* @param host hostname or ip address to connect to
* @param port service port number to connect to
*/
- void establishConnection(const string& host, int port);
+ void establishConnection(const string& host, int32_t port);
void setNonBlockingMode() const;
@@ -142,7 +142,7 @@ public:
* @return true if the socket is available for writing,
* otherwise returns false.
*/
- bool isWritable(int timeout) const;
+ bool isWritable(int32_t timeout) const;
/**
* Checks whether this socket is available for reading.
@@ -151,7 +151,7 @@ public:
* @return true if the socket is available for reading,
* otherwise returns false.
*/
- bool isReadable(int timeout) const;
+ bool isReadable(int32_t timeout) const;
/**
* Writes characters into this socket. data is a pointer pointing the first
@@ -161,7 +161,7 @@ public:
* @param data data to write
* @param len length of data
*/
- void writeData(const char* data, int len);
+ void writeData(const char* data, int32_t len);
void writeData(const string& msg) { writeData(msg.c_str(), msg.size()); }
/**
@@ -176,7 +176,7 @@ public:
* @param len the maximum size data can store. This method assigns
* the number of bytes read to len.
*/
- void readData(char* data, int& len);
+ void readData(char* data, int32_t& len);
/**
* Reads up to len bytes from this socket, but bytes are not removed from
@@ -187,7 +187,7 @@ public:
* @param len the maximum size data can store. This method assigns
* the number of bytes read to len.
*/
- void peekData(char* data, int& len);
+ void peekData(char* data, int32_t& len);
/**
* Makes this socket secure.
diff --git a/src/TimeA2.cc b/src/TimeA2.cc
index 421760cd..c62d3a55 100644
--- a/src/TimeA2.cc
+++ b/src/TimeA2.cc
@@ -43,7 +43,7 @@ Time::Time(const Time& time) {
tv = time.tv;
}
-Time::Time(int sec) {
+Time::Time(int32_t sec) {
setTimeInSec(sec);
}
@@ -59,11 +59,11 @@ struct timeval Time::getCurrentTime() const {
return now;
}
-bool Time::elapsed(int sec) const {
+bool Time::elapsed(int32_t sec) const {
return Util::difftvsec(getCurrentTime(), tv) >= sec;
}
-bool Time::elapsedInMillis(int millis) const {
+bool Time::elapsedInMillis(int32_t millis) const {
return Util::difftv(getCurrentTime(), tv)/1000 >= millis;
}
@@ -71,11 +71,11 @@ bool Time::isNewer(const Time& time) const {
return Util::difftv(this->tv, time.tv) > 0;
}
-int Time::difference() const {
+int32_t Time::difference() const {
return Util::difftvsec(getCurrentTime(), tv);
}
-long long int Time::differenceInMillis() const {
+int64_t Time::differenceInMillis() const {
return Util::difftv(getCurrentTime(), tv)/1000;
}
@@ -84,7 +84,7 @@ int64_t Time::differenceInMillis(const struct timeval& now) const
return Util::difftv(now, tv)/1000;
}
-void Time::setTimeInSec(int sec) {
+void Time::setTimeInSec(int32_t sec) {
tv.tv_sec = sec;
tv.tv_usec = 0;
}
diff --git a/src/TimeA2.h b/src/TimeA2.h
index 5ac66416..d5100405 100644
--- a/src/TimeA2.h
+++ b/src/TimeA2.h
@@ -48,7 +48,7 @@ public:
// this object was created.
Time();
Time(const Time& time);
- Time(int sec);
+ Time(int32_t sec);
Time& operator=(const Time& time) {
if(this != &time) {
@@ -62,32 +62,32 @@ public:
// Makes this object's time value up to date.
void reset();
- bool elapsed(int sec) const;
+ bool elapsed(int32_t sec) const;
- bool elapsedInMillis(int millis) const;
+ bool elapsedInMillis(int32_t millis) const;
- int difference() const;
- long long int differenceInMillis() const;
+ int32_t difference() const;
+ int64_t differenceInMillis() const;
int64_t differenceInMillis(const struct timeval& now) const;
// Returns true if this object's time value is zero.
bool isZero() const { return tv.tv_sec == 0 && tv.tv_usec == 0; }
- long long int getTimeInMicros() const {
- return (long long int)tv.tv_sec*1000*1000+tv.tv_usec;
+ int64_t getTimeInMicros() const {
+ return (int64_t)tv.tv_sec*1000*1000+tv.tv_usec;
}
- long long int getTimeInMillis() const {
- return (long long int)tv.tv_sec*1000+tv.tv_usec/1000;
+ int64_t getTimeInMillis() const {
+ return (int64_t)tv.tv_sec*1000+tv.tv_usec/1000;
}
// Returns this object's time value in seconds.
- int getTime() const {
+ int32_t getTime() const {
return tv.tv_sec;
}
- void setTimeInSec(int sec);
+ void setTimeInSec(int32_t sec);
bool isNewer(const Time& time) const;
};
diff --git a/src/TimeSeedCriteria.h b/src/TimeSeedCriteria.h
index 7dca9f37..84eb63d8 100644
--- a/src/TimeSeedCriteria.h
+++ b/src/TimeSeedCriteria.h
@@ -41,10 +41,10 @@
class TimeSeedCriteria : public SeedCriteria {
private:
// How much time the client does seeding in seconds.
- int duration;
+ int32_t duration;
Time watch;
public:
- TimeSeedCriteria(int duration):duration(duration) {}
+ TimeSeedCriteria(int32_t duration):duration(duration) {}
virtual ~TimeSeedCriteria() {}
virtual void reset() {
@@ -55,11 +55,11 @@ public:
return watch.elapsed(duration);
}
- void setDuration(int duration) {
+ void setDuration(int32_t duration) {
this->duration = duration;
}
- int getDuration() const {
+ int32_t getDuration() const {
return duration;
}
};
diff --git a/src/TimeoutException.h b/src/TimeoutException.h
index 33744fc3..d3821d2d 100644
--- a/src/TimeoutException.h
+++ b/src/TimeoutException.h
@@ -37,13 +37,13 @@
class TimeoutException {
public:
- int err;
+ int32_t err;
string msg;
public:
TimeoutException():err(0), msg("") {};
- TimeoutException(int err):err(err), msg("") {};
+ TimeoutException(int32_t err):err(err), msg("") {};
TimeoutException(string msg):err(0), msg(msg) {};
- TimeoutException(int err, string msg):err(err), msg(msg) {}
+ TimeoutException(int32_t err, string msg):err(err), msg(msg) {}
};
#endif // _D_TIMEOUT_EXCEPTION_H_
diff --git a/src/TorrentAutoSaveCommand.cc b/src/TorrentAutoSaveCommand.cc
index b363e3ca..28f343dd 100644
--- a/src/TorrentAutoSaveCommand.cc
+++ b/src/TorrentAutoSaveCommand.cc
@@ -35,10 +35,10 @@
#include "TorrentAutoSaveCommand.h"
#include "Util.h"
-TorrentAutoSaveCommand::TorrentAutoSaveCommand(int cuid,
+TorrentAutoSaveCommand::TorrentAutoSaveCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
- int interval):
+ int32_t interval):
BtContextAwareCommand(cuid, btContext),
e(e),
interval(interval) {}
diff --git a/src/TorrentAutoSaveCommand.h b/src/TorrentAutoSaveCommand.h
index d0f511a3..86d31641 100644
--- a/src/TorrentAutoSaveCommand.h
+++ b/src/TorrentAutoSaveCommand.h
@@ -43,13 +43,13 @@
class TorrentAutoSaveCommand : public BtContextAwareCommand {
private:
TorrentDownloadEngine* e;
- int interval;
+ int32_t interval;
Time checkPoint;
public:
- TorrentAutoSaveCommand(int cuid,
+ TorrentAutoSaveCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
- int interval);
+ int32_t interval);
~TorrentAutoSaveCommand();
diff --git a/src/TorrentDownloadEngine.cc b/src/TorrentDownloadEngine.cc
index 75491129..1a5f4017 100644
--- a/src/TorrentDownloadEngine.cc
+++ b/src/TorrentDownloadEngine.cc
@@ -78,8 +78,8 @@ void TorrentDownloadEngine::initStatistics() {
totalLength = 0;
}
-int TorrentDownloadEngine::calculateSpeed(long long int length, int elapsed) {
- int nowSpeed = (int)(length/elapsed);
+int32_t TorrentDownloadEngine::calculateSpeed(int64_t length, int32_t elapsed) {
+ int32_t nowSpeed = length/elapsed;
return nowSpeed;
}
diff --git a/src/TorrentDownloadEngine.h b/src/TorrentDownloadEngine.h
index f87cd32e..ba0cfda1 100644
--- a/src/TorrentDownloadEngine.h
+++ b/src/TorrentDownloadEngine.h
@@ -53,19 +53,19 @@ private:
protected:
Time cp;
Time lastCalcStat;
- int downloadSpeed;
- int uploadSpeed;
- long long int selectedDownloadLengthDiff;
- long long int selectedTotalLength;
+ int32_t downloadSpeed;
+ int32_t uploadSpeed;
+ int64_t selectedDownloadLengthDiff;
+ int64_t selectedTotalLength;
// The time when startup
Time startup;
// The average speed(bytes per second) since startup
- int avgSpeed;
+ int32_t avgSpeed;
// The estimated remaining time to complete the download.
- int eta;
- long long int downloadLength;
- long long int uploadLength;
- long long int totalLength;
+ int32_t eta;
+ int64_t downloadLength;
+ int64_t uploadLength;
+ int64_t totalLength;
BtContextHandle btContext;
BtRuntimeHandle btRuntime;
@@ -74,7 +74,7 @@ protected:
BtAnnounceHandle btAnnounce;
BtProgressInfoFileHandle btProgressInfoFile;
- int calculateSpeed(long long int sessionLength, int elapsed);
+ int32_t calculateSpeed(int64_t sessionLength, int32_t elapsed);
void calculateStat();
virtual void onEndOfRun();
diff --git a/src/TrackerUpdateCommand.cc b/src/TrackerUpdateCommand.cc
index a0382ebe..b66cda17 100644
--- a/src/TrackerUpdateCommand.cc
+++ b/src/TrackerUpdateCommand.cc
@@ -42,7 +42,7 @@
#include "CUIDCounter.h"
#include <sstream>
-TrackerUpdateCommand::TrackerUpdateCommand(int cuid,
+TrackerUpdateCommand::TrackerUpdateCommand(int32_t cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext):
BtContextAwareCommand(cuid, btContext), e(e)
@@ -62,7 +62,7 @@ string TrackerUpdateCommand::getTrackerResponse() {
char data[2048];
try {
while(1) {
- int dataLength = e->_requestGroupMan->getRequestGroup(0)->getSegmentMan()->diskWriter->readData(data, sizeof(data), strm.tellp());
+ int32_t dataLength = e->_requestGroupMan->getRequestGroup(0)->getSegmentMan()->diskWriter->readData(data, sizeof(data), strm.tellp());
strm.write(data, dataLength);
if(dataLength != sizeof(data)) {
break;
diff --git a/src/TransferEncoding.h b/src/TransferEncoding.h
index 080c9b36..04d3056d 100644
--- a/src/TransferEncoding.h
+++ b/src/TransferEncoding.h
@@ -41,7 +41,7 @@ class TransferEncoding {
public:
virtual ~TransferEncoding() {}
virtual void init() = 0;
- virtual void inflate(char* outbuf, int& outlen, const char* inbuf, int inlen) = 0;
+ virtual void inflate(char* outbuf, int32_t& outlen, const char* inbuf, int32_t inlen) = 0;
virtual bool finished() = 0;
virtual void end() = 0;
};
diff --git a/src/UrlRequestInfo.h b/src/UrlRequestInfo.h
index 40f0152d..210e9b51 100644
--- a/src/UrlRequestInfo.h
+++ b/src/UrlRequestInfo.h
@@ -52,7 +52,7 @@ typedef SharedHandle<HeadResult> HeadResultHandle;
class UrlRequestInfo : public RequestInfo {
private:
Strings urls;
- int maxConnections;
+ int32_t maxConnections;
string _filename;
int64_t _totalLength;
#ifdef ENABLE_MESSAGE_DIGEST
@@ -64,11 +64,11 @@ private:
RequestInfo* createNextRequestInfo() const;
void adjustRequestSize(Requests& requests,
Requests& reserved,
- int maxConnections) const;
+ int32_t maxConnections) const;
void printUrls(const Strings& urls) const;
HeadResultHandle getHeadResult();
public:
- UrlRequestInfo(const Strings& urls, int maxConnections, Option* op):
+ UrlRequestInfo(const Strings& urls, int32_t maxConnections, Option* op):
RequestInfo(op),
urls(urls),
maxConnections(maxConnections),
diff --git a/src/Util.cc b/src/Util.cc
index b6cc6ad7..9607a9e0 100644
--- a/src/Util.cc
+++ b/src/Util.cc
@@ -57,7 +57,7 @@ string uint2str(T value, bool comma) {
str = "0";
return str;
}
- int count = 0;
+ int32_t count = 0;
while(value) {
++count;
char digit = value%10+'0';
@@ -150,15 +150,15 @@ pair<string, string> Util::split(const string& src, const string& delims)
return hp;
}
-long long int Util::difftv(struct timeval tv1, struct timeval tv2) {
+int64_t Util::difftv(struct timeval tv1, struct timeval tv2) {
if(tv1.tv_sec < tv2.tv_sec || tv1.tv_sec == tv2.tv_sec && tv1.tv_usec < tv2.tv_usec) {
return 0;
}
- return ((long long int)(tv1.tv_sec-tv2.tv_sec)*1000000+
+ return ((int64_t)(tv1.tv_sec-tv2.tv_sec)*1000000+
tv1.tv_usec-tv2.tv_usec);
}
-int Util::difftvsec(struct timeval tv1, struct timeval tv2) {
+int32_t Util::difftvsec(struct timeval tv1, struct timeval tv2) {
if(tv1.tv_sec < tv2.tv_sec) {
return 0;
}
@@ -235,9 +235,9 @@ string Util::replace(const string& target, const string& oldstr, const string& n
return result;
}
-string Util::urlencode(const unsigned char* target, int len) {
+string Util::urlencode(const unsigned char* target, int32_t len) {
string dest;
- for(int i = 0; i < len; i++) {
+ for(int32_t i = 0; i < len; i++) {
if(!('0' <= target[i] && target[i] <= '9' ||
'A' <= target[i] && target[i] <= 'Z' ||
'a' <= target[i] && target[i] <= 'z' ||
@@ -258,9 +258,9 @@ string Util::urlencode(const unsigned char* target, int len) {
return dest;
}
-string Util::torrentUrlencode(const unsigned char* target, int len) {
+string Util::torrentUrlencode(const unsigned char* target, int32_t len) {
string dest;
- for(int i = 0; i < len; i++) {
+ for(int32_t i = 0; i < len; i++) {
if('0' <= target[i] && target[i] <= '9' ||
'A' <= target[i] && target[i] <= 'Z' ||
'a' <= target[i] && target[i] <= 'z') {
@@ -298,9 +298,9 @@ string Util::urldecode(const string& target) {
return result;
}
-string Util::toHex(const unsigned char* src, int len) {
+string Util::toHex(const unsigned char* src, int32_t len) {
char* temp = new char[len*2+1];
- for(int i = 0; i < len; i++) {
+ for(int32_t i = 0; i < len; i++) {
sprintf(temp+i*2, "%02x", src[i]);
}
temp[len*2] = '\0';
@@ -319,11 +319,11 @@ void Util::fileCopy(const string& dest, const string& src) {
rangedFileCopy(dest, src, 0, file.size());
}
-void Util::rangedFileCopy(const string& dest, const string& src, long long int srcOffset, long long int length) {
- int bufSize = 4096;
+void Util::rangedFileCopy(const string& dest, const string& src, int64_t srcOffset, int64_t length) {
+ int32_t bufSize = 4096;
char buf[bufSize];
- int destFd = -1;
- int srcFd = -1;
+ int32_t destFd = -1;
+ int32_t srcFd = -1;
try {
if((destFd = open(dest.c_str(), O_CREAT|O_WRONLY|O_TRUNC, OPEN_MODE)) == -1) {
throw new DlAbortEx(EX_FILE_OPEN, dest.c_str(), strerror(errno));
@@ -334,10 +334,10 @@ void Util::rangedFileCopy(const string& dest, const string& src, long long int s
if(lseek(srcFd, srcOffset, SEEK_SET) != srcOffset) {
throw new DlAbortEx(EX_FILE_SEEK, src.c_str(), strerror(errno));
}
- int x = length/bufSize;
- int r = length%bufSize;
- for(int i = 0; i < x; i++) {
- int readLength;
+ int32_t x = length/bufSize;
+ int32_t r = length%bufSize;
+ for(int32_t i = 0; i < x; i++) {
+ int32_t readLength;
if((readLength = read(srcFd, buf, bufSize)) == -1 || readLength != bufSize) {
throw new DlAbortEx(EX_FILE_READ, src.c_str(), strerror(errno));
}
@@ -346,7 +346,7 @@ void Util::rangedFileCopy(const string& dest, const string& src, long long int s
}
}
if(r > 0) {
- int readLength;
+ int32_t readLength;
if((readLength = read(srcFd, buf, r)) == -1 || readLength != r) {
throw new DlAbortEx(EX_FILE_READ, src.c_str(), strerror(errno));
}
@@ -369,7 +369,7 @@ void Util::rangedFileCopy(const string& dest, const string& src, long long int s
}
}
-bool Util::isPowerOf(int num, int base) {
+bool Util::isPowerOf(int32_t num, int32_t base) {
if(base <= 0) { return false; }
if(base == 1) { return true; }
@@ -382,14 +382,14 @@ bool Util::isPowerOf(int num, int base) {
return false;
}
-string Util::secfmt(int sec) {
+string Util::secfmt(int32_t sec) {
string str;
if(sec >= 3600) {
str = itos(sec/3600)+"h";
sec %= 3600;
}
if(sec >= 60) {
- int min = sec/60;
+ int32_t min = sec/60;
if(min < 10) {
str += "0";
}
@@ -403,7 +403,7 @@ string Util::secfmt(int sec) {
return str;
}
-int Util::expandBuffer(char** pbuf, int curLength, int newLength) {
+int32_t Util::expandBuffer(char** pbuf, int32_t curLength, int32_t newLength) {
char* newbuf = new char[newLength];
memcpy(newbuf, *pbuf, curLength);
delete [] *pbuf;
@@ -411,11 +411,11 @@ int Util::expandBuffer(char** pbuf, int curLength, int newLength) {
return newLength;
}
-int getNum(const char* buf, int offset, int length) {
+int32_t getNum(const char* buf, int32_t offset, int32_t length) {
char* temp = new char[length+1];
memcpy(temp, buf+offset, length);
temp[length] = '\0';
- int x = strtol(temp, NULL, 10);
+ int32_t x = strtol(temp, NULL, 10);
delete [] temp;
return x;
}
@@ -431,18 +431,18 @@ void unfoldSubRange(const string& src, Integers& range) {
range.push_back(atoi(src.c_str()));
} else {
if(src.at(p) == ',') {
- int num = getNum(src.c_str(), 0, p);
+ int32_t num = getNum(src.c_str(), 0, p);
range.push_back(num);
unfoldSubRange(src.substr(p+1), range);
} else if(src.at(p) == '-') {
- int rightNumBegin = p+1;
+ int32_t rightNumBegin = p+1;
string::size_type nextDelim = src.find_first_of(",", rightNumBegin);
if(nextDelim == string::npos) {
nextDelim = src.size();
}
- int left = getNum(src.c_str(), 0, p);
- int right = getNum(src.c_str(), rightNumBegin, nextDelim-rightNumBegin);
- for(int i = left; i <= right; i++) {
+ int32_t left = getNum(src.c_str(), 0, p);
+ int32_t right = getNum(src.c_str(), rightNumBegin, nextDelim-rightNumBegin);
+ for(int32_t i = left; i <= right; i++) {
range.push_back(i);
}
if(src.size() > nextDelim) {
@@ -483,7 +483,7 @@ string Util::getContentDispositionFilename(const string& header) {
}
#ifdef ENABLE_MESSAGE_DIGEST
-void Util::sha1Sum(unsigned char* digest, const void* data, int dataLength) {
+void Util::sha1Sum(unsigned char* digest, const void* data, int32_t dataLength) {
MessageDigestContext ctx(DIGEST_ALGO_SHA1);
ctx.digestInit();
ctx.digestUpdate(data, dataLength);
@@ -504,15 +504,15 @@ void Util::fileChecksum(const string& filename, unsigned char* digest,
MessageDigestContext ctx(algo);
ctx.digestInit();
- int BUFLEN = 4096;
+ int32_t BUFLEN = 4096;
char buf[BUFLEN];
- int fd;
+ int32_t fd;
if((fd = open(filename.c_str(), O_RDWR, OPEN_MODE)) < 0) {
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
}
while(1) {
- int size = read(fd, buf, BUFLEN);
+ int32_t size = read(fd, buf, BUFLEN);
if(size == -1) {
if(errno == EINTR) {
continue;
@@ -533,7 +533,7 @@ void Util::fileChecksum(const string& filename, unsigned char* digest,
#ifdef ENABLE_BITTORRENT
Integers Util::computeFastSet(string ipaddr, const unsigned char* infoHash,
- int pieces, int fastSetSize) {
+ int32_t pieces, int32_t fastSetSize) {
Integers fastSet;
struct in_addr saddr;
if(inet_aton(ipaddr.c_str(), &saddr) == 0) {
@@ -550,13 +550,13 @@ Integers Util::computeFastSet(string ipaddr, const unsigned char* infoHash,
memcpy(tx+4, infoHash, 20);
unsigned char x[20];
sha1Sum(x, tx, 24);
- while((int)fastSet.size() < fastSetSize) {
- for(int i = 0; i < 5 && (int)fastSet.size() < fastSetSize; i++) {
- int j = i*4;
- unsigned int ny;
+ while((int32_t)fastSet.size() < fastSetSize) {
+ for(int32_t i = 0; i < 5 && (int32_t)fastSet.size() < fastSetSize; i++) {
+ int32_t j = i*4;
+ uint32_t ny;
memcpy(&ny, x+j, 4);
- unsigned int y = ntohl(ny);
- int index = y%pieces;
+ uint32_t y = ntohl(ny);
+ int32_t index = y%pieces;
if(find(fastSet.begin(), fastSet.end(), index) == fastSet.end()) {
fastSet.push_back(index);
}
@@ -569,18 +569,7 @@ Integers Util::computeFastSet(string ipaddr, const unsigned char* infoHash,
}
#endif // ENABLE_BITTORRENT
-/*
-int Util::countBit(unsigned int n) {
- int count = 0;
- while(n > 0) {
- count++;
- n &= (n-1);
- }
- return count;
-}
-*/
-
-static int nbits[] = {
+static int32_t nbits[] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
@@ -607,10 +596,10 @@ int32_t Util::countBit(uint32_t n) {
nbits[(n >> 24)&0xffu];
}
-string Util::randomAlpha(int length) {
+string Util::randomAlpha(int32_t length) {
string str;
- for(int i = 0; i < length; i++) {
- int index = (int)(((double)52)*random()/(RAND_MAX+1.0));
+ for(int32_t i = 0; i < length; i++) {
+ int32_t index = (int32_t)(((double)52)*random()/(RAND_MAX+1.0));
char ch;
if(index < 26) {
ch = (char)('A'+index);
@@ -657,7 +646,7 @@ bool Util::isNumbersAndDotsNotation(const string& name) {
}
}
-void Util::setGlobalSignalHandler(int signal, void (*handler)(int), int flags) {
+void Util::setGlobalSignalHandler(int32_t signal, void (*handler)(int32_t), int32_t flags) {
struct sigaction sigact;
sigact.sa_handler = handler;
sigact.sa_flags = flags;
@@ -690,7 +679,7 @@ int64_t Util::getRealSize(const string& sizeWithUnit)
{
string::size_type p = sizeWithUnit.find_first_of("KM");
string size;
- int mult = 1;
+ int32_t mult = 1;
if(p == string::npos) {
size = sizeWithUnit;
} else {
@@ -735,7 +724,7 @@ void Util::toStream(ostream& os, const FileEntries& fileEntries)
os << _("Files:") << "\n";
os << "idx|path/length" << "\n";
os << "===+===========================================================================" << "\n";
- int count = 1;
+ int32_t count = 1;
for(FileEntries::const_iterator itr = fileEntries.begin();
itr != fileEntries.end(); count++, itr++) {
os << setw(3) << count << "|" << (*itr)->getPath() << "\n";
diff --git a/src/Util.h b/src/Util.h
index d165a589..a5e1ac28 100644
--- a/src/Util.h
+++ b/src/Util.h
@@ -65,8 +65,8 @@ public:
* assuming tv1 is newer than tv2.
* If tv1 is older than tv2, then this method returns 0.
*/
- static long long int difftv(struct timeval tv1, struct timeval tv2);
- static int difftvsec(struct timeval tv1, struct timeval tv2);
+ static int64_t difftv(struct timeval tv1, struct timeval tv2);
+ static int32_t difftvsec(struct timeval tv1, struct timeval tv2);
/**
* Take a string src which is a deliminated list and add its elements
* into result. result is not cleared before conversion begins.
@@ -81,7 +81,7 @@ public:
static string replace(const string& target, const string& oldstr, const string& newstr);
- static string urlencode(const unsigned char* target, int len);
+ static string urlencode(const unsigned char* target, int32_t len);
static string urlencode(const string& target)
{
@@ -90,21 +90,21 @@ public:
static string urldecode(const string& target);
- static string torrentUrlencode(const unsigned char* target, int len);
+ static string torrentUrlencode(const unsigned char* target, int32_t len);
- static string toHex(const unsigned char* src, int len);
+ static string toHex(const unsigned char* src, int32_t len);
static FILE* openFile(const string& filename, const string& mode);
static void fileCopy(const string& destFile, const string& src);
- static void rangedFileCopy(const string& destFile, const string& src, long long int srcOffset, long long int length);
+ static void rangedFileCopy(const string& destFile, const string& src, int64_t srcOffset, int64_t length);
- static bool isPowerOf(int num, int base);
+ static bool isPowerOf(int32_t num, int32_t base);
- static string secfmt(int sec);
+ static string secfmt(int32_t sec);
- static int expandBuffer(char** pbuf, int curLength, int newLength);
+ static int32_t expandBuffer(char** pbuf, int32_t curLength, int32_t newLength);
static void unfoldRange(const string& src, Integers& range);
@@ -113,7 +113,7 @@ public:
// digest must be at least 20 bytes long.
#ifdef ENABLE_MESSAGE_DIGEST
- static void sha1Sum(unsigned char* digest, const void* data, int dataLength);
+ static void sha1Sum(unsigned char* digest, const void* data, int32_t dataLength);
static string simpleMessageDigest(const string& data);
#endif // ENABLE_MESSAGE_DIGEST
@@ -126,12 +126,12 @@ public:
#ifdef ENABLE_BITTORRENT
static Integers computeFastSet(string ipaddr, const unsigned char* infoHash,
- int pieces, int fastSetSize);
+ int32_t pieces, int32_t fastSetSize);
#endif // ENABLE_BITTORRENT
static int32_t countBit(uint32_t n);
- static string randomAlpha(int length);
+ static string randomAlpha(int32_t length);
static string toUpper(const string& src);
@@ -139,7 +139,7 @@ public:
static bool isNumbersAndDotsNotation(const string& name);
- static void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);
+ static void setGlobalSignalHandler(int32_t signal, void (*handler)(int32_t), int32_t flags);
static void indexRange(int32_t& startIndex, int32_t& endIndex,
int64_t offset,
diff --git a/src/main.cc b/src/main.cc
index 3f6a59b2..cd5a5221 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -330,7 +330,7 @@ int main(int argc, char* argv[]) {
textdomain (PACKAGE);
#endif // ENABLE_NLS
stringstream cmdstream;
- int c;
+ int32_t c;
Option* op = new Option();
op->put(PREF_STDOUT_LOG, V_FALSE);
op->put(PREF_DIR, ".");
@@ -385,8 +385,8 @@ int main(int argc, char* argv[]) {
op->put(PREF_MAX_CONCURRENT_DOWNLOADS, "5");
op->put(PREF_DIRECT_DOWNLOAD_TIMEOUT, "15");
while(1) {
- int optIndex = 0;
- int lopt;
+ int32_t optIndex = 0;
+ int32_t lopt;
static struct option longOpts[] = {
{ "daemon", no_argument, NULL, 'D' },
{ "dir", required_argument, NULL, 'd' },
@@ -699,7 +699,7 @@ int main(int argc, char* argv[]) {
} else {
LogFactory::setLogFile("/dev/null");
}
- int exitStatus = EXIT_SUCCESS;
+ int32_t exitStatus = EXIT_SUCCESS;
try {
Logger* logger = LogFactory::getInstance();
logger->info("%s %s", PACKAGE, PACKAGE_VERSION);
diff --git a/src/messageDigest.h b/src/messageDigest.h
index d7743586..345a5483 100644
--- a/src/messageDigest.h
+++ b/src/messageDigest.h
@@ -57,7 +57,7 @@ public:
# define DIGEST_ALGO_SHA1 EVP_sha1()
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGCRYPT
- typedef int DigestAlgo;
+ typedef int32_t DigestAlgo;
# define DIGEST_ALGO_MD5 GCRY_MD_MD5
# define DIGEST_ALGO_SHA1 GCRY_MD_SHA1
#endif // HAVE_LIBGCRYPT
@@ -83,16 +83,16 @@ public:
#if defined(HAVE_OLD_LIBSSL)
void digestInit() {EVP_DigestInit(&ctx, algo);}
void digestReset() {EVP_DigestInit(&ctx, algo);}
- void digestUpdate(const void* data, int length) {EVP_DigestUpdate(&ctx, data, length);}
+ void digestUpdate(const void* data, int32_t length) {EVP_DigestUpdate(&ctx, data, length);}
void digestFinal(unsigned char* md) {
- int len;
- EVP_DigestFinal(&ctx, md, (unsigned int*)&len);
+ int32_t len;
+ EVP_DigestFinal(&ctx, md, (uint32_t*)&len);
}
void digestFree() {/*empty*/}
- int digestLength() const {
+ int32_t digestLength() const {
return digestLength(algo);
}
- static int digestLength(DigestAlgo algo) {
+ static int32_t digestLength(DigestAlgo algo) {
return EVP_MD_size(algo);
}
@@ -104,20 +104,20 @@ public:
void digestReset() {
EVP_DigestInit_ex(&ctx, algo, 0);
}
- void digestUpdate(const void* data, int length) {
+ void digestUpdate(const void* data, int32_t length) {
EVP_DigestUpdate(&ctx, data, length);
}
void digestFinal(unsigned char* md) {
- int len;
- EVP_DigestFinal_ex(&ctx, md, (unsigned int*)&len);
+ int32_t len;
+ EVP_DigestFinal_ex(&ctx, md, (uint32_t*)&len);
}
void digestFree() {
EVP_MD_CTX_cleanup(&ctx);
}
- int digestLength() const {
+ int32_t digestLength() const {
return digestLength(algo);
}
- static int digestLength(DigestAlgo algo) {
+ static int32_t digestLength(DigestAlgo algo) {
return EVP_MD_size(algo);
}
@@ -128,7 +128,7 @@ public:
void digestReset() {
gcry_md_reset(ctx);
}
- void digestUpdate(const void* data, int length) {
+ void digestUpdate(const void* data, int32_t length) {
gcry_md_write(ctx, data, length);
}
void digestFinal(unsigned char* md) {
@@ -138,7 +138,7 @@ public:
void digestFree() {
gcry_md_close(ctx);
}
- int digestLength() const {
+ int32_t digestLength() const {
return digestLength(algo);
}
static int digestLength(DigestAlgo algo) {