changed insertion in queue for cache files: these are always placed before the first non cache file, hence giving cache files a higher priority over normal downloads.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3502 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-09-15 19:48:13 +00:00
parent f080fb22a0
commit 301b7daa88
2 changed files with 35 additions and 5 deletions

View File

@ -69,6 +69,9 @@ static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress e
static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released
static const uint32_t MAX_TIME_INACTIVE_REQUEUED = 60 ; // time after which an inactive ftFileControl is bt-queued static const uint32_t MAX_TIME_INACTIVE_REQUEUED = 60 ; // time after which an inactive ftFileControl is bt-queued
static const uint32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ;
static const uint32_t FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE = 1 ;
ftFileControl::ftFileControl() ftFileControl::ftFileControl()
:mTransfer(NULL), mCreator(NULL), :mTransfer(NULL), mCreator(NULL),
mState(DOWNLOADING), mSize(0), mFlags(0), mState(DOWNLOADING), mSize(0), mFlags(0),
@ -437,13 +440,40 @@ void ftController::checkDownloadQueue()
} }
} }
void ftController::locked_addToQueue(ftFileControl* ftfc) void ftController::locked_addToQueue(ftFileControl* ftfc,int add_strategy)
{ {
#ifdef DEBUG_DWLQUEUE #ifdef DEBUG_DWLQUEUE
std::cerr << "Queueing ftfileControl " << (void*)ftfc << ", name=" << ftfc->mName << std::endl ; std::cerr << "Queueing ftfileControl " << (void*)ftfc << ", name=" << ftfc->mName << std::endl ;
#endif #endif
_queue.push_back(ftfc) ;
switch(add_strategy)
{
case FT_FILECONTROL_QUEUE_ADD_END: _queue.push_back(ftfc) ;
locked_checkQueueElement(_queue.size()-1) ; locked_checkQueueElement(_queue.size()-1) ;
break ;
case FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE:
{
// We add the transfer just before the first non cache transfer.
//
uint32_t pos =0;
while(pos < _queue.size() && (_queue[pos]->mFlags & RS_FILE_HINTS_CACHE)>0)
++pos ;
_queue.push_back(NULL) ;
for(int i=int(_queue.size())-1;i>pos;--i)
{
_queue[i] = _queue[i-1] ;
locked_checkQueueElement(i) ;
}
_queue[pos] = ftfc ;
locked_checkQueueElement(pos) ;
std::cerr << "!!!!!!!!!!!!!! Added cache transfer at position " << pos << std::endl ;
}
break ;
}
} }
void ftController::locked_queueRemove(uint32_t pos) void ftController::locked_queueRemove(uint32_t pos)
@ -1248,7 +1278,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
/* add structures into the accessible data. Needs to be locked */ /* add structures into the accessible data. Needs to be locked */
{ {
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
locked_addToQueue(ftfc) ; locked_addToQueue(ftfc, (flags & RS_FILE_HINTS_CACHE)?FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE : FT_FILECONTROL_QUEUE_ADD_END ) ;
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc; std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc;

View File

@ -217,7 +217,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
/* RunTime Functions */ /* RunTime Functions */
void checkDownloadQueue(); // check the whole queue for inactive files void checkDownloadQueue(); // check the whole queue for inactive files
void locked_addToQueue(ftFileControl*) ; // insert this one into the queue void locked_addToQueue(ftFileControl*,int strategy) ;// insert this one into the queue
void locked_bottomQueue(uint32_t pos) ; // bottom queue file which is at this position void locked_bottomQueue(uint32_t pos) ; // bottom queue file which is at this position
void locked_topQueue(uint32_t pos) ; // top queue file which is at this position void locked_topQueue(uint32_t pos) ; // top queue file which is at this position
void locked_checkQueueElement(uint32_t pos) ; // check the state of this element in the queue void locked_checkQueueElement(uint32_t pos) ; // check the state of this element in the queue