| 602 | } |
| 603 | |
| 604 | void DoSends() { |
| 605 | { |
| 606 | // cancelling requests |
| 607 | TGUID reqGuid; |
| 608 | while (CancelReqList_.Dequeue(&reqGuid)) { |
| 609 | TOutRequestHash::iterator i = OutRequests_.find(reqGuid); |
| 610 | if (i == OutRequests_.end()) { |
| 611 | AnticipateCancels_.insert(reqGuid); |
| 612 | continue; // cancelling non existing request is ok |
| 613 | } |
| 614 | TOutRequestState& s = i->second; |
| 615 | if (s.State == TOutRequestState::S_SENDING) { |
| 616 | // we are in trouble - have not sent request and we already have to cancel it, wait send |
| 617 | s.State = TOutRequestState::S_CANCEL_AFTER_SENDING; |
| 618 | s.EventsCollector->AddCancel(i->first); |
| 619 | } else { |
| 620 | DoSendCancel(s.Address, reqGuid); |
| 621 | FinishRequest(i, TUdpHttpResponse::CANCELED, nullptr, "request canceled: notify requested side"); |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | { |
| 626 | // sending replies |
| 627 | for (TSendResponse* rd = nullptr; SendRespList_.Dequeue(&rd); delete rd) { |
| 628 | TInRequestHash::iterator i = InRequests_.find(rd->ReqGuid); |
| 629 | if (i == InRequests_.end()) { |
| 630 | Y_ASSERT(0); |
| 631 | continue; |
| 632 | } |
| 633 | TInRequestState& s = i->second; |
| 634 | if (s.State == TInRequestState::S_CANCELED) { |
| 635 | // need not send response for the canceled request |
| 636 | InRequests_.erase(i); |
| 637 | continue; |
| 638 | } |
| 639 | |
| 640 | Y_ASSERT(s.State == TInRequestState::S_WAITING); |
| 641 | s.State = TInRequestState::S_RESPONSE_SENDING; |
| 642 | |
| 643 | TAutoPtr<TRopeDataPacket> ms = new TRopeDataPacket; |
| 644 | ui32 crc32 = 0; |
| 645 | int dataSize = rd->Data.ysize(); |
| 646 | if (rd->Data.size() > MIN_SHARED_MEM_PACKET && IsLocal(s.Address)) { |
| 647 | TIntrusivePtr<TSharedMemory> shm = new TSharedMemory; |
| 648 | if (shm->Create(dataSize)) { |
| 649 | ms->Write((char)PKT_LOCAL_RESPONSE); |
| 650 | ms->Write(rd->ReqGuid); |
| 651 | memcpy(shm->GetPtr(), &rd->Data[0], dataSize); |
| 652 | TVector<char> empty; |
| 653 | rd->Data.swap(empty); |
| 654 | ms->AttachSharedData(shm); |
| 655 | crc32 = CalcChecksum(ms->GetChain()); |
| 656 | } |
| 657 | } |
| 658 | if (ms->GetSharedData() == nullptr) { |
| 659 | ms->Write((char)PKT_RESPONSE); |
| 660 | ms->Write(rd->ReqGuid); |
| 661 |
nothing calls this directly
no test coverage detected