mirror of https://github.com/aria2/aria2
Removed BtMessage::isSendingProgress()
DefaultBtMessageDispatcher::isSendingInProgress() now checks the number of buffer entry in PeerConnection.pull/43/head
parent
c04df672d1
commit
c893d82867
|
@ -41,7 +41,6 @@ namespace aria2 {
|
|||
|
||||
AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name)
|
||||
: BtMessage(id),
|
||||
sendingInProgress_(false),
|
||||
invalidate_(false),
|
||||
uploading_(false),
|
||||
cuid_(0),
|
||||
|
|
|
@ -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_;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,6 @@ public:
|
|||
|
||||
virtual ~BtMessage() {}
|
||||
|
||||
virtual bool isSendingInProgress() = 0;
|
||||
|
||||
virtual bool isInvalidate() = 0;
|
||||
|
||||
virtual bool isUploading() = 0;
|
||||
|
|
|
@ -290,7 +290,6 @@ void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& 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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ void DefaultBtMessageDispatcher::sendMessagesInternal()
|
|||
while(!messageQueue_.empty()) {
|
||||
SharedHandle<BtMessage> 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 {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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> 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> 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> 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());
|
||||
|
|
|
@ -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<MockBtMessage2> msg1(new MockBtMessage2());
|
||||
msg1->setSendingInProgress(false);
|
||||
msg1->setUploading(false);
|
||||
SharedHandle<MockBtMessage2> 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<MockBtMessage2> msg1(new MockBtMessage2());
|
||||
msg1->setSendingInProgress(false);
|
||||
msg1->setUploading(true);
|
||||
SharedHandle<MockBtMessage2> 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<MockBtMessage2> msg1(new MockBtMessage2());
|
||||
// msg1->setSendingInProgress(false);
|
||||
// msg1->setUploading(true);
|
||||
// SharedHandle<MockBtMessage2> msg2(new MockBtMessage2());
|
||||
// msg2->setSendingInProgress(false);
|
||||
// msg2->setUploading(true);
|
||||
// SharedHandle<MockBtMessage2> 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<MockBtMessage2> 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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue