Example #1
0
        /// <summary>
        ///
        /// </summary>
        internal ClientSocketManager(Connecter connecter, ConnectHandler connectHandler, ReceiveQueue receiveBuffer)
        {
            if (connecter == null)
            {
                throw new ArgumentNullException("ClientSocketHandler.ClientSocketManager(...) - listener == null error!");
            }

            if (connectHandler == null)
            {
                throw new ArgumentNullException("ClientSocketHandler.ClientSocketManager(...) - serviceHandle == null error!");
            }

            if (receiveBuffer == null)
            {
                throw new ArgumentNullException("receiveBuffer", "ClientSocketHandler.ClientSocketManager(...) - receiveBuffer == null error!");
            }

            m_Connecter     = connecter;
            m_ConnectHandle = connectHandler;
            m_ReceiveBuffer = receiveBuffer;
            {
                // 清空数据
                m_ReceiveBuffer.Clear();
            }

            // 初始化数据 表示还没调用过Free(...)函数
            m_LockFree.SetValid();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        internal ClientSocketManager(Listener listener, ServiceHandler serviceHandler, ReceiveQueue receiveBuffer)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener", "ClientSocketHandler.ClientSocketManager(...) - listener == null error!");
            }

            if (serviceHandler == null)
            {
                throw new ArgumentNullException("serviceHandler", "ClientSocketHandler.ClientSocketManager(...) - serviceHandle == null error!");
            }

            if (receiveBuffer == null)
            {
                throw new ArgumentNullException("receiveBuffer", "ClientSocketHandler.ClientSocketManager(...) - receiveBuffer == null error!");
            }

            m_Listener      = listener;
            m_ServiceHandle = serviceHandler;
            m_ReceiveBuffer = receiveBuffer;
            {
                // 清空数据
                m_ReceiveBuffer.Clear();
            }

            m_ServiceHandle.EventProcessData += OnListenerProcessMessageBlock;
            m_ServiceHandle.EventDisconnect  += OnListenerDisconnect;

            // 初始化数据 表示还没调用过Free(...)函数
            m_LockFree.SetValid();
        }
Example #3
0
        /// <summary>
        /// 内部断开(调用后此类不得再进行任何处理,因为已返回进内存池)
        /// </summary>
        internal void Free()
        {
            // 检测有没有调用过Free(...)函数
            if (m_LockFree.SetInvalid() == false)
            {
                return;
            }

            // 先调用Clear(...)
            m_ReceiveBuffer.Clear();

            // 取消回调
            if (m_ServiceHandle != null)
            {
                m_ServiceHandle.EventProcessData -= OnListenerProcessMessageBlock;
                m_ServiceHandle.EventDisconnect  -= OnListenerDisconnect;
            }

            // 如果是Listener的则需要释放入内存池中...
            if (m_Listener != null)
            {
                m_Listener.Free(m_ReceiveBuffer);
            }
        }