示例#1
0
        public ByteBuf GetDefault()
        {
            int              size;
            IntPtr           dataPtr = GetDefaultDataIntPtr(out size);
            UnmanagedByteBuf byteBuf = (UnmanagedByteBuf)WrapDefault(dataPtr, 0 /* filledSize */);

            return(byteBuf);
        }
示例#2
0
        private UnmanagedByteBuf GetByteBufCore()
        {
            ByteBuf byteBuf;

            if (!_byteBufs.TryDequeue(out byteBuf))
            {
                byteBuf = new UnmanagedByteBuf(this);
            }

            return((UnmanagedByteBuf)byteBuf);
        }
示例#3
0
        public IUnmanagedByteBuf WrapDefault(IntPtr dataPtr, int filledSize)
        {
            IntPtr memSegPtr = MemorySegment.GetMemSegPtrByDataPtr(dataPtr);

            UnmanagedByteBuf byteBuf = GetByteBufCore();

            byteBuf.Attach(memSegPtr);
            byteBuf.SetWrite(filledSize);

            return(byteBuf);
        }
示例#4
0
        public override void Append(ByteBuf byteBuf)
        {
            UnmanagedByteBuf unmanagedByteBuf = (UnmanagedByteBuf)byteBuf;

            IntPtr appendixCurrentMemSegPtr = unmanagedByteBuf._memSegPtr;
            IntPtr appendixLastMemSegPtr    = unmanagedByteBuf._lastMemSegPtr;

            MemorySegment.SetNext(_lastMemSegPtr, appendixCurrentMemSegPtr);
            MemorySegment.SetPrev(appendixCurrentMemSegPtr, _lastMemSegPtr);

            _lastMemSegPtr = appendixLastMemSegPtr;
            _globalWrited += unmanagedByteBuf._globalWrited;

            // Т.к. мы все забрали у присоединяемого буфера, то буфер как обертка больше не нужен.
            // Освобождаем его.
            unmanagedByteBuf.ReleaseCore();
        }
示例#5
0
 internal void Release(UnmanagedByteBuf unmanagedByteBuf)
 {
     _byteBufs.Enqueue(unmanagedByteBuf);
 }