mirror of https://github.com/aria2/aria2
				
				
				
			2009-02-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that adding 0 length filter to BitfieldMan filters 1 block. It should not filter anything. * src/BitfieldMan.cc * src/ConsoleStatCalc.cc * test/BitfieldManTest.ccpull/1/head
							parent
							
								
									a8376a5c4b
								
							
						
					
					
						commit
						0fc900c0ac
					
				| 
						 | 
					@ -1,3 +1,11 @@
 | 
				
			||||||
 | 
					2009-02-11  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Fixed the bug that adding 0 length filter to BitfieldMan filters 1
 | 
				
			||||||
 | 
						block. It should not filter anything.
 | 
				
			||||||
 | 
						* src/BitfieldMan.cc
 | 
				
			||||||
 | 
						* src/ConsoleStatCalc.cc
 | 
				
			||||||
 | 
						* test/BitfieldManTest.cc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2009-02-11  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
					2009-02-11  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Fixed the bug that the boolean options that don't take arguments
 | 
						Fixed the bug that the boolean options that don't take arguments
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,10 +33,12 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
/* copyright --> */
 | 
					/* copyright --> */
 | 
				
			||||||
#include "BitfieldMan.h"
 | 
					#include "BitfieldMan.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <cstring>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Randomizer.h"
 | 
					#include "Randomizer.h"
 | 
				
			||||||
#include "Util.h"
 | 
					#include "Util.h"
 | 
				
			||||||
#include "array_fun.h"
 | 
					#include "array_fun.h"
 | 
				
			||||||
