本文整理汇总了C++中MetaData::readMetaData方法的典型用法代码示例。如果您正苦于以下问题:C++ MetaData::readMetaData方法的具体用法?C++ MetaData::readMetaData怎么用?C++ MetaData::readMetaData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetaData
的用法示例。
在下文中一共展示了MetaData::readMetaData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
for(unsigned int i=0; i<localFileList[hashes[reqdIndex-1]].source.size(), metaDownloaded==false;i++){
int statusConnect = senderMetaTCP.connectToServer(localFileList[hashes[reqdIndex-1]].source[0],META_REQUEST_PORT);
if(DEBUG){
cout<<"status:"<<statusConnect<<endl;
}
if(statusConnect==-1)
continue;
senderMetaTCP.sendDataToServer(dataToSend);
response = senderMetaTCP.readData();
if(DEBUG)
cout<<"Response received : "<<response;
// If meta is present, then write to file and set metaDownloaded to true
if(!utilsobj.equality(response, "META -1")){
if(DEBUG){
cout<<"Metadata received. Writing to file."<<endl;
}
metaDownloaded = true;
metaFileName = fileName+META_EXTENSION+P2P_EXTENSION;
writeMetaToFile(metaFileName,response);
}
}
// If meta hasnt been received, alert user.
if(!metaDownloaded){
cout<<"The file is not yet ready for download"<<endl;
continue;
}
//4.repeat 3 until meta is received
//5.after receiving meta, decide divison of blocks over IPs
MetaData metadataObj;
MetaData metaData = metadataObj.readMetaData(fileName);
long long int noOfBlocks = metaData.noOfBlocks;
int sizeOfLastBlock = BLOCK_SIZE;
long long int blocksLeft = noOfBlocks;
//unsigned int noOfSources = sourceIPMap.size();
int blocksPerSource = mini(noOfBlocks,BLOCKS_PER_SOURCE);
int startBlock = 0;
int lastBlock = mini(blocksPerSource-1, blocksLeft-1);
//6.send specific request in separate threads
if(DEBUG)
cout<<"download info: "<<startBlock<<" "<<lastBlock<<" "<<sizeOfLastBlock<<" "<<blocksPerSource<<" "<<noOfBlocks<<endl;
downloaded=0;
bool completed=false;
do{
for(map<string,bool>::iterator it = sourceIPMap.begin();it!=sourceIPMap.end();it++){
if(it->second==true){
if(DEBUG)
cout<<startBlock<<" "<<lastBlock<<endl;
string ip = it->first;
it->second=false;
if(lastBlock==noOfBlocks-1)
sizeOfLastBlock=metaData.fileSize - ((noOfBlocks-1)*BLOCK_SIZE);
downloadThreadVector.push_back(thread(downloadBlocks,ip,fileName,startBlock,lastBlock,sizeOfLastBlock));
mtx.lock();
downloadThreadNo++;
mtx.unlock();
if(lastBlock==noOfBlocks-1)
completed=true;
startBlock=lastBlock+1;
lastBlock = mini((startBlock+BLOCKS_PER_SOURCE-1),(noOfBlocks-1));
if(completed==true)
break;