Exemplo n.º 1
0
        static void CopyToBuff(ref BlockInfo <byte> buff, ref KcpHead head, byte[] src)
        {
            int start = KcpHead.Size;

            if (buff.DataCount > 0)
            {
                int index = head.CurPart * FragmentSize;
                int len   = head.PartLen;
                int all   = buff.DataCount;
                unsafe
                {
                    byte *tar = buff.Addr;
                    for (int i = 0; i < len; i++)
                    {
                        if (index >= all)
                        {
                            break;
                        }
                        tar[index] = src[start];
                        index++;
                        start++;
                    }
                }
            }
        }
Exemplo n.º 2
0
 void AddNew(ref KcpHead head, byte[] dat, int index)
 {
     if (head.AllPart > 1)
     {
         unsafe
         {
             SetChecked(caches[index].states.Addr, head.CurPart);
         }
     }
     CopyToBuff(ref caches[index].buff, ref head, dat);
     caches[index].rcvLen = 1;
 }
Exemplo n.º 3
0
        void FillMsg(ref KcpHead head, byte[] dat, int index)
        {
            bool a;

            unsafe
            {
                a = SetChecked(caches[index].states.Addr, head.CurPart);
            }
            if (a)
            {
                CopyToBuff(ref caches[index].buff, ref head, dat);
                caches[index].rcvLen++;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 成功发送的消息回执,剔除掉缓存中的消息备份
        /// </summary>
        /// <param name="head">消息头</param>
        /// <param name="link">用户连接</param>
        public void Success(ref KcpHead head, KcpData link)
        {
            unsafe
            {
                fixed(byte *bp = &tmp2[0])
                {
                    KcpReturn *hp = (KcpReturn *)bp;

                    hp->Type    = EnvelopeType.Success;
                    hp->MsgID   = head.MsgID;
                    hp->CurPart = head.CurPart;
                    hp->Time    = head.Time;
                }
            }
            int c = PackInt(tmp2, KcpReturn.Size, tmpBuffer);

            kcpListener.soc.SendTo(tmpBuffer, c, SocketFlags.None, link.endpPoint);
        }