Esempio n. 1
0
        /// <summary>
        /// 如果外部能够提供缓冲区则使用外部缓冲区,否则new byte[]
        /// </summary>
        /// <param name="needSize"></param>
        /// <returns></returns>
        internal protected BufferOwner CreateBuffer(int needSize)
        {
            var res = rentable?.RentBuffer(needSize);

            if (res == null)
            {
                return(new KcpInnerBuffer(needSize));
            }
            else
            {
                if (res.Memory.Length < needSize)
                {
                    throw new ArgumentException($"{nameof(rentable.RentBuffer)} 指定的委托不符合标准,返回的" +
                                                $"BufferOwner.Memory.Length 小于 {nameof(needSize)}");
                }
            }

            return(res);
        }
Esempio n. 2
0
 /// <summary>
 /// 如果外部能够提供缓冲区则使用外部缓冲区,否则new byte[]
 /// </summary>
 /// <param name="needSize"></param>
 /// <returns></returns>
 internal protected BufferOwner CreateBuffer(int needSize)
 {
     return(rentable?.RentBuffer(needSize));
 }