Ejemplo n.º 1
0
        public void GlobalSetup()
        {
            _memoryPool   = SlabMemoryPoolFactory.Create();
            _httpFrame    = new Http2Frame();
            _responseData = new string('!', ResponseDataLength);

            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

            _connectionPair = DuplexPipe.CreateConnectionPair(options, options);

            _httpRequestHeaders = new HttpRequestHeaders();
            _httpRequestHeaders.Append(HeaderNames.Method, new StringValues("GET"));
            _httpRequestHeaders.Append(HeaderNames.Path, new StringValues("/"));
            _httpRequestHeaders.Append(HeaderNames.Scheme, new StringValues("http"));
            _httpRequestHeaders.Append(HeaderNames.Authority, new StringValues("localhost:80"));

            _headersBuffer = new byte[1024 * 16];

            var serviceContext = new ServiceContext
            {
                DateHeaderValueManager = new DateHeaderValueManager(),
                ServerOptions          = new KestrelServerOptions(),
                Log         = new KestrelTrace(NullLogger.Instance),
                SystemClock = new MockSystemClock()
            };

            serviceContext.DateHeaderValueManager.OnHeartbeat(default);
Ejemplo n.º 2
0
        public StartLineTests()
        {
            MemoryPool = SlabMemoryPoolFactory.Create();
            var options = new PipeOptions(MemoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            Transport = pair.Transport;

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: new HttpParser <Http1ParsingHandler>(),
                log: _trace);

            var connectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: serviceContext,
                connectionContext: Mock.Of <ConnectionContext>(),
                transport: Transport,
                timeoutControl: new TimeoutControl(timeoutHandler: null),
                memoryPool: MemoryPool,
                connectionFeatures: new FeatureCollection());

            Http1Connection = new Http1Connection(connectionContext);

            Parser         = new HttpParser <Http1ParsingHandler>(showErrorDetails: true);
            ParsingHandler = new Http1ParsingHandler(Http1Connection);
        }
Ejemplo n.º 3
0
        public void InitialDictionaryIsEmpty()
        {
            using (var memoryPool = SlabMemoryPoolFactory.Create())
            {
                var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
                var pair    = DuplexPipe.CreateConnectionPair(options, options);
                var http1ConnectionContext = new HttpConnectionContext
                {
                    ServiceContext     = new TestServiceContext(),
                    ConnectionFeatures = new FeatureCollection(),
                    MemoryPool         = memoryPool,
                    Transport          = pair.Transport,
                    TimeoutControl     = null
                };

                var http1Connection = new Http1Connection(http1ConnectionContext);

                http1Connection.Reset();

                IDictionary <string, StringValues> headers = http1Connection.ResponseHeaders;

                Assert.Equal(0, headers.Count);
                Assert.False(headers.IsReadOnly);
            }
        }
Ejemplo n.º 4
0
        public TestInput(IKestrelTrace log = null, ITimeoutControl timeoutControl = null)
        {
            _memoryPool = SlabMemoryPoolFactory.Create();
            var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            Transport   = pair.Transport;
            Application = pair.Application;

            var connectionFeatures = new FeatureCollection();

            connectionFeatures.Set(Mock.Of <IConnectionLifetimeFeature>());

            Http1ConnectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: new TestServiceContext
            {
                Log = log ?? Mock.Of <IKestrelTrace>()
            },
                connectionContext: Mock.Of <ConnectionContext>(),
                transport: Transport,
                timeoutControl: timeoutControl ?? Mock.Of <ITimeoutControl>(),
                memoryPool: _memoryPool,
                connectionFeatures: connectionFeatures);

            Http1Connection = new Http1Connection(Http1ConnectionContext);
            Http1Connection.HttpResponseControl = Mock.Of <IHttpResponseControl>();
            Http1Connection.Reset();
        }
