mirror of https://github.com/aria2/aria2
2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Only add socket to DownloadEngine's select routine when peer or localhost is unchoked and interested. This lowers CPU usage a little bit. * src/PeerInteractionCommand.cc * src/PeerAbstractCommand.{h, cc} * src/BtInteractive.h * src/DefaultBtInteractive.{h, cc}pull/1/head
parent
9ab0ece87f
commit
f38eb15ca9
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Only add socket to DownloadEngine's select routine when peer or
|
||||
localhost is unchoked and interested. This lowers CPU usage a
|
||||
little bit.
|
||||
* src/PeerInteractionCommand.cc
|
||||
* src/PeerAbstractCommand.{h, cc}
|
||||
* src/BtInteractive.h
|
||||
* src/DefaultBtInteractive.{h, cc}
|
||||
|
||||
2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Revert previous change because get_peers message is needed for
|
||||
|
|
|
@ -63,6 +63,8 @@ public:
|
|||
virtual int32_t countPendingMessage() = 0;
|
||||
|
||||
virtual bool isSendingMessageInProgress() = 0;
|
||||
|
||||
virtual size_t countReceivedMessageInIteration() const = 0;
|
||||
};
|
||||
|
||||
typedef SharedHandle<BtInteractive> BtInteractiveHandle;
|
||||
|
|
|
@ -75,7 +75,8 @@ DefaultBtInteractive::DefaultBtInteractive(const SharedHandle<BtContext>& btCont
|
|||
keepAliveInterval(120),
|
||||
maxDownloadSpeedLimit(0),
|
||||
_utPexEnabled(false),
|
||||
_dhtEnabled(false)
|
||||
_dhtEnabled(false),
|
||||
_numReceivedMessage(0)
|
||||
{}
|
||||
|
||||
DefaultBtInteractive::~DefaultBtInteractive() {}
|
||||
|
@ -222,7 +223,8 @@ void DefaultBtInteractive::sendKeepAlive() {
|
|||
}
|
||||
}
|
||||
|
||||
void DefaultBtInteractive::receiveMessages() {
|
||||
size_t DefaultBtInteractive::receiveMessages() {
|
||||
size_t msgcount = 0;
|
||||
for(int i = 0; i < 50; i++) {
|
||||
if(maxDownloadSpeedLimit > 0) {
|
||||
TransferStat stat = peerStorage->calculateStat();
|
||||
|
@ -234,6 +236,7 @@ void DefaultBtInteractive::receiveMessages() {
|
|||
if(message.isNull()) {
|
||||
break;
|
||||
}
|
||||
++msgcount;
|
||||
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
message->toString().c_str());
|
||||
|
@ -259,6 +262,7 @@ void DefaultBtInteractive::receiveMessages() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return msgcount;
|
||||
}
|
||||
|
||||
void DefaultBtInteractive::decideInterest() {
|
||||
|
@ -415,7 +419,7 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
|||
|
||||
sendKeepAlive();
|
||||
|
||||
receiveMessages();
|
||||
_numReceivedMessage = receiveMessages();
|
||||
|
||||
btRequestFactory->removeCompletedPiece();
|
||||
|
||||
|
@ -446,6 +450,11 @@ bool DefaultBtInteractive::isSendingMessageInProgress()
|
|||
return dispatcher->isSendingInProgress();
|
||||
}
|
||||
|
||||
size_t DefaultBtInteractive::countReceivedMessageInIteration() const
|
||||
{
|
||||
return _numReceivedMessage;
|
||||
}
|
||||
|
||||
void DefaultBtInteractive::setPeer(const SharedHandle<Peer>& peer)
|
||||
{
|
||||
this->peer = peer;
|
||||
|
|
|
@ -110,6 +110,8 @@ private:
|
|||
bool _utPexEnabled;
|
||||
bool _dhtEnabled;
|
||||
|
||||
size_t _numReceivedMessage;
|
||||
|
||||
static const int32_t FLOODING_CHECK_INTERVAL = 5;
|
||||
|
||||
void addBitfieldMessageToQueue();
|
||||
|
@ -146,12 +148,14 @@ public:
|
|||
|
||||
virtual void sendPendingMessage();
|
||||
|
||||
void receiveMessages();
|
||||
size_t receiveMessages();
|
||||
|
||||
virtual int32_t countPendingMessage();
|
||||
|
||||
virtual bool isSendingMessageInProgress();
|
||||
|
||||
virtual size_t countReceivedMessageInIteration() const;
|
||||
|
||||
void setCuid(int32_t cuid) {
|
||||
this->cuid = cuid;
|
||||
}
|
||||
|
|
|
@ -174,4 +174,9 @@ void PeerAbstractCommand::setNoCheck(bool check) {
|
|||
this->noCheck = check;
|
||||
}
|
||||
|
||||
void PeerAbstractCommand::updateKeepAlive()
|
||||
{
|
||||
checkPoint.reset();
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -68,6 +68,7 @@ protected:
|
|||
void setUploadLimit(int32_t uploadLimit);
|
||||
void setUploadLimitCheck(bool check);
|
||||
void setNoCheck(bool check);
|
||||
void updateKeepAlive();
|
||||
private:
|
||||
bool checkSocketIsReadable;
|
||||
bool checkSocketIsWritable;
|
||||
|
|
|
@ -174,17 +174,15 @@ PeerInteractionCommand::~PeerInteractionCommand() {
|
|||
}
|
||||
|
||||
bool PeerInteractionCommand::executeInternal() {
|
||||
setReadCheckSocket(socket);
|
||||
disableWriteCheckSocket();
|
||||
setUploadLimitCheck(false);
|
||||
setNoCheck(false);
|
||||
switch(sequence) {
|
||||
case INITIATOR_SEND_HANDSHAKE:
|
||||
if(!socket->isWritable(0)) {
|
||||
disableReadCheckSocket();
|
||||
setWriteCheckSocket(socket);
|
||||
break;
|
||||
}
|
||||
disableWriteCheckSocket();
|
||||
setReadCheckSocket(socket);
|
||||
socket->setBlockingMode();
|
||||
setTimeout(e->option->getAsInt(PREF_BT_TIMEOUT));
|
||||
btInteractive->initiateHandshake();
|
||||
|
@ -216,19 +214,30 @@ bool PeerInteractionCommand::executeInternal() {
|
|||
}
|
||||
case WIRED:
|
||||
btInteractive->doInteractionProcessing();
|
||||
|
||||
if(btInteractive->countReceivedMessageInIteration() > 0) {
|
||||
updateKeepAlive();
|
||||
}
|
||||
if(peer->amInterested && !peer->peerChoking ||
|
||||
peer->peerInterested && !peer->amChoking) {
|
||||
if(maxDownloadSpeedLimit > 0) {
|
||||
TransferStat stat = peerStorage->calculateStat();
|
||||
if(maxDownloadSpeedLimit < stat.downloadSpeed) {
|
||||
disableReadCheckSocket();
|
||||
setNoCheck(true);
|
||||
} else {
|
||||
setReadCheckSocket(socket);
|
||||
}
|
||||
} else {
|
||||
setReadCheckSocket(socket);
|
||||
}
|
||||
} else {
|
||||
disableReadCheckSocket();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(btInteractive->countPendingMessage() > 0) {
|
||||
setNoCheck(true);
|
||||
}
|
||||
if(maxDownloadSpeedLimit > 0) {
|
||||
TransferStat stat = peerStorage->calculateStat();
|
||||
if(maxDownloadSpeedLimit < stat.downloadSpeed) {
|
||||
disableReadCheckSocket();
|
||||
setNoCheck(true);
|
||||
}
|
||||
}
|
||||
e->commands.push_back(this);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue