Example #1
0
        /// <summary>
        /// 从缓冲池里分配一个消息包
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public static PacketReader AcquireContent(DogBuffer buffer)
        {
            var ret = s_pool.AcquireContent();

            ret.SetBuffer(buffer);
            return(ret);
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="buffer"></param>
 public void SetBuffer(DogBuffer buffer)
 {
     m_Data   = buffer.Bytes;
     m_Size   = buffer.Length;
     m_Index  = ReceiveQueue.PacketLengthSize + 2;   // 包头的长度和消息码长度
     m_buffer = buffer;
 }
Example #3
0
 /// <summary>
 /// 数据包写入器
 /// </summary>
 /// <param name="codeId">消息报的id</param>
 internal PacketWriter(ushort codeId)
 {
     buffer = DogBuffer.GetFromPool32K();
     //  先预留2位用于存放消息id
     buffer.Length = ReceiveQueue.PacketLengthSize;
     Write(codeId);
 }
Example #4
0
 /// <summary>
 /// 释放资源
 /// </summary>
 void Dispose()
 {
     if (m_buffer != null)
     {
         var t = m_buffer;
         m_buffer = null;
         t.Release();
     }
 }
Example #5
0
 internal static void ReleaseToPool(DogBuffer bufff)
 {
     bufff.Length = 0;
     if (bufff.BuffSizeType == DogBufferType._4K)
     {
         s_pools.ReleaseContent(bufff);
     }
     else if (bufff.BuffSizeType == DogBufferType._32K)
     {
         s_pools32K.ReleaseContent(bufff as DogBuffer32K);
     }
 }
Example #6
0
        /// <summary>
        /// 设置网络消息码
        /// </summary>
        /// <param name="codeId"></param>
        public void SetNetCode(ushort codeId)
        {
            if (buffer != null)
            {
                buffer.Release();
            }

            buffer = DogBuffer.GetFromPool32K();
            //  先预留2位用于存放消息id
            buffer.Length = ReceiveQueue.PacketLengthSize;
            Write(codeId);
        }
        /// <summary>
        /// 重新异步开始接受数据
        /// </summary>
        internal void SyncRecvData()
        {
            if (isClose || Socket == null || !Socket.Connected)
            {
                return;
            }

#if !UNITY_IPHONE
            lock (Socket)
#endif
            {
                var buff = DogBuffer.GetFromPool32K();
                RecvBuffer = buff;
                ReceiveEventArgs.SetBuffer(RecvBuffer.Bytes, 0, RecvBuffer.Bytes.Length);
                Socket.ReceiveAsync(ReceiveEventArgs);
            }
        }
        /// <summary>
        /// 向客户端发送数据
        /// </summary>
        /// <param name="buff"></param>
        public void SendPackage(DogBuffer buff)
        {
            if (Socket == null || !Socket.Connected)
            {
                return;
            }

            buff.Use();

#if !UNITY_IPHONE
            lock (m_PendingBuffer)
#endif
            {
                m_PendingBuffer.Enqueue(buff);
            }

            PeekSend();
        }
Example #9
0
 internal static void ReleaseToPool(DogBuffer bufff)
 {
     bufff.Length = 0;
     if (bufff.BuffSizeType == DogBufferType._4K)
         s_pools.ReleaseContent(bufff);
     else if (bufff.BuffSizeType == DogBufferType._32K)
         s_pools32K.ReleaseContent(bufff as DogBuffer32K);
 }