From c893d8286779533bfd652c6de8394cf32f4ca835 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 11 Jan 2013 20:26:31 +0900 Subject: [PATCH] Removed BtMessage::isSendingProgress() DefaultBtMessageDispatcher::isSendingInProgress() now checks the number of buffer entry in PeerConnection. --- src/AbstractBtMessage.cc | 1 - src/AbstractBtMessage.h | 9 ------- src/BtMessage.h | 2 -- src/BtPieceMessage.cc | 2 -- src/BtRequestMessage.cc | 3 +-- src/DefaultBtMessageDispatcher.cc | 15 ++--------- test/BtPieceMessageTest.cc | 36 -------------------------- test/BtRequestMessageTest.cc | 13 ---------- test/DefaultBtMessageDispatcherTest.cc | 19 -------------- test/MockBtMessage.h | 9 ------- 10 files changed, 3 insertions(+), 106 deletions(-) diff --git a/src/AbstractBtMessage.cc b/src/AbstractBtMessage.cc index 607f2fe3..55177370 100644 --- a/src/AbstractBtMessage.cc +++ b/src/AbstractBtMessage.cc @@ -41,7 +41,6 @@ namespace aria2 { AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name) : BtMessage(id), - sendingInProgress_(false), invalidate_(false), uploading_(false), cuid_(0), diff --git a/src/AbstractBtMessage.h b/src/AbstractBtMessage.h index 4f7bf288..c34269e7 100644 --- a/src/AbstractBtMessage.h +++ b/src/AbstractBtMessage.h @@ -50,7 +50,6 @@ class BtMessageValidator; class AbstractBtMessage : public BtMessage { private: - bool sendingInProgress_; bool invalidate_; bool uploading_; cuid_t cuid_; @@ -107,14 +106,6 @@ public: virtual ~AbstractBtMessage(); - virtual bool isSendingInProgress() { - return sendingInProgress_; - } - - void setSendingInProgress(bool sendingInProgress) { - sendingInProgress_ = sendingInProgress; - } - virtual bool isInvalidate() { return invalidate_; } diff --git a/src/BtMessage.h b/src/BtMessage.h index 53f6ed82..5770dc13 100644 --- a/src/BtMessage.h +++ b/src/BtMessage.h @@ -55,8 +55,6 @@ public: virtual ~BtMessage() {} - virtual bool isSendingInProgress() = 0; - virtual bool isInvalidate() = 0; virtual bool isUploading() = 0; diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index 845493eb..b0362d72 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -290,7 +290,6 @@ void BtPieceMessage::onWrongPiece(const SharedHandle& piece) void BtPieceMessage::onChokingEvent(const BtChokingEvent& event) { if(!isInvalidate() && - !isSendingInProgress() && !getPeer()->isInAmAllowedIndexSet(index_)) { A2_LOG_DEBUG(fmt(MSG_REJECT_PIECE_CHOKED, getCuid(), @@ -311,7 +310,6 @@ void BtPieceMessage::onCancelSendingPieceEvent (const BtCancelSendingPieceEvent& event) { if(!isInvalidate() && - !isSendingInProgress() && index_ == event.getIndex() && begin_ == event.getBegin() && blockLength_ == event.getLength()) { diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc index 5595bdca..34473bf3 100644 --- a/src/BtRequestMessage.cc +++ b/src/BtRequestMessage.cc @@ -87,8 +87,7 @@ void BtRequestMessage::onQueued() void BtRequestMessage::onAbortOutstandingRequestEvent (const BtAbortOutstandingRequestEvent& event) { - if(getIndex() == event.getPiece()->getIndex() && - !isInvalidate() && !isSendingInProgress()) { + if(getIndex() == event.getPiece()->getIndex() && !isInvalidate()) { setInvalidate(true); } } diff --git a/src/DefaultBtMessageDispatcher.cc b/src/DefaultBtMessageDispatcher.cc index b385b38c..bc236350 100644 --- a/src/DefaultBtMessageDispatcher.cc +++ b/src/DefaultBtMessageDispatcher.cc @@ -94,7 +94,7 @@ void DefaultBtMessageDispatcher::sendMessagesInternal() while(!messageQueue_.empty()) { SharedHandle msg = messageQueue_.front(); messageQueue_.pop_front(); - if(msg->isUploading() && !msg->isSendingInProgress()) { + if(msg->isUploading()) { if(requestGroupMan_->doesOverallUploadSpeedExceed() || downloadContext_->getOwnerRequestGroup()->doesUploadSpeedExceed()) { tempQueue.push_back(msg); @@ -104,15 +104,8 @@ void DefaultBtMessageDispatcher::sendMessagesInternal() msg->send(); } if(!tempQueue.empty()) { - // Insert pending message to the front, so that message is likely sent in - // the same order as it is queued. - if(!messageQueue_.empty() && messageQueue_.front()->isSendingInProgress()) { - messageQueue_.insert(messageQueue_.begin()+1, - tempQueue.begin(), tempQueue.end()); - } else { messageQueue_.insert(messageQueue_.begin(), tempQueue.begin(), tempQueue.end()); - } } } @@ -350,11 +343,7 @@ void DefaultBtMessageDispatcher::checkRequestSlotAndDoNecessaryThing() bool DefaultBtMessageDispatcher::isSendingInProgress() { - if(messageQueue_.empty()) { - return false; - } else { - return messageQueue_.front()->isSendingInProgress(); - } + return peerConnection_->getBufferEntrySize(); } namespace { diff --git a/test/BtPieceMessageTest.cc b/test/BtPieceMessageTest.cc index 9a74cb88..9a120d55 100644 --- a/test/BtPieceMessageTest.cc +++ b/test/BtPieceMessageTest.cc @@ -27,12 +27,10 @@ class BtPieceMessageTest:public CppUnit::TestFixture { CPPUNIT_TEST(testChokingEvent_allowedFastEnabled); CPPUNIT_TEST(testChokingEvent_inAmAllowedIndexSet); CPPUNIT_TEST(testChokingEvent_invalidate); - CPPUNIT_TEST(testChokingEvent_sendingInProgress); CPPUNIT_TEST(testCancelSendingPieceEvent); CPPUNIT_TEST(testCancelSendingPieceEvent_noMatch); CPPUNIT_TEST(testCancelSendingPieceEvent_allowedFastEnabled); CPPUNIT_TEST(testCancelSendingPieceEvent_invalidate); - CPPUNIT_TEST(testCancelSendingPieceEvent_sendingInProgress); CPPUNIT_TEST(testToString); CPPUNIT_TEST_SUITE_END(); @@ -43,12 +41,10 @@ public: void testChokingEvent_allowedFastEnabled(); void testChokingEvent_inAmAllowedIndexSet(); void testChokingEvent_invalidate(); - void testChokingEvent_sendingInProgress(); void testCancelSendingPieceEvent(); void testCancelSendingPieceEvent_noMatch(); void testCancelSendingPieceEvent_allowedFastEnabled(); void testCancelSendingPieceEvent_invalidate(); - void testCancelSendingPieceEvent_sendingInProgress(); void testToString(); class MockBtMessage2 : public MockBtMessage { @@ -150,7 +146,6 @@ void BtPieceMessageTest::testCreateMessageHeader() { void BtPieceMessageTest::testChokingEvent() { CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(1)); CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); @@ -164,7 +159,6 @@ void BtPieceMessageTest::testChokingEvent_allowedFastEnabled() { peer->setFastExtensionEnabled(true); CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(1)); CPPUNIT_ASSERT(peer->isFastExtensionEnabled()); @@ -185,7 +179,6 @@ void BtPieceMessageTest::testChokingEvent_inAmAllowedIndexSet() { peer->addAmAllowedIndex(1); CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(peer->isInAmAllowedIndexSet(1)); CPPUNIT_ASSERT(peer->isFastExtensionEnabled()); @@ -198,7 +191,6 @@ void BtPieceMessageTest::testChokingEvent_inAmAllowedIndexSet() { void BtPieceMessageTest::testChokingEvent_invalidate() { msg->setInvalidate(true); CPPUNIT_ASSERT(msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(1)); CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); @@ -208,22 +200,8 @@ void BtPieceMessageTest::testChokingEvent_invalidate() { CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->messageQueue.size()); } -void BtPieceMessageTest::testChokingEvent_sendingInProgress() { - msg->setSendingInProgress(true); - CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(msg->isSendingInProgress()); - CPPUNIT_ASSERT(!peer->isInAmAllowedIndexSet(1)); - CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); - - msg->onChokingEvent(BtChokingEvent()); - - CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->messageQueue.size()); -} - void BtPieceMessageTest::testCancelSendingPieceEvent() { CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); @@ -233,7 +211,6 @@ void BtPieceMessageTest::testCancelSendingPieceEvent() { void BtPieceMessageTest::testCancelSendingPieceEvent_noMatch() { CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(0, 1024, 16*1024)); @@ -252,7 +229,6 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_noMatch() { void BtPieceMessageTest::testCancelSendingPieceEvent_allowedFastEnabled() { peer->setFastExtensionEnabled(true); CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(peer->isFastExtensionEnabled()); msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); @@ -271,7 +247,6 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_invalidate() { msg->setInvalidate(true); peer->setFastExtensionEnabled(true); CPPUNIT_ASSERT(msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); CPPUNIT_ASSERT(peer->isFastExtensionEnabled()); msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); @@ -280,17 +255,6 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_invalidate() { CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->messageQueue.size()); } -void BtPieceMessageTest::testCancelSendingPieceEvent_sendingInProgress() { - msg->setSendingInProgress(true); - CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(msg->isSendingInProgress()); - CPPUNIT_ASSERT(!peer->isFastExtensionEnabled()); - - msg->onCancelSendingPieceEvent(BtCancelSendingPieceEvent(1, 1024, 16*1024)); - - CPPUNIT_ASSERT(!msg->isInvalidate()); -} - void BtPieceMessageTest::testToString() { CPPUNIT_ASSERT_EQUAL(std::string("piece index=1, begin=1024, length=16384"), msg->toString()); diff --git a/test/BtRequestMessageTest.cc b/test/BtRequestMessageTest.cc index daa12b54..c54e6212 100644 --- a/test/BtRequestMessageTest.cc +++ b/test/BtRequestMessageTest.cc @@ -31,7 +31,6 @@ class BtRequestMessageTest:public CppUnit::TestFixture { CPPUNIT_TEST(testHandleAbortRequestEvent); CPPUNIT_TEST(testHandleAbortRequestEvent_indexNoMatch); CPPUNIT_TEST(testHandleAbortRequestEvent_alreadyInvalidated); - CPPUNIT_TEST(testHandleAbortRequestEvent_sendingInProgress); CPPUNIT_TEST(testToString); CPPUNIT_TEST(testValidate); CPPUNIT_TEST(testValidate_lengthTooLong); @@ -49,7 +48,6 @@ public: void testHandleAbortRequestEvent(); void testHandleAbortRequestEvent_indexNoMatch(); void testHandleAbortRequestEvent_alreadyInvalidated(); - void testHandleAbortRequestEvent_sendingInProgress(); void testToString(); void testValidate(); void testValidate_lengthTooLong(); @@ -238,7 +236,6 @@ void BtRequestMessageTest::testHandleAbortRequestEvent() { void BtRequestMessageTest::testHandleAbortRequestEvent_indexNoMatch() { SharedHandle piece(new Piece(2, 16*1024)); CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece)); CPPUNIT_ASSERT(!msg->isInvalidate()); } @@ -247,20 +244,10 @@ void BtRequestMessageTest::testHandleAbortRequestEvent_alreadyInvalidated() { SharedHandle piece(new Piece(1, 16*1024)); msg->setInvalidate(true); CPPUNIT_ASSERT(msg->isInvalidate()); - CPPUNIT_ASSERT(!msg->isSendingInProgress()); msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece)); CPPUNIT_ASSERT(msg->isInvalidate()); } -void BtRequestMessageTest::testHandleAbortRequestEvent_sendingInProgress() { - SharedHandle piece(new Piece(1, 16*1024)); - msg->setSendingInProgress(true); - CPPUNIT_ASSERT(!msg->isInvalidate()); - CPPUNIT_ASSERT(msg->isSendingInProgress()); - msg->onAbortOutstandingRequestEvent(BtAbortOutstandingRequestEvent(piece)); - CPPUNIT_ASSERT(!msg->isInvalidate()); -} - void BtRequestMessageTest::testToString() { CPPUNIT_ASSERT_EQUAL(std::string("request index=1, begin=16, length=32"), msg->toString()); diff --git a/test/DefaultBtMessageDispatcherTest.cc b/test/DefaultBtMessageDispatcherTest.cc index 71cb3ed8..89076824 100644 --- a/test/DefaultBtMessageDispatcherTest.cc +++ b/test/DefaultBtMessageDispatcherTest.cc @@ -35,7 +35,6 @@ class DefaultBtMessageDispatcherTest:public CppUnit::TestFixture { CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing); CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing_timeout); CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing_completeBlock); - CPPUNIT_TEST(testIsSendingInProgress); CPPUNIT_TEST(testCountOutstandingRequest); CPPUNIT_TEST(testIsOutstandingRequest); CPPUNIT_TEST(testGetOutstandingRequest); @@ -62,7 +61,6 @@ public: void testCheckRequestSlotAndDoNecessaryThing(); void testCheckRequestSlotAndDoNecessaryThing_timeout(); void testCheckRequestSlotAndDoNecessaryThing_completeBlock(); - void testIsSendingInProgress(); void testCountOutstandingRequest(); void testIsOutstandingRequest(); void testGetOutstandingRequest(); @@ -180,10 +178,8 @@ void DefaultBtMessageDispatcherTest::testAddMessage() { void DefaultBtMessageDispatcherTest::testSendMessages() { SharedHandle msg1(new MockBtMessage2()); - msg1->setSendingInProgress(false); msg1->setUploading(false); SharedHandle msg2(new MockBtMessage2()); - msg2->setSendingInProgress(false); msg2->setUploading(false); btMessageDispatcher->addMessageToQueue(msg1); btMessageDispatcher->addMessageToQueue(msg2); @@ -195,10 +191,8 @@ void DefaultBtMessageDispatcherTest::testSendMessages() { void DefaultBtMessageDispatcherTest::testSendMessages_underUploadLimit() { SharedHandle msg1(new MockBtMessage2()); - msg1->setSendingInProgress(false); msg1->setUploading(true); SharedHandle msg2(new MockBtMessage2()); - msg2->setSendingInProgress(false); msg2->setUploading(true); btMessageDispatcher->addMessageToQueue(msg1); btMessageDispatcher->addMessageToQueue(msg2); @@ -219,13 +213,10 @@ void DefaultBtMessageDispatcherTest::testSendMessages_underUploadLimit() { // peerStorage->setStat(stat); // SharedHandle msg1(new MockBtMessage2()); -// msg1->setSendingInProgress(false); // msg1->setUploading(true); // SharedHandle msg2(new MockBtMessage2()); -// msg2->setSendingInProgress(false); // msg2->setUploading(true); // SharedHandle msg3(new MockBtMessage2()); -// msg3->setSendingInProgress(false); // msg3->setUploading(false); // btMessageDispatcher->addMessageToQueue(msg1); @@ -327,16 +318,6 @@ void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing_com btMessageDispatcher->getRequestSlots().size()); } -void DefaultBtMessageDispatcherTest::testIsSendingInProgress() { - CPPUNIT_ASSERT(!btMessageDispatcher->isSendingInProgress()); - SharedHandle msg(new MockBtMessage2()); - msg->setSendingInProgress(false); - btMessageDispatcher->addMessageToQueue(msg); - CPPUNIT_ASSERT(!btMessageDispatcher->isSendingInProgress()); - msg->setSendingInProgress(true); - CPPUNIT_ASSERT(btMessageDispatcher->isSendingInProgress()); -} - void DefaultBtMessageDispatcherTest::testCountOutstandingRequest() { RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0); btMessageDispatcher->addOutstandingRequest(slot); diff --git a/test/MockBtMessage.h b/test/MockBtMessage.h index d7a600c6..37625a0f 100644 --- a/test/MockBtMessage.h +++ b/test/MockBtMessage.h @@ -41,7 +41,6 @@ namespace aria2 { class MockBtMessage : public BtMessage { private: - bool sendingInProgress; bool invalidate; bool uploading; public: @@ -51,14 +50,6 @@ public: virtual ~MockBtMessage() {} - virtual bool isSendingInProgress() { - return sendingInProgress; - } - - void setSendingInProgress(bool flag) { - this->sendingInProgress = flag; - } - virtual bool isInvalidate() { return invalidate; }