private void AddChannel(MoTChannel channel) { //加入到频道列表 lock (_allChannels) { _allChannels.Add(channel); } }
private void RemoveChannel(MoTChannel channel) { channel.Dispose(); //从频道列表里删除 lock (_allChannels) { _allChannels.Remove(channel); } //信号减弱 if (_maxAcceptedSemaphore != null) { _maxAcceptedSemaphore.Release(); } }
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); } }
/// <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); }