public MultiplexingSocketClientProtocol(IMultiplexingSocketProtocol <TInbound, TOutbound> innerProtocol, IMessageIdGenerator idGenerator) { this.innerProtocol = innerProtocol ?? throw new ArgumentNullException(nameof(innerProtocol)); this.idGenerator = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator)); this.pendings = new ConcurrentDictionary <MessageId, PendingResponse <TInbound> >(); this.sourcePool = new ObjectPool <PooledValueTaskSource <TInbound> >(() => { return(new PooledValueTaskSource <TInbound>()); }, 100); this.ScheduleRead(); }
static async Task ProcessProtocol(IMultiplexingSocketProtocol <AddIntegerRequest, int> protocol) { while (true) { var res = await protocol.Read(); _ = PerformAddInteger(res.Item1, res.Item2.A, res.Item2.B, protocol); } }
static async Task PerformAddInteger(MessageId id, int a, int b, IMultiplexingSocketProtocol <AddIntegerRequest, int> protocol) { var sum = a + b; await protocol.Write(sum, id); }