diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-05-24 15:18:58 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-05-24 15:18:58 +0000 |
| commit | 0411de92716bbdefa5dc795f1ecb8a2c2d61004e (patch) | |
| tree | 374ffa60e707f21a17d3e599459e6614eda98489 /src/TrackerWatcherCommand.cc | |
| parent | 896ca193e01f9f629f222fe992e05aebdca23a24 (diff) | |
2006-05-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To attempt to handle EINTR:
* src/SocketCore.cc
(isReadable): Added EINTR handling.
(isWritable): Added EINTR handling.
To improve the performance:
* src/AbstractCommand.cc
(isTimeoutDetected): Use Util::difftvsec() instead of
Util::difftv().
* src/PeerInteractionCommand.h
(receiveMessage): Renamed as receiveMessages().
(receiveMessages): New function.
* src/PeerInteractionCommand.cc
(executeInternal): receiveMessage loop is moved to new
receiveMessages
() function. detectMessageFlooding() is moved here.
(detectMessageFlooding): Use Util::difftvsec() instead of
Util::difftv
(). The flooding detection for have message is comment out.
(checkLongTimePeerChoking): Use Util::difftvsec() instead of
Util::difftv().
(receiveMessage): Renamed as receiveMessages().
(receiveMessages): New function.
(keepAlive): Use Util::difftvsec() instead of Util::difftv().
(beforeSocketCheck): Commented out checkLongTimePeerChoking().
* src/SleepCommand.cc
(execute): Use Util::difftvsec() instead of Util::difftv().
* src/BitfieldMan.h
(getNthBitIndex): New function.
(hasMissingPiece): New function.
(getAllMissingIndexes): New function.
* src/BitfieldMan.cc
(countSetBit): Rewritten.
(getNthBitIndex): New function.
(getMissingIndexRandomly): Rewritten.
(hasMissingPiece): New function.
(getAllMissingIndexes): New function.
* src/TorrentMan.cc
(hasMissingPiece): New function.
(deleteUsedPiece): Rewritten using STL.
* src/PeerInteraction.cc
(getNewPieceAndSendInterest): Use TorrentMan::hasMissingPiece(),
which
is a little bit faster then TorrentMan::getMissingPieceIndex().
(addRequests): Updated the number of pending requests.
* src/PeerAbstractCommand.cc
(isTimeoutDetected): Use Util::difftvsec() instead of
Util::difftv().
(execute): Returns true if TorrentMan::isHalt() is true.
Corrected the condition of upload limit checking.
* src/Util.h
(countBit): New function.
* src/Util.cc
(nbits): New variable.
(countBit): New function.
* src/DownloadEngine.h
(SockCmdMap): New type definition.
(waitData): Added an argument.
(addSocket): Added an argument.
(addSocketForReadCheck): Added an argument.
(addSocketForWriteCheck): Added an argument.
* src/DownloadEngine.cc
(run): Executes only commands whose sockets are ready to read or
write.
All commands are executed in every 1 second.
(waitData): Calls select() again if it returned
EINTR.
(addSocket): Saves socket and command object pair to the map.
(deleteSocket): Deletes socket and command object pair from the
map.
(addSocketForReadCheck): Added an argument.
(addSocketForWriteCheck): Added an argument.
* src/DownloadCommand.cc
(executeInternal): Use Util::difftvsec() instead of
Util::difftv().
To send "event=stopped" to the tracker when the application
finishes:
* src/PeerChokeCommand.h
(checkPoint): New variable.
* src/PeerChokeCommand.cc
(PeerChokeCommand): Added the initialization of checkPoint.
(execute): The interval check is now done by checkPoint, not
SleepCommand. Return true if TorrentMan::isHalt() is true.
* src/TorrentMan.h
(halt): New function.
(hasMissingPiece): New function.
(isHalt): New function.
(setHalt): New function.
* src/TorrentMan.cc
(TorrentMan): Added the initialization of halt.
* src/TorrentAutoSaveCommand.h
(checkPoint): New variable.
* src/PeerListenCommand.cc
(execute): Returns true if TorrentMan::isHalt() is true.
* src/main.cc
(setSignalHander): Added flags argument.
(torrentHandler): Just calls TorrentMan::setHalt(true) and
returns.
(main): Set SA_ONESHOT flag of the signal hander of SIGINT and
SIGTERM.
Removed printDownloadAbortMessage() after torrent downloading
loop.
* src/TorrentAutoSaveCommand.cc
(TorrentAutoSaveCommand): Added the initialization of
checkPoint.
(execute): Returns true if TorrentMan::isHalt() is true.
The interval check is now done by checkPoint, not SleepCommand.
* src/TrackerWatcherCommand.cc
(execute): If TorrentMan::isHalt(), then create a tracker
request with
event=stopped.
* src/TrackerUpdateCommand.cc
(prepareForRetry): Do not use SleepCommand here.
(execute): Returns true if TorrentMan::isHalt() is true.
Others:
* src/TorrentMan.cc
(getMissingPieceIndex): Updated log message.
* src/PeerInteraction.cc
(createPeerMessag): Updated log message.
Diffstat (limited to 'src/TrackerWatcherCommand.cc')
| -rw-r--r-- | src/TrackerWatcherCommand.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 0677c52e..426119ab 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -20,7 +20,6 @@ */ /* copyright --> */ #include "TrackerWatcherCommand.h" -#include "SleepCommand.h" #include "InitiateConnectionCommandFactory.h" #include "Util.h" @@ -37,16 +36,17 @@ TrackerWatcherCommand::~TrackerWatcherCommand() {} bool TrackerWatcherCommand::execute() { struct timeval now; gettimeofday(&now, NULL); - if(e->torrentMan->trackers == 0 && - Util::difftvsec(now, checkPoint) >= interval) { + (Util::difftvsec(now, checkPoint) >= interval || e->torrentMan->isHalt())) { checkPoint = now; e->torrentMan->req->resetTryCount(); int numWant = 50; - if(e->torrentMan->connections >= MIN_PEERS) { + if(e->torrentMan->connections >= MIN_PEERS || e->torrentMan->isHalt()) { numWant = 0; - } - if(e->torrentMan->downloadComplete()) { + } + if(e->torrentMan->isHalt()) { + e->torrentMan->req->setTrackerEvent(Request::STOPPED); + } else if(e->torrentMan->downloadComplete()) { if(e->torrentMan->req->getTrackerEvent() == Request::COMPLETED) { e->torrentMan->req->setTrackerEvent(Request::AFTER_COMPLETED); } else { @@ -92,6 +92,9 @@ bool TrackerWatcherCommand::execute() { e->torrentMan->trackers++; logger->info("CUID#%d - creating new tracker request command #%d", cuid, command->getCuid()); + if(e->torrentMan->isHalt()) { + return true; + } } interval = e->torrentMan->minInterval; e->commands.push_back(this); |
