Example #1
0
        /// <summary>
        /// 
        /// </summary>
        public void Execute(NetState netState)
        {
            var sw = Stopwatch.StartNew();

            // 只有在客户端未断开连接时才执行业务回调
            if (netState.Running)
                PacketHandler.OnReceive(netState, PacketReader);

            sw.Stop();

            PacketHandler.CallTimes++;
            PacketHandler.ElapsedTicks += sw.Elapsed.Ticks;
        }
Example #2
0
 /// <summary>
 /// 再次处理没处理完全的数据(仅调用一次)
 /// </summary>
 /// <param name="netState"></param>
 private void OnceAgainReceive( NetState netState )
 {
     if ( netState.Running )
     {
         if ( netState.ReceiveBuffer.Length > 0 )
             OnReceive( netState );
     }
 }
Example #3
0
        /// <summary>
        /// 检查是否有新的客户端接过来
        /// </summary>
        private void CheckListener()
        {
            for ( int iIndex = 0; iIndex < m_Listeners.Length; iIndex++ )
            {
                Listener listener = m_Listeners[iIndex];

                // 获取连接的客户端
                ClientSocketManager[] acceptedManager = listener.Slice();

                for ( int iIndex2 = 0; iIndex2 < acceptedManager.Length; iIndex2++ )
                {
                    ClientSocketManager clientSocketManager = acceptedManager[iIndex2];
                    if ( clientSocketManager == null )
                        continue;

                    // 把连接过来的客户端放置入NetState中,当前的实例会保存在NetState.Instances中
                    NetState netState = new NetState( clientSocketManager, this );

                    OnNetStateInit( netState );

                    netState.Start();
                }
            }
        }
Example #4
0
        /// <summary>
        /// 检查是否有新的客户端接出来
        /// </summary>
        private void CheckConnecter()
        {
            for ( int iIndex = 0; iIndex < m_Connecters.Length; iIndex++ )
            {
                Connecter connecter = m_Connecters[iIndex];

                // 检查是否已经处理过
                if ( connecter.IsNeedSlice == false )
                    continue;

                // 获取连接出去的客户端
                ClientSocketManager clientSocketManager = connecter.Slice();
                if ( clientSocketManager != null )
                {
                    // 把连接出来的客户端放置入NetState中,当前的实例会保存在NetState.Instances中
                    NetState netState = new NetState( clientSocketManager, this );

                    OnNetStateInit( netState );

                    netState.Start();
                }
            }
        }
Example #5
0
        /// <summary>
        /// 网络上面有数据过来
        /// </summary>
        /// <param name="netState"></param>
        internal void OnReceive( NetState netState )
        {
            // 表示当前已加入在处理列表中(减少处理列表的长度)
            if ( netState.InProcessQueue() == false )
                return;

            m_NetStateQueue.Enqueue( netState );

            Debug.Assert( m_World != null, "MessagePump.OnReceive(...) - m_World == null error!" );

            // 有数据过来需要发送全局信号处理数据包
            m_World.SendWorldSignal();
        }
Example #6
0
 /// <summary>
 /// 处理接收到的数据
 /// </summary>
 /// <param name="netState"></param>
 internal void OnProcessReceive( NetState netState )
 {
     EventHandler<NetStateEventArgs> tempEventArgs = m_EventProcessReceive;
     if ( tempEventArgs != null )
     {
         NetStateEventArgs netStateEventArgs = new NetStateEventArgs( netState );
         tempEventArgs( this, netStateEventArgs );
     }
 }
Example #7
0
 /// <summary>
 /// 创建了新的NetState需要的初始化
 /// </summary>
 internal void OnNetStateInit( NetState newNetState )
 {
     EventHandler<NetStateInitEventArgs> tempEventArgs = m_EventNetStateCreate;
     if ( tempEventArgs != null )
     {
         NetStateInitEventArgs netStateInitEventArgs = new NetStateInitEventArgs( newNetState );
         tempEventArgs( this, netStateInitEventArgs );
     }
 }
Example #8
0
 /// <summary>
 /// ��ӿͻ��˵�����
 /// </summary>
 internal void InternalAddNetState( long netStateId, NetState netState )
 {
     m_NetStates.Add( netStateId, netState );
 }