private async Task TestReadPendingIsResetAfterEachRead0(ServerBootstrap sb, Bootstrap cb, bool isLibuvServer, bool isLibuvClient) { IChannel serverChannel = null; IChannel clientChannel = null; try { ReadPendingInitializer serverInitializer = new ReadPendingInitializer(isLibuvServer); ReadPendingInitializer clientInitializer = new ReadPendingInitializer(isLibuvClient); sb.Option(ChannelOption.SoBacklog, 1024) .Option(ChannelOption.AutoRead, true) .ChildOption(ChannelOption.AutoRead, false) // We intend to do 2 reads per read loop wakeup .ChildOption(ChannelOption.RcvbufAllocator, new TestNumReadsRecvByteBufAllocator(2)) .ChildHandler(serverInitializer); serverChannel = await sb.BindAsync(); cb.Option(ChannelOption.AutoRead, false) // We intend to do 2 reads per read loop wakeup .Option(ChannelOption.RcvbufAllocator, new TestNumReadsRecvByteBufAllocator(2)) .Handler(clientInitializer); clientChannel = await cb.ConnectAsync(serverChannel.LocalAddress); // 4 bytes means 2 read loops for TestNumReadsRecvByteBufAllocator await clientChannel.WriteAndFlushAsync(Unpooled.WrappedBuffer(new byte[4])); // 4 bytes means 2 read loops for TestNumReadsRecvByteBufAllocator Assert.True(serverInitializer._channelInitLatch.Wait(TimeSpan.FromSeconds(5))); await serverInitializer._channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(new byte[4])); serverInitializer._channel.Read(); serverInitializer._readPendingHandler.AssertAllRead(); clientChannel.Read(); clientInitializer._readPendingHandler.AssertAllRead(); } finally { if (serverChannel != null) { await serverChannel.CloseAsync(); } if (clientChannel != null) { await clientChannel.CloseAsync(); } 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))); } }
void ReadPendingIsResetAfterEachRead0(ServerBootstrap sb, Bootstrap cb) { var serverInitializer = new ReadPendingInitializer(); sb.Option(ChannelOption.SoBacklog, 1024) .Option(ChannelOption.AutoRead, true) .ChildOption(ChannelOption.AutoRead, false) // We intend to do 2 reads per read loop wakeup .ChildOption(ChannelOption.RcvbufAllocator, new TestNumReadsRecvByteBufAllocator(2)) .ChildHandler(serverInitializer); // 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; var clientInitializer = new ReadPendingInitializer(); cb.Option(ChannelOption.AutoRead, false) // We intend to do 2 reads per read loop wakeup .Option(ChannelOption.RcvbufAllocator, new TestNumReadsRecvByteBufAllocator(2)) .Handler(clientInitializer); // 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); // 4 bytes means 2 read loops for TestNumReadsRecvByteBufAllocator Task writeTask = this.clientChannel.WriteAndFlushAsync(Unpooled.WrappedBuffer(new byte[4])); Assert.True(writeTask.Wait(TimeSpan.FromSeconds(5)), "Client write task timed out"); // 4 bytes means 2 read loops for TestNumReadsRecvByteBufAllocator Assert.True(serverInitializer.Initialize.Wait(DefaultTimeout), "Server initializer timed out"); writeTask = serverInitializer.Channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(new byte[4])); Assert.True(writeTask.Wait(TimeSpan.FromSeconds(5)), "Server write task timed out"); serverInitializer.Channel.Read(); serverInitializer.ReadPendingHandler.AssertAllRead(); this.clientChannel.Read(); clientInitializer.ReadPendingHandler.AssertAllRead(); }