本文整理汇总了C++中Download::getStartPos方法的典型用法代码示例。如果您正苦于以下问题:C++ Download::getStartPos方法的具体用法?C++ Download::getStartPos怎么用?C++ Download::getStartPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Download
的用法示例。
在下文中一共展示了Download::getStartPos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkDownloads
void DownloadManager::checkDownloads(UserConnection* aConn) {
dcassert(aConn->getDownload() == NULL);
QueueItem::Priority prio = QueueManager::getInstance()->hasDownload(aConn->getUser());
if(!startDownload(prio)) {
removeConnection(aConn);
return;
}
Download* d = QueueManager::getInstance()->getDownload(*aConn, aConn->isSet(UserConnection::FLAG_SUPPORTS_TTHL));
if(!d) {
Lock l(cs);
aConn->setState(UserConnection::STATE_IDLE);
idlers.push_back(aConn);
return;
}
aConn->setState(UserConnection::STATE_SND);
if(aConn->isSet(UserConnection::FLAG_SUPPORTS_XML_BZLIST) && d->getType() == Transfer::TYPE_FULL_LIST) {
d->setFlag(Download::FLAG_XML_BZ_LIST);
}
{
Lock l(cs);
downloads.push_back(d);
}
fire(DownloadManagerListener::Requesting(), d);
dcdebug("Requesting " I64_FMT "/" I64_FMT "\n", static_cast<long long int>(d->getStartPos()), static_cast<long long int>(d->getSize()));
aConn->send(d->getCommand(aConn->isSet(UserConnection::FLAG_SUPPORTS_ZLIB_GET)));
}
示例2: 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);
}
示例3: startData
void DownloadManager::startData(UserConnection* aSource, int64_t start, int64_t bytes, bool z) {
Download* d = aSource->getDownload();
dcassert(d != NULL);
dcdebug("Preparing " I64_FMT ":" I64_FMT ", " I64_FMT ":" I64_FMT"\n",
static_cast<long long int>(d->getStartPos()), static_cast<long long int>(start),
static_cast<long long int>(d->getSize()), static_cast<long long int>(bytes));
if(d->getSize() == -1) {
if(bytes >= 0) {
d->setSize(bytes);
} else {
failDownload(aSource, _("Invalid size"));
return;
}
} else if(d->getSize() != bytes || d->getStartPos() != start) {
// This is not what we requested...
failDownload(aSource, _("Response does not match request"));
return;
}
try {
QueueManager::getInstance()->setFile(d);
} catch(const FileException& e) {
failDownload(aSource, str(F_("Could not open target file: %1%") % e.getError()));
return;
} catch(const Exception& e) {
failDownload(aSource, e.getError());
return;
}
if((d->getType() == Transfer::TYPE_FILE || d->getType() == Transfer::TYPE_FULL_LIST) && SETTING(BUFFER_SIZE) > 0 ) {
d->setFile(new BufferedOutputStream<true>(d->getFile()));
}
if(d->getType() == Transfer::TYPE_FILE) {
typedef MerkleCheckOutputStream<TigerTree, true> MerkleStream;
d->setFile(new MerkleStream(d->getTigerTree(), d->getFile(), d->getStartPos()));
d->setFlag(Download::FLAG_TTH_CHECK);
}
// Check that we don't get too many bytes
d->setFile(new LimitedOutputStream<true>(d->getFile(), bytes));
if(z) {
d->setFlag(Download::FLAG_ZDOWNLOAD);
d->setFile(new FilteredOutputStream<UnZFilter, true>(d->getFile()));
}
d->setStart(GET_TICK());
d->tick();
aSource->setState(UserConnection::STATE_RUNNING);
fire(DownloadManagerListener::Starting(), d);
if(d->getPos() == d->getSize()) {
try {
// Already finished? A zero-byte file list could cause this...
endData(aSource);
} catch(const Exception& e) {
failDownload(aSource, e.getError());
}
} else {
aSource->setDataMode();
}
}