Beispiel #1
0
        void BufRelease0(ServerBootstrap sb, Bootstrap cb)
        {
            var serverHandler = new BufWriterHandler();
            var clientHandler = new BufWriterHandler();

            sb.ChildHandler(serverHandler);
            cb.Handler(clientHandler);

            // start server
            Task <IChannel> task = sb.BindAsync(LoopbackAnyPort);

            Assert.True(task.Wait(DefaultTimeout), "Server bind timed out");
            this.serverChannel = task.Result;
            Assert.NotNull(this.serverChannel.LocalAddress);
            var endPoint = (IPEndPoint)this.serverChannel.LocalAddress;

            // connect to server
            task = cb.ConnectAsync(endPoint);
            Assert.True(task.Wait(DefaultTimeout), "Connect to server timed out");
            this.clientChannel = task.Result;
            Assert.NotNull(this.clientChannel.LocalAddress);

            // Ensure the server socket accepted the client connection *and* initialized pipeline successfully.
            Assert.True(serverHandler.Added.Wait(DefaultTimeout), "Channel HandlerAdded timed out");

            // and then close all sockets.
            this.serverChannel.CloseAsync().Wait(DefaultTimeout);
            this.clientChannel.CloseAsync().Wait(DefaultTimeout);

            serverHandler.Check();
            clientHandler.Check();

            serverHandler.Release();
            clientHandler.Release();
        }
Beispiel #2
0
        private async Task TestBufRelease0(ServerBootstrap sb, Bootstrap cb)
        {
            try
            {
                BufWriterHandler serverHandler = new BufWriterHandler();
                BufWriterHandler clientHandler = new BufWriterHandler();

                sb.ChildHandler(serverHandler);
                cb.Handler(clientHandler);

                IChannel sc = await sb.BindAsync();

                IChannel cc = await cb.ConnectAsync(sc.LocalAddress);

                // Ensure the server socket accepted the client connection *and* initialized pipeline successfully.
                await serverHandler._channelFuture.Task;

                // and then close all sockets.
                await sc.CloseAsync();

                await cc.CloseAsync();

                serverHandler.Check();
                clientHandler.Check();

                serverHandler.Release();
                clientHandler.Release();
            }
            finally
            {
                Task.WaitAll(
                    sb.Group().ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)),
                    sb.ChildGroup().ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)),
                    cb.Group().ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5)));
            }
        }