| 611 | } |
| 612 | } |
| 613 | void SendPingsIfNeeded() { |
| 614 | NHPTimer::STime tChk = PingsSendT; |
| 615 | float deltaT = (float)NHPTimer::GetTimePassed(&tChk); |
| 616 | if (deltaT < 0.05) { |
| 617 | return; |
| 618 | } |
| 619 | PingsSendT = tChk; |
| 620 | deltaT = ClampVal(deltaT, 0.0f, HTTP_TIMEOUT / 3); |
| 621 | |
| 622 | { |
| 623 | for (TOutRequestHash::iterator i = OutRequests.begin(); i != OutRequests.end();) { |
| 624 | TOutRequestHash::iterator curIt = i++; |
| 625 | TOutRequestState& s = curIt->second; |
| 626 | const TGUID& guid = curIt->first; |
| 627 | switch (s.State) { |
| 628 | case TOutRequestState::S_WAITING: |
| 629 | s.TimePassed += deltaT; |
| 630 | if (s.TimePassed > HTTP_TIMEOUT) { |
| 631 | TAutoPtr<TRopeDataPacket> ms = new TRopeDataPacket; |
| 632 | ms->Write((char)PKT_PING); |
| 633 | ms->Write(guid); |
| 634 | int transId = SendWithHighPriority(s.Address, ms.Release()); |
| 635 | TransferHash[transId] = TTransferPurpose(DIR_OUT, guid); |
| 636 | s.State = TOutRequestState::S_WAITING_PING_SENDING; |
| 637 | //printf("OutReq %s SendPingsIfNeeded() S_WAITING -> S_WAITING_PING_SENDING\n", GetGuidAsString(guid).c_str()); |
| 638 | s.PingTransferId = transId; |
| 639 | } |
| 640 | break; |
| 641 | case TOutRequestState::S_WAITING_PING_SENT: |
| 642 | s.TimePassed += deltaT; |
| 643 | if (s.TimePassed > HTTP_TIMEOUT) { |
| 644 | //printf("OutReq %s SendPingsIfNeeded() S_WAITING_PING_SENT -> failed\n", GetGuidAsString(guid).c_str()); |
| 645 | FinishRequest(curIt, TUdpHttpResponse::FAILED, nullptr, "request failed: http timeout in state S_WAITING_PING_SENT"); |
| 646 | } |
| 647 | break; |
| 648 | default: |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | void Step() { |
| 655 | { |
| 656 | TGuard<TSpinLock> lock(cs); |
nothing calls this directly
no test coverage detected