2009-03-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Typedefed cuid_t as int32_t in Command.h
	* src/CUIDCounter.h
	* src/Command.cc
	* src/Command.h
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/PeerStat.h
	* src/SegmentMan.cc
	* src/SegmentMan.h
pull/1/head
Tatsuhiro Tsujikawa 2009-03-19 13:54:09 +00:00
parent e3ed6adf91
commit 9233a6258f
9 changed files with 67 additions and 47 deletions

View File

@ -1,3 +1,15 @@
2009-03-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Typedefed cuid_t as int32_t in Command.h
* src/CUIDCounter.h
* src/Command.cc
* src/Command.h
* src/DownloadEngine.cc
* src/DownloadEngine.h
* src/PeerStat.h
* src/SegmentMan.cc
* src/SegmentMan.h
2009-03-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Reduced the number of calls to PeerStorage::calculateStat() and

View File

@ -36,22 +36,25 @@
#define _D_CUID_COUNTER_H_
#include "common.h"
#include "Command.h"
namespace aria2 {
typedef int32_t CUID;
class CUIDCounter {
private:
int32_t count;
cuid_t _count;
public:
CUIDCounter():count(0) {}
CUIDCounter():_count(0) {}
~CUIDCounter() {}
CUID newID()
cuid_t newID()
{
return ++count;
cuid_t id = ++_count;
if(id == INT32_MAX) {
_count = 0;
}
return id;
}
};

View File

@ -40,14 +40,14 @@ namespace aria2 {
int32_t Command::uuidGen = 0;
Command::Command(int32_t cuid):uuid(uuidGen++),
status(STATUS_INACTIVE),
cuid(cuid),
logger(LogFactory::getInstance()),
_readEvent(false),
_writeEvent(false),
_errorEvent(false),
_hupEvent(false) {}
Command::Command(cuid_t cuid):uuid(uuidGen++),
status(STATUS_INACTIVE),
cuid(cuid),
logger(LogFactory::getInstance()),
_readEvent(false),
_writeEvent(false),
_errorEvent(false),
_hupEvent(false) {}
void Command::transitStatus()
{

View File

@ -45,6 +45,8 @@ class Logger;
typedef int32_t CommandUuid;
typedef int32_t cuid_t;
class Command {
public:
enum STATUS {
@ -67,13 +69,13 @@ protected:
bool _errorEvent;
bool _hupEvent;
public:
Command(int32_t cuid);
Command(cuid_t cuid);
virtual ~Command() {}
virtual bool execute() = 0;
int32_t getCuid() const { return cuid; }
cuid_t getCuid() const { return cuid; }
const CommandUuid& getUuid() const { return uuid; }

View File

@ -459,7 +459,7 @@ DownloadEngine::SocketPoolEntry::getOptions() const
return _options;
}
CUID DownloadEngine::newCUID()
cuid_t DownloadEngine::newCUID()
{
return _cuidCounter.newID();
}

View File

@ -230,7 +230,7 @@ public:
SharedHandle<BtRegistry> getBtRegistry() const;
CUID newCUID();
cuid_t newCUID();
const std::string& findCachedIPAddress(const std::string& hostname) const;

View File

@ -36,9 +36,12 @@
#define _D_PEER_STAT_H_
#include "common.h"
#include <string>
#include "SpeedCalc.h"
#include "SharedHandle.h"
#include <string>
#include "Command.h"
namespace aria2 {
@ -50,7 +53,7 @@ public:
REQUEST_IDLE,
};
private:
int32_t cuid;
cuid_t cuid;
std::string _hostname;
std::string _protocol;
SpeedCalc downloadSpeed;
@ -63,7 +66,7 @@ private:
uint64_t _sessionUploadLength;
public:
PeerStat(int32_t cuid, const std::string& hostname,
PeerStat(cuid_t cuid, const std::string& hostname,
const::std::string& protocol):
cuid(cuid),
_hostname(hostname),
@ -74,11 +77,11 @@ public:
_sessionDownloadLength(0),
_sessionUploadLength(0) {}
PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE),
_avgDownloadSpeed(0),
_avgUploadSpeed(0),
_sessionDownloadLength(0),
_sessionUploadLength(0) {}
PeerStat(cuid_t cuid = 0):cuid(cuid), status(PeerStat::IDLE),
_avgDownloadSpeed(0),
_avgUploadSpeed(0),
_sessionDownloadLength(0),
_sessionUploadLength(0) {}
~PeerStat() {}
@ -167,7 +170,7 @@ public:
return status;
}
int32_t getCuid() const {
cuid_t getCuid() const {
return cuid;
}

View File

@ -53,7 +53,7 @@
namespace aria2 {
SegmentEntry::SegmentEntry(int32_t cuid, const SegmentHandle& segment):
SegmentEntry::SegmentEntry(cuid_t cuid, const SegmentHandle& segment):
cuid(cuid), segment(segment) {}
SegmentEntry::~SegmentEntry() {}
@ -103,7 +103,7 @@ void SegmentMan::setDownloadContext(const DownloadContextHandle& downloadContext
_downloadContext = downloadContext;
}
SegmentHandle SegmentMan::checkoutSegment(int32_t cuid,
SegmentHandle SegmentMan::checkoutSegment(cuid_t cuid,
const PieceHandle& piece)
{
if(piece.isNull()) {
@ -164,7 +164,7 @@ SegmentEntryHandle SegmentMan::findSlowerSegmentEntry
}
void SegmentMan::getInFlightSegment(std::deque<SharedHandle<Segment> >& segments,
int32_t cuid)
cuid_t cuid)
{
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
itr != usedSegmentEntries.end(); ++itr) {
@ -175,7 +175,7 @@ void SegmentMan::getInFlightSegment(std::deque<SharedHandle<Segment> >& segments
}
}
SegmentHandle SegmentMan::getSegment(int32_t cuid) {
SegmentHandle SegmentMan::getSegment(cuid_t cuid) {
PieceHandle piece = _pieceStorage->getMissingPiece();
if(piece.isNull()) {
PeerStatHandle myPeerStat = getPeerStat(cuid);
@ -205,14 +205,14 @@ SegmentHandle SegmentMan::getSegment(int32_t cuid) {
}
}
SegmentHandle SegmentMan::getSegment(int32_t cuid, size_t index) {
SegmentHandle SegmentMan::getSegment(cuid_t cuid, size_t index) {
if(_downloadContext->getNumPieces() <= index) {
return SharedHandle<Segment>();
}
return checkoutSegment(cuid, _pieceStorage->getMissingPiece(index));
}
void SegmentMan::cancelSegment(int32_t cuid) {
void SegmentMan::cancelSegment(cuid_t cuid) {
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
itr != usedSegmentEntries.end();) {
if((*itr)->cuid == cuid) {
@ -236,7 +236,7 @@ public:
}
};
bool SegmentMan::completeSegment(int32_t cuid, const SegmentHandle& segment) {
bool SegmentMan::completeSegment(cuid_t cuid, const SegmentHandle& segment) {
_pieceStorage->completePiece(segment->getPiece());
_pieceStorage->advertisePiece(cuid, segment->getPiece()->getIndex());
SegmentEntries::iterator itr = std::find_if(usedSegmentEntries.begin(),
@ -264,7 +264,7 @@ uint64_t SegmentMan::getDownloadLength() const {
class FindPeerStat {
public:
bool operator()(const SharedHandle<PeerStat>& peerStat, int32_t cuid) const
bool operator()(const SharedHandle<PeerStat>& peerStat, cuid_t cuid) const
{
return peerStat->getCuid() < cuid;
}
@ -283,7 +283,7 @@ bool SegmentMan::registerPeerStat(const SharedHandle<PeerStat>& peerStat)
}
}
PeerStatHandle SegmentMan::getPeerStat(int32_t cuid) const
PeerStatHandle SegmentMan::getPeerStat(cuid_t cuid) const
{
std::deque<SharedHandle<PeerStat> >::const_iterator i =
std::lower_bound(peerStats.begin(), peerStats.end(), cuid, FindPeerStat());
@ -314,7 +314,7 @@ unsigned int SegmentMan::calculateDownloadSpeed()
}
}
} else {
for(std::map<int32_t, unsigned int>::const_iterator i =
for(std::map<cuid_t, unsigned int>::const_iterator i =
_peerStatDlspdMap.begin();
i != _peerStatDlspdMap.end(); ++i) {
speed += (*i).second;

View File

@ -56,10 +56,10 @@ class Piece;
class SegmentEntry {
public:
int32_t cuid;
cuid_t cuid;
SharedHandle<Segment> segment;
public:
SegmentEntry(int32_t cuid, const SharedHandle<Segment>& segment);
SegmentEntry(cuid_t cuid, const SharedHandle<Segment>& segment);
~SegmentEntry();
};
@ -85,11 +85,11 @@ private:
std::deque<SharedHandle<PeerStat> > peerStats;
// key: PeerStat's cuid, value: its download speed
std::map<int32_t, unsigned int> _peerStatDlspdMap;
std::map<cuid_t, unsigned int> _peerStatDlspdMap;
Time _lastPeerStatDlspdMapUpdated;
SharedHandle<Segment> checkoutSegment(int32_t cuid,
SharedHandle<Segment> checkoutSegment(cuid_t cuid,
const SharedHandle<Piece>& piece);
SharedHandle<SegmentEntry> findSlowerSegmentEntry
@ -125,9 +125,9 @@ public:
* This function doesn't clear passed segments.
*/
void getInFlightSegment(std::deque<SharedHandle<Segment> >& segments,
int32_t cuid);
cuid_t cuid);
SharedHandle<Segment> getSegment(int32_t cuid);
SharedHandle<Segment> getSegment(cuid_t cuid);
/**
* Returns a segment whose index is index.
@ -135,7 +135,7 @@ public:
* to another cuid or has been downloaded, then returns a segment instance
* whose isNull call is true.
*/
SharedHandle<Segment> getSegment(int32_t cuid, size_t index);
SharedHandle<Segment> getSegment(cuid_t cuid, size_t index);
/**
* Updates download status.
*/
@ -144,11 +144,11 @@ public:
* Cancels all the segment which the command having given cuid
* uses.
*/
void cancelSegment(int32_t cuid);
void cancelSegment(cuid_t cuid);
/**
* Tells SegmentMan that the segment has been downloaded successfully.
*/
bool completeSegment(int32_t cuid, const SharedHandle<Segment>& segment);
bool completeSegment(cuid_t cuid, const SharedHandle<Segment>& segment);
/**
* Injects PieceStorage.
@ -179,7 +179,7 @@ public:
* Returns peerStat whose cuid is given cuid. If it is not found, returns
* 0.
*/
SharedHandle<PeerStat> getPeerStat(int32_t cuid) const;
SharedHandle<PeerStat> getPeerStat(cuid_t cuid) const;
const std::deque<SharedHandle<PeerStat> >& getPeerStats() const;