示例#1
0
 public static void Despawn(NetChannel obj)
 {
     if (obj == null)
     {
         return;
     }
     if (!m_channel_pools.Contains(obj))
     {
         m_channel_pools.Add(obj);
     }
 }
        private void OnAcceptConnect(long conn_idx)
        {
            lock (ThreadScheduler.Instance.LogicLock)
            {
                m_channel = NetChannelPools.Spawn();
                m_channel.Setup(this, m_conn_idx);

                if (OnConnected != null)
                {
                    OnConnected(m_channel.conn_idx);
                }
            }
        }
 /// <summary>
 /// 关闭链接:底层通知
 /// </summary>
 private void HanldeCloseConnect()
 {
     if (m_channel != null)
     {
         m_channel.Destroy();
         NetChannelPools.Despawn(m_channel);
         m_channel = null;
     }
     if (OnClose != null)
     {
         OnClose(conn_idx);
         OnClose = null;
     }
 }
示例#4
0
        private void OnAcceptConnect(long conn_idx)
        {
            lock (ThreadScheduler.Instance.LogicLock)
            {
                NetChannel channel = NetChannelPools.Spawn();
                channel.Setup(this, conn_idx);
                m_channels.Add(channel.conn_idx, channel);

                if (OnAccept != null)
                {
                    OnAccept(conn_idx);
                }
            }
        }
 public override void Destroy()
 {
     if (m_socket != null)
     {//socket只有外部调用时才主动关闭,否则底层会先自己关闭
         m_socket.Close();
         m_socket = null;
     }
     if (m_channel != null)
     {
         m_channel.Destroy();
         NetChannelPools.Despawn(m_channel);
         m_channel = null;
     }
     base.Destroy();
 }
示例#6
0
        public static NetChannel Spawn()
        {
            NetChannel obj = null;

            if (m_channel_pools.Count > 0)
            {
                obj = m_channel_pools[m_channel_pools.Count - 1];
                m_channel_pools.RemoveAt(m_channel_pools.Count - 1);
                return(obj);
            }
            else
            {
                ++m_total_new_count;
                obj = new NetChannel();
                return(obj);
            }
        }