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
pull/1/head
Tatsuhiro Tsujikawa 2007-07-21 08:56:16 +00:00
parent cd6b6e3591
commit 6574e44f88
123 changed files with 706 additions and 713 deletions

View File

@ -1,3 +1,8 @@
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
2007-07-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that prevents cookies from being sent to the server

8
TODO
View File

@ -25,3 +25,11 @@
* consider life cycle of requestGroup and segmentMan
* exit status: all downloads have been successful-> EXIT_SUCCESS,
some of downloads have been failed -> EXIT_FAILURE
* Fix log and stdout message in Metalink related class.
* Fix Cookie header's value. ';' is not necessary at the end of it.
* It is possible to replace all %lld to %s, using Util::llitos(...) ?.
* Time::getTimeInMillis() returns int64_t.
* Util::secfmt, What happens if sec is less than 0?
* Rewrite ChunkedEncoding
* typedef int32_t CUID in common.h or a2types.h

View File

@ -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) {

View File

@ -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();
};

View File

@ -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());
}

View File

@ -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

View File

@ -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;

View File

@ -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_

View File

@ -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;

View File

@ -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) {}

View File

@ -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) {}

View File

@ -49,7 +49,7 @@ public:
virtual void removeAllTargetPiece() = 0;
virtual int countTargetPiece() = 0;
virtual int32_t countTargetPiece() = 0;
virtual void removeCompletedPiece() = 0;

View File

@ -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++; }

View File

@ -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) {}

View File

@ -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

View File

@ -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) {}

View File

@ -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);

View File

@ -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();
};

View File

@ -34,4 +34,4 @@
/* copyright --> */
#include "Command.h"
int Command::uuidGen = 0;
int32_t Command::uuidGen = 0;

View File

@ -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; }

View File

@ -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);
}

View File

@ -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) {}

View File

@ -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) {

View File

@ -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();

View File

@ -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 {

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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");

View File

@ -77,7 +77,7 @@ public:
virtual void removeAllTargetPiece();
virtual int countTargetPiece() {
virtual int32_t countTargetPiece() {
return pieces.size();
}

View File

@ -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;

View File

@ -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) {}

View File

@ -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) {

View File

@ -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);

View File

@ -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()) {

View File

@ -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();

View File

@ -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));

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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();

View File

@ -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) {}

View File

@ -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; }

View File

@ -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(),

View File

@ -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_

View File

@ -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;
}

View File

@ -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,

View File

@ -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) {}

View File

@ -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() {}

View File

@ -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())

View File

@ -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);

View File

@ -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;

View File

@ -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;
};

View File

@ -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));
}

View File

@ -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();
}

View File

@ -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);

View File

@ -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_

View File

@ -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));
}

View File

@ -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);
};

View File

@ -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;

View File

@ -48,9 +48,9 @@ public:
};
public:
string url;
int type;
TYPE type;
string location;
int preference;
int32_t preference;
public:
MetalinkResource();
~MetalinkResource();

View File

@ -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;

View File

@ -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);

View File

@ -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));

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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());

View File

@ -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) {

View File

@ -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();

View File

@ -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;
}

View File

@ -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_

View File

@ -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();

View File

@ -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)
{

View File

@ -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;
}
};

View File

@ -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;
}

View File

@ -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);
}
};

View File

@ -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.

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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; }

View File

@ -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) {}

View File

@ -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;

View File

@ -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) {

View File

@ -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();

View File

@ -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 {

View File

@ -39,7 +39,7 @@
class SimpleBtMessage : public AbstractBtMessage {
private:
int leftDataLength;
int32_t leftDataLength;
public:
SimpleBtMessage();

View File

@ -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");

View File

@ -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_

View File

@ -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;
}
};

Some files were not shown because too many files have changed in this diff Show More