本文整理汇总了C++中Download::getSecondsLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ Download::getSecondsLeft方法的具体用法?C++ Download::getSecondsLeft怎么用?C++ Download::getSecondsLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Download
的用法示例。
在下文中一共展示了Download::getSecondsLeft方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNextSegment
//.........这里部分代码省略.........
targetSize = Util::roundDown(targetSize, blockSize);
} else {
targetSize = blockSize;
}
int64_t start = 0;
int64_t curSize = targetSize;
while(start < getSize()) {
int64_t end = std::min(getSize(), start + curSize);
Segment block(start, end - start);
bool overlaps = false;
for(SegmentConstIter i = done.begin(); !overlaps && i != done.end(); ++i) {
if(curSize <= blockSize) {
int64_t dstart = i->getStart();
int64_t dend = i->getEnd();
// We accept partial overlaps, only consider the block done if it is fully consumed by the done block
if(dstart <= start && dend >= end) {
overlaps = true;
}
} else {
overlaps = block.overlaps(*i);
}
}
for(auto i = downloads.begin(); !overlaps && i != downloads.end(); ++i) {
overlaps = block.overlaps((*i)->getSegment());
}
if(!overlaps) {
if(partialSource) {
// store all chunks we could need
for(vector<int64_t>::const_iterator j = posArray.begin(); j < posArray.end(); j += 2){
if( (*j <= start && start < *(j+1)) || (start <= *j && *j < end) ) {
int64_t b = max(start, *j);
int64_t e = min(end, *(j+1));
// segment must be blockSize aligned
dcassert(b % blockSize == 0);
dcassert(e % blockSize == 0 || e == getSize());
neededParts.push_back(Segment(b, e - b));
}
}
} else {
return block;
}
}
if(overlaps && (curSize > blockSize)) {
curSize -= blockSize;
} else {
start = end;
curSize = targetSize;
}
}
if(!neededParts.empty()) {
// select random chunk for download
dcdebug("Found chunks: %d\n", neededParts.size());
Segment& selected = neededParts[Util::rand(0, neededParts.size())];
selected.setSize(std::min(selected.getSize(), targetSize)); // request only wanted size
return selected;
}
if(partialSource == NULL && BOOLSETTING(OVERLAP_CHUNKS) && lastSpeed > 0) {
// overlap slow running chunk
for(auto i = downloads.begin(); i != downloads.end(); ++i) {
Download* d = *i;
// current chunk mustn't be already overlapped
if(d->getOverlapped())
continue;
// current chunk must be running at least for 4 seconds
if(d->getStart() == 0 || GET_TICK() - d->getStart() < 4000)
continue;
// current chunk mustn't be finished in next 20 seconds
if(d->getSecondsLeft() < 20)
continue;
// overlap current chunk at last block boundary
int64_t pos = d->getPos() - (d->getPos() % blockSize);
int64_t size = d->getSize() - pos;
// new user should finish this chunk more than 2x faster
int64_t newChunkLeft = size / lastSpeed;
if(2 * newChunkLeft < d->getSecondsLeft()) {
dcdebug("Overlapping... old user: %I64d s, new user: %I64d s\n", d->getSecondsLeft(), newChunkLeft);
return Segment(d->getStartPos() + pos, size, true);
}
}
}
return Segment(0, 0);
}