| 803 | } |
| 804 | |
| 805 | void TUdpHost::RecvCycle() { |
| 806 | for (;;) { |
| 807 | sockaddr_in6 fromAddress; |
| 808 | int rv = RecvBuf.GetBufSize(); |
| 809 | bool recvOk = s.RecvFrom(RecvBuf.GetDataPtr(), &rv, &fromAddress); |
| 810 | if (!recvOk) |
| 811 | break; |
| 812 | |
| 813 | NHPTimer::STime tCopy = CurrentT; |
| 814 | float deltaT = (float)NHPTimer::GetTimePassed(&tCopy); |
| 815 | deltaT = ClampVal(deltaT, 0.0f, UDP_TRANSFER_TIMEOUT / 3); |
| 816 | |
| 817 | //int fromIP = fromAddress.sin_addr.s_addr; |
| 818 | |
| 819 | TTransferKey k; |
| 820 | char* pktData = RecvBuf.GetDataPtr() + UDP_LOW_LEVEL_HEADER_SIZE; |
| 821 | GetUdpAddress(&k.Address, fromAddress); |
| 822 | k.Id = Read<int>(&pktData); |
| 823 | int transferId = k.Id; |
| 824 | int cmd = Read<char>(&pktData); |
| 825 | Y_ASSERT(cmd == (int)*(RecvBuf.GetDataPtr() + CMD_POS)); |
| 826 | switch (cmd) { |
| 827 | case DATA: |
| 828 | case DATA_SMALL: |
| 829 | case DATA_SHMEM: |
| 830 | case DATA_SMALL_SHMEM: { |
| 831 | int attempt = Read<int>(&pktData); |
| 832 | int packetId = Read<int>(&pktData); |
| 833 | //printf("data packet %d (trans ID = %d)\n", packetId, transferId); |
| 834 | TUdpCompleteInXferHash::iterator itCompl = RecvCompleted.find(k); |
| 835 | if (itCompl != RecvCompleted.end()) { |
| 836 | Y_ASSERT(RecvQueue.find(k) == RecvQueue.end()); |
| 837 | const TUdpCompleteInTransfer& complete = itCompl->second; |
| 838 | bool sendAckComplete = true; |
| 839 | if (packetId == 0) { |
| 840 | // check packet GUID |
| 841 | char* tmpPktData = pktData; |
| 842 | TGUID packetGuid; |
| 843 | packetGuid = Read<TGUID>(&tmpPktData); |
| 844 | if (packetGuid != complete.PacketGuid) { |
| 845 | // we are receiving new data with the same transferId |
| 846 | // in this case we have to flush all the information about previous transfer |
| 847 | // and start over |
| 848 | //printf("same transferId for a different packet\n"); |
| 849 | RecvCompleted.erase(itCompl); |
| 850 | sendAckComplete = false; |
| 851 | } |
| 852 | } |
| 853 | if (sendAckComplete) { |
| 854 | AckComplete(s, fromAddress, transferId, complete.PacketGuid, packetId); |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | TUdpInXferHash::iterator rq = RecvQueue.find(k); |
| 859 | if (rq == RecvQueue.end()) { |
| 860 | //printf("new input transfer\n"); |
| 861 | TUdpInTransfer& res = RecvQueue[k]; |
| 862 | res.ToAddress = fromAddress; |
nothing calls this directly
no test coverage detected