Beispiel #1
0
        void ParseData(ref SocMsg msg, Int16 time)
        {
            int s   = 0;
            var buf = msg.link.RecvBuffer;
            int r   = msg.link.Remain;
            int e   = r;

            while (GetPart(buf, ref s, ref e))
            {
                int len = e - s;
                if (len > 4 & len < 1490)
                {
                    len = UnpackInt(buf, s, e);
                    msg.link.AddMsgPart(tmpBuffer, len, this, time);
                }
                s = e + 4;
                e = r;
            }
            if (s > 0)
            {
                int len = r - s;
                for (int i = 0; i < len; i++)
                {
                    buf[i] = buf[s];
                    s++;
                }
                msg.link.Remain = len;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 解压消息
        /// </summary>
        /// <param name="time">当前时间</param>
        internal void UnPack(Int16 time)
        {
            int c = queue.Count;

            for (int i = 0; i < c; i++)
            {
                SocMsg msg = queue.Dequeue();
                MergeData(ref msg);
                ParseData(ref msg, time);
                msg.dat.Release();
            }
        }
Beispiel #3
0
        void MergeData(ref SocMsg msg)
        {
            byte[] buf = msg.link.RecvBuffer;
            int    s   = msg.link.Remain;
            int    c   = msg.dat.DataCount;

            unsafe
            {
                byte *src = msg.dat.Addr;
                for (int i = 0; i < c; i++)
                {
                    buf[s] = src[i];
                    s++;
                }
            }
            msg.link.Remain = s;
        }
Beispiel #4
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="buf">缓存</param>
        /// <param name="len">数据长度</param>
        /// <param name="link">用户连接</param>
        public void ReciveMsg(byte[] buf, int len, KcpData link)
        {
            var tmp = recvBuffer.RegNew(len);

            tmp.DataCount = len;
            unsafe
            {
                byte *ptr = tmp.Addr;
                for (int i = 0; i < len; i++)
                {
                    ptr[i] = buf[i];
                }
            }
            SocMsg msg = new SocMsg();

            msg.link = link;
            msg.dat  = tmp;
            queue.Enqueue(msg);
        }