private void AsyncSettingsAck0(Http2FrameCodec codec, IChannelHandler multiplexer) { // The client expects 2 settings frames. One from the connection setup and one from this test. CountdownEvent serverAckOneLatch = new CountdownEvent(1); CountdownEvent serverAckAllLatch = new CountdownEvent(2); CountdownEvent clientSettingsLatch = new CountdownEvent(2); CountdownEvent serverConnectedChannelLatch = new CountdownEvent(1); AtomicReference <IChannel> serverConnectedChannelRef = new AtomicReference <IChannel>(); _sb = new ServerBootstrap(); _sb.Group(new MultithreadEventLoopGroup(1), new MultithreadEventLoopGroup()); _sb.Channel <TcpServerSocketChannel>(); _sb.ChildHandler(new ActionChannelInitializer <IChannel>(ch => { ch.Pipeline.AddLast(codec); if (multiplexer != null) { ch.Pipeline.AddLast(multiplexer); } ch.Pipeline.AddLast(new TestServerInboundHandler(serverAckOneLatch, serverAckAllLatch, serverConnectedChannelLatch, serverConnectedChannelRef)); })); var loopback = IPAddress.IPv6Loopback; _serverChannel = _sb.BindAsync(loopback, 0).GetAwaiter().GetResult(); _bs = new Bootstrap(); _bs.Group(new MultithreadEventLoopGroup()); _bs.Channel <TcpSocketChannel>(); _bs.Handler(new ActionChannelInitializer <IChannel>(ch => { var builder = Http2MultiplexCodecBuilder.ForClient(DISCARD_HANDLER.Instance); builder.AutoAckSettingsFrame = false; ch.Pipeline.AddLast(builder.Build()); ch.Pipeline.AddLast(new TestClientInboundHandler(clientSettingsLatch)); })); var port = ((IPEndPoint)_serverChannel.LocalAddress).Port; var ccf = _bs.ConnectAsync(loopback, port); _clientChannel = ccf.GetAwaiter().GetResult(); serverConnectedChannelLatch.Wait(); _serverConnectedChannel = serverConnectedChannelRef.Value; _serverConnectedChannel.WriteAndFlushAsync(new DefaultHttp2SettingsFrame(new Http2Settings() .MaxConcurrentStreams(10))).GetAwaiter().GetResult(); clientSettingsLatch.Wait(); // We expect a timeout here because we want to asynchronously generate the SETTINGS ACK below. Assert.False(serverAckOneLatch.Wait(TimeSpan.FromMilliseconds(300))); // We expect 2 settings frames, the initial settings frame during connection establishment and the setting frame // written in this test. We should ack both of these settings frames. _clientChannel.WriteAndFlushAsync(DefaultHttp2SettingsAckFrame.Instance).GetAwaiter().GetResult(); _clientChannel.WriteAndFlushAsync(DefaultHttp2SettingsAckFrame.Instance).GetAwaiter().GetResult(); serverAckAllLatch.Wait(); }
protected override Http2MultiplexCodec NewCodec(IChannelHandler upgradeHandler) { Http2MultiplexCodecBuilder builder = Http2MultiplexCodecBuilder.ForClient(new NoopHandler()); if (upgradeHandler != null) { builder.WithUpgradeStreamHandler(upgradeHandler); } return(builder.Build()); }
public void UpgradeToHttp2MultiplexCodec() { TestUpgrade(Http2MultiplexCodecBuilder.ForClient(new HttpInboundHandler()) .WithUpgradeStreamHandler(new ChannelHandlerAdapter()).Build(), null); }