Ejemplo n.º 1
0
        private ITcpSession ConnectSync(string host, int port)
        {
            var          remove_mes = new List <int>();
            MemoryStream?mstream    = null;

            foreach (var(id, stream) in streams)
            {
                if (!stream.CanRead)
                {
                    remove_mes.Add(id);
                    continue;
                }
                if (id == port)
                {
                    mstream = stream;
                }
            }
            foreach (var remove in remove_mes)
            {
                streams.Remove(remove);
            }

            if (mstream is null)
            {
                mstream = new MemoryStream();
                streams.Add(port, mstream);
            }

            var session = new MockTcpSession(mstream, Config.TcpConnectionTimeoutTicks);

            return(session);
        }
Ejemplo n.º 2
0
        public async Task <ITcpSession> AcceptTcpConnection(CancellationToken token)
        {
            while (!token.IsCancellationRequested && !Pending())
            {
                if (token.IsCancellationRequested)
                {
                    return(TcpSessionFactory.Empty);
                }

                await Task.Delay(15);
            }

            var sm = simulated_stream !;
            var sp = simulated_port;

            simulated_stream = null;
            simulated_port   = -1;

            var session = new MockTcpSession(sm, Config.TcpConnectionTimeoutTicks);

            streams.Add(sp, sm);

            return(session);
        }