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

            AbstractPool <tReqSend> ._DestroyNode(this);
        }
Esempio n. 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();
        }
Esempio n. 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;
     }
 }
Esempio n. 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);
                 }
             }
         }
     }
 }
Esempio n. 6
0
 public tReqSend()
 {
     uReqType  = eReqType.eREQ_TYPE_SEND;
     pSendData = null;
 }