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/PeerAbstractCommand.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/PeerAbstractCommand.cc')
| -rw-r--r-- | src/PeerAbstractCommand.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index 0c6386f0..7008c2d9 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -64,8 +64,8 @@ bool PeerAbstractCommand::isTimeoutDetected() { checkPoint = now; return false; } else { - long long int elapsed = Util::difftv(now, checkPoint); - if(elapsed >= ((long long int)timeout)*1000000) { + int elapsed = Util::difftvsec(now, checkPoint); + if(elapsed >= timeout) { return true; } else { return false; @@ -74,9 +74,13 @@ bool PeerAbstractCommand::isTimeoutDetected() { } bool PeerAbstractCommand::execute() { + if(e->torrentMan->isHalt()) { + return true; + } try { beforeSocketCheck(); - if(uploadLimitCheck && e->getUploadSpeed() <= uploadLimit*1024 || + if(uploadLimitCheck && (uploadLimit == 0 || + e->getUploadSpeed() <= uploadLimit*1024) || checkSocketIsReadable && readCheckTarget->isReadable(0) || checkSocketIsWritable && writeCheckTarget->isWritable(0) || !checkSocketIsReadable && !checkSocketIsWritable) { @@ -130,11 +134,11 @@ void PeerAbstractCommand::setReadCheckSocket(Socket* socket) { if(checkSocketIsReadable) { if(readCheckTarget != socket) { e->deleteSocketForReadCheck(readCheckTarget); - e->addSocketForReadCheck(socket); + e->addSocketForReadCheck(socket, this); readCheckTarget = socket; } } else { - e->addSocketForReadCheck(socket); + e->addSocketForReadCheck(socket, this); checkSocketIsReadable = true; readCheckTarget = socket; } @@ -152,11 +156,11 @@ void PeerAbstractCommand::setWriteCheckSocket(Socket* socket) { if(checkSocketIsWritable) { if(writeCheckTarget != socket) { e->deleteSocketForWriteCheck(writeCheckTarget); - e->addSocketForWriteCheck(socket); + e->addSocketForWriteCheck(socket, this); writeCheckTarget = socket; } } else { - e->addSocketForWriteCheck(socket); + e->addSocketForWriteCheck(socket, this); checkSocketIsWritable = true; writeCheckTarget = socket; } |
