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>
 | 
			
		||||
 | 
			
		||||
	Fixed the bug that the boolean options that don't take arguments
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,10 +33,12 @@
 | 
			
		|||
 */
 | 
			
		||||
/* copyright --> */
 | 
			
		||||
#include "BitfieldMan.h"
 | 
			
		||||
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
#include "Randomizer.h"
 | 
			
		||||
#include "Util.h"
 | 
			
		||||
#include "array_fun.h"
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
namespace aria2 {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -609,11 +611,13 @@ void BitfieldMan::addFilter(uint64_t offset, uint64_t length) {
 | 
			
		|||
    filterBitfield = new unsigned char[bitfieldLength];
 | 
			
		||||
    memset(filterBitfield, 0, bitfieldLength);
 | 
			
		||||
  }
 | 
			
		||||
  if(length > 0) {
 | 
			
		||||
    size_t startBlock = offset/blockLength;
 | 
			
		||||
    size_t endBlock = (offset+length-1)/blockLength;
 | 
			
		||||
    for(size_t i = startBlock; i <= endBlock && i < blocks; i++) {
 | 
			
		||||
      setFilterBit(i);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  updateCache();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,10 +75,14 @@ static void printProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg)
 | 
			
		|||
#ifdef ENABLE_BITTORRENT
 | 
			
		||||
  if(rg->downloadFinished() &&
 | 
			
		||||
     !dynamic_pointer_cast<BtContext>(rg->getDownloadContext()).isNull()) {
 | 
			
		||||
    o << "SEEDING" << "(" << "ratio:"
 | 
			
		||||
      << std::fixed << std::setprecision(1)
 | 
			
		||||
      << ((stat.getAllTimeUploadLength()*10)/rg->getCompletedLength())/10.0
 | 
			
		||||
      << ")";
 | 
			
		||||
    o << "SEEDING" << "(" << "ratio:";
 | 
			
		||||
    if(rg->getCompletedLength() > 0) {
 | 
			
		||||
      o << std::fixed << std::setprecision(1)
 | 
			
		||||
	<< ((stat.getAllTimeUploadLength()*10)/rg->getCompletedLength())/10.0;
 | 
			
		||||
    } else {
 | 
			
		||||
      o << "--";
 | 
			
		||||
    }
 | 
			
		||||
    o << ")";
 | 
			
		||||
  } else
 | 
			
		||||
#endif // ENABLE_BITTORRENT
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,11 @@
 | 
			
		|||
#include "BitfieldMan.h"
 | 
			
		||||
#include "FixedNumberRandomizer.h"
 | 
			
		||||
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
#include <cppunit/extensions/HelperMacros.h>
 | 
			
		||||
 | 
			
		||||
#include "FixedNumberRandomizer.h"
 | 
			
		||||
 | 
			
		||||
namespace aria2 {
 | 
			
		||||
 | 
			
		||||
class BitfieldManTest:public CppUnit::TestFixture {
 | 
			
		||||
| 
						 | 
				
			
			@ -13,6 +16,7 @@ class BitfieldManTest:public CppUnit::TestFixture {
 | 
			
		|||
  CPPUNIT_TEST(testGetFirstMissingIndex);
 | 
			
		||||
  CPPUNIT_TEST(testIsAllBitSet);
 | 
			
		||||
  CPPUNIT_TEST(testFilter);
 | 
			
		||||
  CPPUNIT_TEST(testAddFilter_zeroLength);
 | 
			
		||||
  CPPUNIT_TEST(testGetMissingIndex);
 | 
			
		||||
  CPPUNIT_TEST(testGetSparceMissingUnusedIndex);
 | 
			
		||||
  CPPUNIT_TEST(testGetSparceMissingUnusedIndex_setBit);
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +58,7 @@ public:
 | 
			
		|||
  
 | 
			
		||||
  void testIsAllBitSet();
 | 
			
		||||
  void testFilter();
 | 
			
		||||
  void testAddFilter_zeroLength();
 | 
			
		||||
  void testGetSparceMissingUnusedIndex();
 | 
			
		||||
  void testGetSparceMissingUnusedIndex_setBit();
 | 
			
		||||
  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() {
 | 
			
		||||
  BitfieldMan bt1(1024, 1024*256);
 | 
			
		||||
  bt1.setRandomizer(fixedNumberRandomizer);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue