public static ByteBufferNode GetByteBufferNode(int dataSize = -1) { if (dataSize <= 0) { dataSize = NetByteArrayPool._cSmallBufferSize; } ByteBufferNode ret = null; lock (m_ByteNodePool) { LinkedListNode <ByteBufferNode> n = m_ByteNodePool.First; if (n != null) { m_ByteNodePool.Remove(n); ret = n.Value; } } if (ret != null) { ret._InitDataSize(dataSize); return(ret); } ret = new ByteBufferNode(dataSize); return(ret); }
public override void Dispose() { if (pSendData != null) { pSendData.Dispose(); pSendData = null; } AbstractPool <tReqSend> ._DestroyNode(this); }
public void SendCapnProto(CapnProtoMsg msg, int packetHandle) { ByteBufferNode node = NetByteArrayPool.GetByteBufferNode(); var buffer = node.GetBuffer(); System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer); msg.WriteToStream(stream); Send(buffer, packetHandle, (int)stream.Position); stream.Dispose(); node.Dispose(); }
public void Init(byte[] pData, int bufSize) { if ((pData != null) && (bufSize > 0)) { if (pSendData != null) { pSendData.Dispose(); } pSendData = NetByteArrayPool.GetByteBufferNode(bufSize); Buffer.BlockCopy(pData, 0, pSendData.GetBuffer(), 0, bufSize); } else { pSendData = null; } }
internal static void _DestroyBuffer(ByteBufferNode node) { if (node != null) { var n = node.LinkedListNode; if (n.List != m_ByteNodePool) { lock (m_ByteNodePool) { var list = n.List; if (list != m_ByteNodePool) { if (list != null) { list.Remove(n); } m_ByteNodePool.AddLast(n); } } } } }
public tReqSend() { uReqType = eReqType.eREQ_TYPE_SEND; pSendData = null; }