Ejemplo n.º 5
0
        public virtual void GlobalSetup()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();
            _httpFrame  = new Http2Frame();

            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

            _connectionPair = DuplexPipe.CreateConnectionPair(options, options);

            _httpRequestHeaders = new HttpRequestHeaders();
            _httpRequestHeaders.HeaderMethod    = new StringValues("GET");
            _httpRequestHeaders.HeaderPath      = new StringValues("/");
            _httpRequestHeaders.HeaderScheme    = new StringValues("http");
            _httpRequestHeaders.HeaderAuthority = new StringValues("localhost:80");

            _headersBuffer = new byte[1024 * 16];
            _hpackEncoder  = new HPackEncoder();

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                dateHeaderValueManager: new DateHeaderValueManager(),
                systemClock: new MockSystemClock(),
                log: new MockTrace());

            serviceContext.DateHeaderValueManager.OnHeartbeat(default);
Ejemplo n.º 6
0
        public TestInput()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();
            var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            Transport   = pair.Transport;
            Application = pair.Application;

            var connectionFeatures = new FeatureCollection();

            connectionFeatures.Set(Mock.Of <IConnectionLifetimeFeature>());

            Http1ConnectionContext = new HttpConnectionContext
            {
                ServiceContext     = new TestServiceContext(),
                ConnectionContext  = Mock.Of <ConnectionContext>(),
                ConnectionFeatures = connectionFeatures,
                Transport          = Transport,
                MemoryPool         = _memoryPool,
                TimeoutControl     = Mock.Of <ITimeoutControl>()
            };

            Http1Connection = new Http1Connection(Http1ConnectionContext);
            Http1Connection.HttpResponseControl = Mock.Of <IHttpResponseControl>();
            Http1Connection.Reset();
        }
        public HttpProtocolFeatureCollection()
        {
            var memoryPool = SlabMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: new HttpParser <Http1ParsingHandler>(),
                dateHeaderValueManager: new DateHeaderValueManager(),
                log: new MockTrace());

            var connectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: serviceContext,
                connectionContext: null,
                transport: pair.Transport,
                memoryPool: memoryPool,
                connectionFeatures: new FeatureCollection());

            var http1Connection = new Http1Connection(connectionContext);

            http1Connection.Reset();

            _collection = http1Connection;
        }
        public void Setup()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();
            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = new ServiceContext
            {
                DateHeaderValueManager = new DateHeaderValueManager(),
                ServerOptions          = new KestrelServerOptions(),
                Log        = new MockTrace(),
                HttpParser = new HttpParser <Http1ParsingHandler>()
            };

            var http1Connection = new Http1Connection(new HttpConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = _memoryPool,
                Transport          = pair.Transport,
                TimeoutControl     = new TimeoutControl(timeoutHandler: null)
            });

            http1Connection.Reset();

            Http1Connection = http1Connection;
            Pipe            = new Pipe(new PipeOptions(_memoryPool));
        }
Ejemplo n.º 9
0
        public StartLineTests()
        {
            MemoryPool = SlabMemoryPoolFactory.Create();
            var options = new PipeOptions(MemoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            Transport = pair.Transport;

            var serviceContext = new ServiceContext
            {
                ServerOptions = new KestrelServerOptions(),
                Log           = _trace,
                HttpParser    = new HttpParser <Http1ParsingHandler>()
            };

            Http1Connection = new Http1Connection(context: new HttpConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = MemoryPool,
                Transport          = Transport,
                TimeoutControl     = new TimeoutControl(timeoutHandler: null)
            });

            Parser         = new HttpParser <Http1ParsingHandler>(showErrorDetails: true);
            ParsingHandler = new Http1ParsingHandler(Http1Connection);
        }
