public static MessageHandler Create(Type handlerType, NetChannel channel) { var handler = (MessageHandler)PopoObjectPool.Fetch(handlerType, channel); handler.Channel = channel; return(handler); }
public static T Create <T>(NetChannel channel) where T : MessageHandler { var type = typeof(T); var handler = (T)PopoObjectPool.Fetch(typeof(T), channel); return(handler); }
public override async Task AcceptAsync() { while (true) { var tcpClient = await tcpListener.AcceptTcpClientAsync(); var channel = (TcpChannel)PopoObjectPool.Fetch(typeof(TcpChannel), endPoint); channel.ChannelType = ChannelType.Server; channel.TcpClient = tcpClient; channel.OnError = OnChannelError; Channels.TryAdd(channel.ObjectId, channel); CreateMessageHandlers(channel); } }
public override async Task ConnectAsync() { var tcpClient = new TcpClient(); var channel = (TcpChannel)PopoObjectPool.Fetch(typeof(TcpChannel), endPoint); channel.ChannelType = ChannelType.Client; channel.TcpClient = tcpClient; channel.EndPoint = endPoint; if (await channel.StartConnecting()) { channel.OnError = OnChannelError; Channels.TryAdd(channel.ObjectId, channel); CreateMessageHandlers(channel); } }
public virtual void Close() { PopoObjectPool.Push(this); }