示例#1
0
 private void AddChannel(MoTChannel channel)
 {
     //加入到频道列表
     lock (_allChannels)
     {
         _allChannels.Add(channel);
     }
 }
示例#2
0
        private void RemoveChannel(MoTChannel channel)
        {
            channel.Dispose();

            //从频道列表里删除
            lock (_allChannels)
            {
                _allChannels.Remove(channel);
            }

            //信号减弱
            if (_maxAcceptedSemaphore != null)
            {
                _maxAcceptedSemaphore.Release();
            }
        }
示例#3
0
        private void ProcessConnected(object obj)
        {
            SocketAsyncEventArgs e = obj as SocketAsyncEventArgs;

            //如果失败
            if (e.SocketError != SocketError.Success)
            {
                MoLog.Log(ELogType.Error, "ProcessConnected error : {0}", e.SocketError);
                return;
            }

            //创建频道
            MoTChannel channel = new MoTChannel();

            channel.InitSocket(e.ConnectSocket);

            //加入到频道列表
            lock (_allChannels)
            {
                _allChannels.Add(channel);
            }
        }
示例#4
0
        /// <summary>
        /// 处理Accept请求
        /// </summary>
        private void ProcessAccept(object obj)
        {
            SocketAsyncEventArgs e = obj as SocketAsyncEventArgs;

            //如果失败
            if (e.SocketError != SocketError.Success)
            {
                MoLog.Log(ELogType.Error, "ProcessConnected error : {0}", e.SocketError);
                return;
            }

            //创建频道
            MoTChannel channel = new MoTChannel();

            channel.InitSocket(e.AcceptSocket);

            //添加频道
            AddChannel(channel);

            // 投递下一个接收请求
            StartAccept(e);
        }