Ejemplo n.º 10
0
        public Http1ConnectionTests()
        {
            _pipelineFactory = SlabMemoryPoolFactory.Create();
            var options = new PipeOptions(_pipelineFactory, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            _transport   = pair.Transport;
            _application = pair.Application;

            var connectionFeatures = new FeatureCollection();

            connectionFeatures.Set(Mock.Of <IConnectionLifetimeFeature>());

            _serviceContext = new TestServiceContext()
            {
                Scheduler = PipeScheduler.Inline
            };

            _timeoutControl         = new Mock <ITimeoutControl>();
            _http1ConnectionContext = new HttpConnectionContext
            {
                ServiceContext     = _serviceContext,
                ConnectionContext  = Mock.Of <ConnectionContext>(),
                ConnectionFeatures = connectionFeatures,
                MemoryPool         = _pipelineFactory,
                TimeoutControl     = _timeoutControl.Object,
                Transport          = pair.Transport
            };

            _http1Connection = new TestHttp1Connection(_http1ConnectionContext);
        }
Ejemplo n.º 11
0
        public void GlobalSetup()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();

            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

            _pipe = new Pipe(options);

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: new HttpParser <Http1ParsingHandler>(),
                dateHeaderValueManager: new DateHeaderValueManager(),
                log: new MockTrace());

            _frameWriter = new Http2FrameWriter(
                new NullPipeWriter(),
                connectionContext: null,
                http2Connection: null,
                new OutputFlowControl(new SingleAwaitableProvider(), initialWindowSize: int.MaxValue),
                timeoutControl: null,
                minResponseDataRate: null,
                "TestConnectionId",
                _memoryPool,
                serviceContext);

            _responseHeaders = new HttpResponseHeaders();
            _responseHeaders.HeaderContentType   = "application/json";
            _responseHeaders.HeaderContentLength = "1024";
        }
Ejemplo n.º 12
0
        public void GlobalSetup()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();

            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

            _pipe = new Pipe(options);

            _httpRequestHeaders = new HttpRequestHeaders();
            _httpRequestHeaders.Append(HeaderNames.Method, new StringValues("GET"));
            _httpRequestHeaders.Append(HeaderNames.Path, new StringValues("/"));
            _httpRequestHeaders.Append(HeaderNames.Scheme, new StringValues("http"));
            _httpRequestHeaders.Append(HeaderNames.Authority, new StringValues("localhost:80"));

            _hpackEncoder  = new HPackEncoder();
            _headersBuffer = new byte[1024 * 16];

            var serviceContext = new ServiceContext
            {
                DateHeaderValueManager = new DateHeaderValueManager(),
                ServerOptions          = new KestrelServerOptions(),
                Log         = new KestrelTrace(NullLogger.Instance),
                SystemClock = new MockSystemClock()
            };

            serviceContext.ServerOptions.Limits.Http2.MaxStreamsPerConnection = int.MaxValue;
            serviceContext.DateHeaderValueManager.OnHeartbeat(default);
Ejemplo n.º 13
0
        public override async Task BuildAsync()
        {
            await base.BuildAsync();

            this.memoryPool         = SlabMemoryPoolFactory.Create(this.options.MemoryPoolOptions);
            this.schedulerAllocator = new SchedulerAllocator(this.options.SchedulerCount);
        }
        public HttpProtocolFeatureCollection()
        {
            var memoryPool = SlabMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = new ServiceContext
            {
                DateHeaderValueManager = new DateHeaderValueManager(),
                ServerOptions          = new KestrelServerOptions(),
                Log        = new MockTrace(),
                HttpParser = new HttpParser <Http1ParsingHandler>()
            };

            var http1Connection = new Http1Connection(new HttpConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = memoryPool,
                Transport          = pair.Transport
            });

            http1Connection.Reset();

            _collection = http1Connection;
        }
        public void Setup()
        {
            var memoryPool = SlabMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = new ServiceContext
            {
                ServerOptions = new KestrelServerOptions(),
                HttpParser    = NullParser <Http1ParsingHandler> .Instance
            };

            var http1Connection = new Http1Connection(context: new HttpConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = memoryPool,
                TimeoutControl     = new TimeoutControl(timeoutHandler: null),
                Transport          = pair.Transport
            });

            http1Connection.Reset();

            Connection = http1Connection;
        }
