private TChannel Create(IPEndPoint ipEndPoint, long id) { TChannel channel = new TChannel(id, ipEndPoint, this); this.idChannels.Add(channel.Id, channel); return(channel); }
private void OnAcceptComplete(SocketError socketError, Socket acceptSocket) { if (this.acceptor == null) { return; } // 开始新的accept this.AcceptAsync(); if (socketError != SocketError.Success) { Log.Error($"accept error {socketError}"); return; } try { long id = this.CreateAcceptChannelId(0); TChannel channel = new TChannel(id, acceptSocket, this); this.idChannels.Add(channel.Id, channel); long channelId = channel.Id; this.OnAccept(channelId, channel.RemoteAddress); } catch (Exception exception) { Log.Error(exception); } }
private TChannel Get(long id) { TChannel channel = null; this.idChannels.TryGetValue(id, out channel); return(channel); }
public override void Update() { foreach (long channelId in this.NeedStartSend) { TChannel tChannel = this.Get(channelId); tChannel?.Update(); } this.NeedStartSend.Clear(); }
public override void Dispose() { this.acceptor?.Close(); this.acceptor = null; this.innArgs.Dispose(); ThreadSynchronizationContext = null; foreach (long id in this.idChannels.Keys.ToArray()) { TChannel channel = this.idChannels[id]; channel.Dispose(); } this.idChannels.Clear(); }
protected override void Send(long channelId, long actorId, MemoryStream stream) { try { TChannel aChannel = this.Get(channelId); if (aChannel == null) { this.OnError(channelId, ErrorCode.ERR_SendMessageNotFoundTChannel); return; } aChannel.Send(actorId, stream); } catch (Exception e) { Log.Error(e); } }