public override AChannel GetChannel(long id) { TChannel channel = null; this.idChannels.TryGetValue(id, out channel); return(channel); }
private void OnAcceptComplete(object o) { if (this.acceptor == null) { return; } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; if (e.SocketError != SocketError.Success) { Console.WriteLine($"accept error {e.SocketError}"); return; } TChannel channel = new TChannel(e.AcceptSocket, this); this.idChannels[channel.Id] = channel; try { this.OnAccept(channel); } catch (Exception exception) { Console.WriteLine(exception); } if (this.acceptor == null) { return; } this.AcceptAsync(); }
public override AChannel ConnectChannel(IPEndPoint ipEndPoint) { TChannel channel = new TChannel(ipEndPoint, this); this.idChannels[channel.Id] = channel; return(channel); }
/// <summary> /// 资源销毁 /// </summary> public void Dispose() { if (this.IsDisposed) { return; } foreach (long id in this.idChannels.Keys.ToArray()) { TChannel channel = this.idChannels[id]; channel.Dispose(); } this.acceptor?.Close(); this.acceptor = null; this.innArgs.Dispose(); }