示例#1
0
        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);
        }
示例#2
0
        public override void Dispose()
        {
            if (pSendData != null)
            {
                pSendData.Dispose();
                pSendData = null;
            }

            AbstractPool <tReqSend> ._DestroyNode(this);
        }
示例#3
0
        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();
        }
示例#4
0
 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;
     }
 }
示例#5
0
 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);
                 }
             }
         }
     }
 }
示例#6
0
 public tReqSend()
 {
     uReqType  = eReqType.eREQ_TYPE_SEND;
     pSendData = null;
 }