#include <cstring>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace aria2 {
 | 
					namespace aria2 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -609,10 +611,12 @@ void BitfieldMan::addFilter(uint64_t offset, uint64_t length) {
 | 
				
			||||||
    filterBitfield = new unsigned char[bitfieldLength];
 | 
					    filterBitfield = new unsigned char[bitfieldLength];
 | 
				
			||||||
    memset(filterBitfield, 0, bitfieldLength);
 | 
					    memset(filterBitfield, 0, bitfieldLength);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  size_t startBlock = offset/blockLength;
 | 
					  if(length > 0) {
 | 
				
			||||||
  size_t endBlock = (offset+length-1)/blockLength;
 | 
					    size_t startBlock = offset/blockLength;
 | 
				
			||||||
  for(size_t i = startBlock; i <= endBlock && i < blocks; i++) {
 | 
					    size_t endBlock = (offset+length-1)/blockLength;
 | 
				
			||||||
    setFilterBit(i);
 | 
					    for(size_t i = startBlock; i <= endBlock && i < blocks; i++) {
 | 
				
			||||||
 | 
					      setFilterBit(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  updateCache();
 | 
					  updateCache();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,10 +75,14 @@ static void printProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg)
 | 
				
			||||||
#ifdef ENABLE_BITTORRENT
 | 
					#ifdef ENABLE_BITTORRENT
 | 
				
			||||||
  if(rg->downloadFinished() &&
 | 
					  if(rg->downloadFinished() &&
 | 
				
			||||||
     !dynamic_pointer_cast<BtContext>(rg->getDownloadContext()).isNull()) {
 | 
					     !dynamic_pointer_cast<BtContext>(rg->getDownloadContext()).isNull()) {
 | 
				
			||||||
    o << "SEEDING" << "(" << "ratio:"
 | 
					    o << "SEEDING" << "(" << "ratio:";
 | 
				
			||||||
      << std::fixed << std::setprecision(1)
 | 
					    if(rg->getCompletedLength() > 0) {
 | 
				
			||||||
      << ((stat.getAllTimeUploadLength()*10)/rg->getCompletedLength())/10.0
 | 
					      o << std::fixed << std::setprecision(1)
 | 
				
			||||||
      << ")";
 | 
						<< ((stat.getAllTimeUploadLength()*10)/rg->getCompletedLength())/10.0;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      o << "--";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    o << ")";
 | 
				
			||||||
  } else
 | 
					  } else
 | 
				
			||||||
#endif // ENABLE_BITTORRENT
 | 
					#endif // ENABLE_BITTORRENT
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,11 @@
 | 
				
			||||||
#include "BitfieldMan.h"
 | 
					#include "BitfieldMan.h"
 | 
				
			||||||
#include "FixedNumberRandomizer.h"
 | 
					
 | 
				
			||||||
#include <cstring>
 | 
					#include <cstring>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <cppunit/extensions/HelperMacros.h>
 | 
					#include <cppunit/extensions/HelperMacros.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "FixedNumberRandomizer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace aria2 {
 | 
					namespace aria2 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BitfieldManTest:public CppUnit::TestFixture {
 | 
					class BitfieldManTest:public CppUnit::TestFixture {
 | 
				
			||||||
| 
						 | 
					@ -13,6 +16,7 @@ class BitfieldManTest:public CppUnit::TestFixture {
 | 
				
			||||||
  CPPUNIT_TEST(testGetFirstMissingIndex);
 | 
					  CPPUNIT_TEST(testGetFirstMissingIndex);
 | 
				
			||||||
  CPPUNIT_TEST(testIsAllBitSet);
 | 
					  CPPUNIT_TEST(testIsAllBitSet);
 | 
				
			||||||
  CPPUNIT_TEST(testFilter);
 | 
					  CPPUNIT_TEST(testFilter);
 | 
				
			||||||
 | 
					  CPPUNIT_TEST(testAddFilter_zeroLength);
 | 
				
			||||||
  CPPUNIT_TEST(testGetMissingIndex);
 | 
					  CPPUNIT_TEST(testGetMissingIndex);
 | 
				
			||||||
  CPPUNIT_TEST(testGetSparceMissingUnusedIndex);
 | 
					  CPPUNIT_TEST(testGetSparceMissingUnusedIndex);
 | 
				
			||||||
  CPPUNIT_TEST(testGetSparceMissingUnusedIndex_setBit);
 | 
					  CPPUNIT_TEST(testGetSparceMissingUnusedIndex_setBit);
 | 
				
			||||||
| 
						 | 
					@ -54,6 +58,7 @@ public:
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  void testIsAllBitSet();
 | 
					  void testIsAllBitSet();
 | 
				
			||||||
  void testFilter();
 | 
					  void testFilter();
 | 
				
			||||||
 | 
					  void testAddFilter_zeroLength();
 | 
				
			||||||
  void testGetSparceMissingUnusedIndex();
 | 
					  void testGetSparceMissingUnusedIndex();
 | 
				
			||||||
  void testGetSparceMissingUnusedIndex_setBit();
 | 
					  void testGetSparceMissingUnusedIndex_setBit();
 | 
				
			||||||
  void testIsBitSetOffsetRange();
 | 
					  void testIsBitSetOffsetRange();
 | 
				
			||||||
| 
						 | 
					@ -369,6 +374,15 @@ void BitfieldManTest::testFilter() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void BitfieldManTest::testAddFilter_zeroLength()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  BitfieldMan bits(1024, 1024*1024);
 | 
				
			||||||
 | 
					  bits.addFilter(2048, 0);
 | 
				
			||||||
 | 
					  bits.enableFilter();
 | 
				
			||||||
 | 
					  CPPUNIT_ASSERT_EQUAL((size_t)0, bits.countMissingBlock());
 | 
				
			||||||
 | 
					  CPPUNIT_ASSERT(bits.isFilteredAllBitSet());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BitfieldManTest::testGetMissingIndex() {
 | 
					void BitfieldManTest::testGetMissingIndex() {
 | 
				
			||||||
  BitfieldMan bt1(1024, 1024*256);
 | 
					  BitfieldMan bt1(1024, 1024*256);
 | 
				
			||||||
  bt1.setRandomizer(fixedNumberRandomizer);
 | 
					  bt1.setRandomizer(fixedNumberRandomizer);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue