MCPcopy Create free account
hub / github.com/amule-project/amule / SendBlockRequests

Method SendBlockRequests

src/DownloadClient.cpp:590–833  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588}
589
590void CUpDownClient::SendBlockRequests()
591{
592 uint64 current_time = ::GetTickCount64();
593 if (GetVBTTags()) {
594
595 // Ask new blocks only when all completed
596 if (!m_PendingBlocks_list.empty()) {
597 return;
598 }
599
600 if ((m_dwLastBlockReceived + SEC2MS(5)) > current_time) {
601 // We received last block in less than 5 secs? Let's request faster.
602 m_MaxBlockRequests = m_MaxBlockRequests << 1;
603 if ( m_MaxBlockRequests > 0x20) {
604 m_MaxBlockRequests = 0x20;
605 }
606 } else {
607 m_MaxBlockRequests = m_MaxBlockRequests >> 1;
608 if ( m_MaxBlockRequests < STANDARD_BLOCKS_REQUEST) {
609 m_MaxBlockRequests = STANDARD_BLOCKS_REQUEST;
610 }
611 }
612 }
613
614 m_dwLastBlockReceived = current_time;
615
616 if (!m_reqfile) {
617 return;
618 }
619
620 if (m_DownloadBlocks_list.empty()) {
621 // Barry - instead of getting 3, just get how many is needed
622 uint16 count = m_MaxBlockRequests - m_PendingBlocks_list.size();
623 std::vector<Requested_Block_Struct*> toadd;
624 if (m_reqfile->GetNextRequestedBlock(this, toadd, count)) {
625 for (int i = 0; i != count; i++) {
626 m_DownloadBlocks_list.push_back(toadd[i]);
627 }
628 }
629 }
630
631 // Barry - Why are unfinished blocks requested again, not just new ones?
632
633 while (m_PendingBlocks_list.size() < m_MaxBlockRequests && !m_DownloadBlocks_list.empty()) {
634 Pending_Block_Struct* pblock = new Pending_Block_Struct;
635 pblock->block = m_DownloadBlocks_list.front();
636 pblock->zStream = NULL;
637 pblock->totalUnzipped = 0;
638 pblock->fZStreamError = 0;
639 pblock->fRecovered = 0;
640 pblock->fQueued = 0; // Block sits in our local queue, not yet asked over the wire.
641 m_PendingBlocks_list.push_back(pblock);
642 m_DownloadBlocks_list.pop_front();
643 }
644
645
646 if (m_PendingBlocks_list.empty()) {
647

Callers 1

ProcessPacketMethod · 0.80

Calls 15

GetTickCount64Function · 0.85
CTagVarIntClass · 0.85
CFormatClass · 0.85
GetNextRequestedBlockMethod · 0.80
GetSentCancelTransferMethod · 0.80
GetPacketSizeMethod · 0.80
SetSentCancelTransferMethod · 0.80
SetDownloadStateMethod · 0.80
WriteUInt8Method · 0.80
WriteTagToFileMethod · 0.80

Tested by

no test coverage detected