| 588 | } |
| 589 | |
| 590 | void 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 |
no test coverage detected