Ejemplo n.º 16
0
        public void Setup()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();
            var pipe = new Pipe(new PipeOptions(_memoryPool));

            _reader = pipe.Reader;
            _writer = pipe.Writer;
        }
        public LibuvOutputConsumerTests()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();
            _mockLibuv  = new MockLibuv();

            var context = new TestLibuvTransportContext();

            _libuvThread = new LibuvThread(_mockLibuv, context, maxLoops: 1);
            _libuvThread.StartAsync().Wait();
        }
        public void Setup()
        {
            var memoryPool = SlabMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = new ServiceContext
            {
                DateHeaderValueManager = _dateHeaderValueManager,
                ServerOptions          = new KestrelServerOptions(),
                Log        = new MockTrace(),
                HttpParser = new HttpParser <Http1ParsingHandler>()
            };

            var http1Connection = new Http1Connection(new HttpConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = memoryPool,
                Transport          = pair.Transport
            });

            http1Connection.Reset();
            serviceContext.DateHeaderValueManager.OnHeartbeat(DateTimeOffset.UtcNow);

            _responseHeadersDirect = (HttpResponseHeaders)http1Connection.ResponseHeaders;
            var context = new DefaultHttpContext(http1Connection);

            _response = context.Response;

            switch (Type)
            {
            case BenchmarkTypes.ContentLengthNumeric:
                ContentLengthNumeric(1);
                break;

            case BenchmarkTypes.ContentLengthString:
                ContentLengthString(1);
                break;

            case BenchmarkTypes.Plaintext:
                Plaintext(1);
                break;

            case BenchmarkTypes.Common:
                Common(1);
                break;

            case BenchmarkTypes.Unknown:
                Unknown(1);
                break;
            }
        }
        public SocketConnectionFactory(IOptions <SocketTransportOptions> options, ILoggerFactory loggerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _options    = options.Value;
            _memoryPool = SlabMemoryPoolFactory.Create();
            var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Client");

            _trace = new SocketsTrace(logger);
        }
Ejemplo n.º 20
0
        public static Http3ConnectionContext CreateHttp3ConnectionContext(
            MultiplexedConnectionContext connectionContext = null,
            ServiceContext serviceContext         = null,
            IFeatureCollection connectionFeatures = null,
            MemoryPool <byte> memoryPool          = null,
            IPEndPoint localEndPoint       = null,
            IPEndPoint remoteEndPoint      = null,
            ITimeoutControl timeoutControl = null)
        {
            var http3ConnectionContext = new Http3ConnectionContext(
                "TestConnectionId",
                connectionContext ?? new TestMultiplexedConnectionContext(),
                serviceContext ?? CreateServiceContext(new KestrelServerOptions()),
                connectionFeatures ?? new FeatureCollection(),
                memoryPool ?? SlabMemoryPoolFactory.Create(),
                localEndPoint,
                remoteEndPoint);

            http3ConnectionContext.TimeoutControl = timeoutControl;

            return(http3ConnectionContext);
        }
Ejemplo n.º 21
0
        public void GlobalSetup()
        {
            _memoryPool = SlabMemoryPoolFactory.Create();

            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

            _pipe = new Pipe(options);

            _frameWriter = new Http2FrameWriter(
                new NullPipeWriter(),
                connectionContext: null,
                http2Connection: null,
                new OutputFlowControl(new SingleAwaitableProvider(), initialWindowSize: uint.MaxValue),
                timeoutControl: null,
                minResponseDataRate: null,
                "TestConnectionId",
                _memoryPool,
                new KestrelTrace(NullLogger.Instance));

            _responseHeaders = new HttpResponseHeaders();
            _responseHeaders.HeaderContentType   = "application/json";
            _responseHeaders.HeaderContentLength = "1024";
        }
Ejemplo n.º 22
0
        public void Setup()
        {
            var memoryPool = SlabMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: new HttpParser <Http1ParsingHandler>());

            var connectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: serviceContext,
                connectionContext: null,
                transport: pair.Transport,
                timeoutControl: new TimeoutControl(timeoutHandler: null),
                memoryPool: memoryPool,
                connectionFeatures: new FeatureCollection());

            var http1Connection = new Http1Connection(connectionContext);

            http1Connection.Reset();

            Connection = http1Connection;
        }
Ejemplo n.º 23
0
 public TcpServerChannel(TcpServerOptions options, Action <IFilterPipeline <ITcpSession> > handler, SslFeature sslFeature)
     : base(handler, sslFeature, options)
 {
     this.memoryPool         = SlabMemoryPoolFactory.Create(this.options.MemoryPoolOptions);
     this.schedulerAllocator = new SchedulerAllocator(this.options.SchedulerCount);
 }
Ejemplo n.º 24
0
 public void GlobalSetup()
 {
     _memoryPool              = SlabMemoryPoolFactory.Create();
     _http1Connection         = MakeHttp1Connection();
     _consumeResponseBodyTask = ConsumeResponseBody();
 }
