mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 00:49:41 -05:00
add a downloading queue in ftControl,max 2 files can be download at same time
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@933 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
812cdd6bd6
commit
0654836a3d
@ -119,20 +119,28 @@ void ftController::run()
|
|||||||
/* tick the transferModules */
|
/* tick the transferModules */
|
||||||
std::list<std::string> done;
|
std::list<std::string> done;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
|
std::map<std::string,ftFileControl>::iterator mit;
|
||||||
|
if (mDownloadingQueue.size() > 0)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
for(it = mDownloadingQueue.begin(); it != mDownloadingQueue.end(); it++)
|
||||||
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "\tTicking: " << it->first;
|
std::cerr << "\tTicking: " << *it;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
mit = mDownloads.find(*it);
|
||||||
if (it->second.mTransfer)
|
if (mit != mDownloads.end())
|
||||||
(it->second.mTransfer)->tick();
|
{
|
||||||
|
if (mit->second.mTransfer)
|
||||||
|
(mit->second.mTransfer)->tick();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mDownloadingQueue.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +151,8 @@ void ftController::run()
|
|||||||
}
|
}
|
||||||
mDone.clear();
|
mDone.clear();
|
||||||
|
|
||||||
|
/* adjust the Downloading queue*/
|
||||||
|
checkDownloadQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -152,9 +162,26 @@ void ftController::run()
|
|||||||
/* Called every 10 seconds or so */
|
/* Called every 10 seconds or so */
|
||||||
void ftController::checkDownloadQueue()
|
void ftController::checkDownloadQueue()
|
||||||
{
|
{
|
||||||
/* */
|
uint32_t cnt = MAX_NUMBER_OF_DOWNLOADING_FILE - mDownloadingQueue.size();
|
||||||
|
if (cnt <= 0) return;
|
||||||
|
|
||||||
|
RsStackMutex stack(ctrlMutex);
|
||||||
|
std::map<std::string,ftFileControl>::iterator mit;
|
||||||
|
mit = mDownloads.begin();
|
||||||
|
while (cnt-- > 0)
|
||||||
|
{
|
||||||
|
while ((mit != mDownloads.end()) && (mit->second.mState != ftFileControl::DOWNLOADING))
|
||||||
|
{ mit++ ; }
|
||||||
|
|
||||||
|
if (mit != mDownloads.end())
|
||||||
|
{
|
||||||
|
mDownloadingQueue.push_back(mit->first);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftController::FlagFileComplete(std::string hash)
|
bool ftController::FlagFileComplete(std::string hash)
|
||||||
@ -275,6 +302,7 @@ bool ftController::completeFile(std::string hash)
|
|||||||
callbackCode = fc->mCallbackCode;
|
callbackCode = fc->mCallbackCode;
|
||||||
|
|
||||||
mDownloads.erase(it);
|
mDownloads.erase(it);
|
||||||
|
mDownloadingQueue.remove(it->first);
|
||||||
} /******* UNLOCKED ********/
|
} /******* UNLOCKED ********/
|
||||||
|
|
||||||
|
|
||||||
@ -614,6 +642,10 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
mDownloads[hash] = ftfc;
|
mDownloads[hash] = ftfc;
|
||||||
mSlowQueue.push_back(hash);
|
mSlowQueue.push_back(hash);
|
||||||
|
|
||||||
|
if (mDownloadingQueue.size() < MAX_NUMBER_OF_DOWNLOADING_FILE)
|
||||||
|
{
|
||||||
|
mDownloadingQueue.push_back(hash);
|
||||||
|
}
|
||||||
|
|
||||||
IndicateConfigChanged(); /* completed transfer -> save */
|
IndicateConfigChanged(); /* completed transfer -> save */
|
||||||
return true;
|
return true;
|
||||||
@ -726,6 +758,8 @@ bool ftController::FileCancel(std::string hash)
|
|||||||
//fc->mState = ftFileControl::ERROR_COMPLETION;
|
//fc->mState = ftFileControl::ERROR_COMPLETION;
|
||||||
mDownloads.erase(mit);
|
mDownloads.erase(mit);
|
||||||
|
|
||||||
|
mDownloadingQueue.remove(mit->first);
|
||||||
|
|
||||||
IndicateConfigChanged(); /* completed transfer -> save */
|
IndicateConfigChanged(); /* completed transfer -> save */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ const uint32_t CB_CODE_MEDIA = 0x0004;
|
|||||||
|
|
||||||
const uint32_t FC_TRANSFER_COMPLETE = 0x0001;
|
const uint32_t FC_TRANSFER_COMPLETE = 0x0001;
|
||||||
|
|
||||||
|
const uint32_t MAX_NUMBER_OF_DOWNLOADING_FILE = 0x0002; //will be controller by user later
|
||||||
|
|
||||||
class ftFileControl
|
class ftFileControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -190,7 +192,8 @@ bool setPeerState(ftTransferModule *tm, std::string id,
|
|||||||
std::map<std::string, ftFileControl> mCompleted;
|
std::map<std::string, ftFileControl> mCompleted;
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, ftFileControl> mDownloads;
|
std::map<std::string, ftFileControl> mDownloads; //include downloading and pending downloading
|
||||||
|
std::list<std::string> mDownloadingQueue; //only include downloading file hashs
|
||||||
|
|
||||||
//std::map<std::string, ftTransferModule *> mTransfers;
|
//std::map<std::string, ftTransferModule *> mTransfers;
|
||||||
//std::map<std::string, ftFileCreator *> mFileCreators;
|
//std::map<std::string, ftFileCreator *> mFileCreators;
|
||||||
|
Loading…
Reference in New Issue
Block a user