Esempio n. 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;
            }
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 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;
        }
Esempio n. 4
0
        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);
        }