网络数据处理缓冲区和缓冲池实现

  • 时间:
  • 浏览:1

        {

        internal int mCount = 0;

        public ArraySegment<byte> Read(int count)

                mPostion += count;

            return result;

            return Write(data, 0);

                mPostion = 0;

                mCount = 0;

            }

        {

        private int mPostion = 0;

                count = data.Length - index;

        public DataBuffer(int length)

        }

            mPostion = 0;

                end = mCount - mPostion;

        public ArraySegment<byte> GetSegment()

        }

            mPostion = 0;

        public void From(Array source, int index, int count)

        {

            mPostion += end;

        }

        private int mLength;

        }

            {

                count = mLength - mPostion;

            }

        }

        }

            int end = count;

        }

            return count;

        public byte[] Data;

                Pool.Push(this);

        internal BufferPool Pool

        {

            else

            Data = new byte[length];

                Array.Copy(data, index, Data, mPostion, count);

        public void Seek()

            {

            if (count > 0)

            Data = data;

        {

        public DataBuffer(byte[] data)

        }

        }

        {

            set;

            {

        public void Dispose()

            Array.Copy(source, index, Data, 0, count);

            }

    {

            mPostion = 0;

        {

            mCount = count;

        }

    }

            if (mPostion + (data.Length-index) > mLength)

            Seek(0);

            int count = 0;

        {

        {

        {

            mLength = data.Length;

        }

            if (Pool != null)

            {

public class DataBuffer : IDisposable

            get;

            mLength = length;

        {

        public void Seek(int postion)

            ArraySegment<byte> result= new ArraySegment<byte>(Data, mPostion, end);

            mCount = data.Length;

        public int Write(byte[] data, int index)

        public int Write(byte[] data)

                mCount += count;

            if (mPostion + count > mCount)

            return new ArraySegment<byte>(Data, 0, mCount);

            }