示例#1
0
        public void OnReceive(int id, byte[] buf, int offset, int size)
        {
            var tmpOffset = offset;

            if (ReliableAckData.TryUnpack(buf, ref offset, out var ack))
            {
                Get(id)?.ReceiveAck(ack);
            }
            offset = tmpOffset;
            if (ReliableData.TryUnpack(buf, ref offset, out var data))
            {
                Get(id)?.Enqueue(data);
            }
        }
示例#2
0
 public void Send(List <Fragment> input)
 {
     foreach (var fragment in input)
     {
         var data = new ReliableData(m_ChannelId, ++m_SendSequence, fragment);
         if (m_AckWaitList.Count < m_Config.MaxWindowSize)
         {
             m_AckWaitList.Add(data);
             Send(data);
         }
         else
         {
             m_SendWaitList.Enqueue(data);
         }
     }
 }
示例#3
0
        public static bool TryUnpack(byte[] buf, ref int offset, out ReliableData data)
        {
            var channel = BinaryUtil.ReadShort(buf, ref offset);

            if ((byte)Type != buf[offset++])
            {
                data = default;
                return(false);
            }
            var sequence        = BinaryUtil.ReadShort(buf, ref offset);
            var receiveSequence = BinaryUtil.ReadShort(buf, ref offset);
            var payload         = FragmentPool.Get();

            payload.Read(buf, ref offset);
            data = new ReliableData(channel, sequence, receiveSequence, payload);
            return(true);
        }