Ejemplo n.º 25
0
 public OutputProducerTests()
 {
     _memoryPool = SlabMemoryPoolFactory.Create();
 }
 public void Setup()
 {
     _memoryPool = SlabMemoryPoolFactory.Create();
     _pipe       = new Pipe(new PipeOptions(_memoryPool));
 }
Ejemplo n.º 27
0
 public void GlobalSetup()
 {
     _memoryPool      = SlabMemoryPoolFactory.Create();
     _http1Connection = MakeHttp1Connection();
 }
Ejemplo n.º 28
0
        static unsafe void Main(string[] args)
        {
            Console.Title = "kcp_lib1111111111111111111111111111111";
            Console.WriteLine(Process.GetCurrentProcess().Id);

            // _ = new PerformanceCounterListener();

            var memoryPool = SlabMemoryPoolFactory.Create(new MemoryPoolOptions(4096, 32));

            for (int i = 0; i < 5000; i++)
            {
                uint tempConv = (uint)i;
                var  unit1    = new KcpUnit(tempConv, memoryPool);
                unit1.SetRcvEvent((uint conv, ref ReadOnlySequence <byte> sequence) => { OnRcvEvent(ref sequence, 1, conv); });
                unit1.SetSndEvent((uint conv, ref ReadOnlySequence <byte> sequence) => { OnSndEvent(ref sequence, 1, conv); });
                units_1.Add(unit1);

                var unit2 = new KcpUnit(tempConv, memoryPool);
                unit2.SetRcvEvent((uint conv, ref ReadOnlySequence <byte> sequence) => { OnRcvEvent(ref sequence, 2, conv); });
                unit2.SetSndEvent((uint conv, ref ReadOnlySequence <byte> sequence) => { OnSndEvent(ref sequence, 2, conv); });
                units_2.Add(unit2);
            }

            Thread thread = new Thread(() =>
            {
                while (isRun)
                {
                    Thread.Sleep(1);

                    int count1 = units_1.Count;
                    for (int i = 0; i < count1; i++)
                    {
                        units_1[i].Update();
                    }

                    int count2 = units_2.Count;
                    for (int i = 0; i < count2; i++)
                    {
                        units_2[i].Update();
                    }
                }
            });

            thread.Start();


            byte[] buffer = Encoding.UTF8.GetBytes(Message.data_32);
            while (true)
            {
                // System.Threading.Thread.Sleep(1);
                string str = Console.ReadLine();
                Console.Clear();
                if (int.TryParse(str, out var length))
                {
                    for (int i = 0; i < length; i++)
                    {
                        Interlocked.Increment(ref num);
                        if (use_buffer)
                        {
                            int count1 = units_1.Count;
                            for (int j = 0; j < count1; j++)
                            {
                                units_1[j].Send(buffer);
                            }
                        }
                        else
                        {
                            var bytes  = System.Text.Encoding.UTF8.GetBytes($"nihao {i}-----{num}");
                            int count1 = units_1.Count;
                            for (int j = 0; j < count1; j++)
                            {
                                units_1[j].Send(bytes);
                            }
                        }
                    }
                }
                else if (string.IsNullOrEmpty(str))
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        Interlocked.Increment(ref num);
                        if (use_buffer)
                        {
                            foreach (var unit in units_1)
                            {
                                unit.Send(buffer);
                            }
                        }
                        else
                        {
                            var bytes = Encoding.UTF8.GetBytes($"nihao {i}");
                            foreach (var unit in units_1)
                            {
                                unit.Send(bytes);
                            }
                        }
                    }
                }
                else if (str == "s")
                {
                    isRun = false;
                    return;
                }
                else
                {
                    //d-type-index
                    if (str.Contains("d"))
                    {
                        var arr   = str.Split('-');
                        var type  = int.Parse(arr[1]);
                        var index = int.Parse(arr[2]);

                        if (type == 1)
                        {
                            for (int i = index; i < units_1.Count; i++)
                            {
                                units_1[i].Debug();
                            }
                        }

                        if (type == 2)
                        {
                            for (int i = index; i < units_2.Count; i++)
                            {
                                units_2[i].Debug();
                            }
                        }
                    }
                }
            }
        }