private static async Task Main(string[] args) { ////System.Diagnostics.Debugger.Launch(); int protocolMajorVersion = int.Parse(args[0]); var options = new MultiplexingStream.Options { TraceSource = { Switch = { Level = SourceLevels.Verbose } }, ProtocolMajorVersion = protocolMajorVersion, DefaultChannelReceivingWindowSize = 64, DefaultChannelTraceSourceFactoryWithQualifier = (id, name) => new TraceSource($"Channel {id}") { Switch = { Level = SourceLevels.Verbose } }, }; if (protocolMajorVersion >= 3) { options.SeededChannels.Add(new MultiplexingStream.ChannelOptions()); } var mx = await MultiplexingStream.CreateAsync( FullDuplexStream.Splice(Console.OpenStandardInput(), Console.OpenStandardOutput()), options); var program = new Program(mx); await program.RunAsync(protocolMajorVersion); }
public void CopyConstructor() { Assert.Throws <ArgumentNullException>(() => new MultiplexingStream.Options(null !)); var original = new MultiplexingStream.Options { DefaultChannelReceivingWindowSize = 7185, DefaultChannelTraceSourceFactory = (id, name) => null, DefaultChannelTraceSourceFactoryWithQualifier = (id, name) => null, ProtocolMajorVersion = 1024, TraceSource = new TraceSource("test"), SeededChannels = { new MultiplexingStream.ChannelOptions(), new MultiplexingStream.ChannelOptions(), }, }; var copy = new MultiplexingStream.Options(original); Assert.Equal(original.DefaultChannelReceivingWindowSize, copy.DefaultChannelReceivingWindowSize); Assert.Equal(original.DefaultChannelTraceSourceFactory, copy.DefaultChannelTraceSourceFactory); Assert.Equal(original.DefaultChannelTraceSourceFactoryWithQualifier, copy.DefaultChannelTraceSourceFactoryWithQualifier); Assert.Equal(original.ProtocolMajorVersion, copy.ProtocolMajorVersion); Assert.Equal(original.TraceSource, copy.TraceSource); Assert.NotSame(original.SeededChannels, copy.SeededChannels); Assert.Equal <MultiplexingStream.ChannelOptions>(original.SeededChannels, copy.SeededChannels); }
public override async Task SeededChannels() { var pair = FullDuplexStream.CreatePair(); var options = new MultiplexingStream.Options { ProtocolMajorVersion = this.ProtocolMajorVersion, SeededChannels = { new MultiplexingStream.ChannelOptions { }, new MultiplexingStream.ChannelOptions { }, }, }; var mx1 = MultiplexingStream.Create(pair.Item1, options); var mx2 = MultiplexingStream.Create(pair.Item2, options); var channel1_0 = mx1.AcceptChannel(0); var channel1_1 = mx1.AcceptChannel(1); var channel2_0 = mx2.AcceptChannel(0); var channel2_1 = mx2.AcceptChannel(1); await this.TransmitAndVerifyAsync(channel1_0.AsStream(), channel2_0.AsStream(), new byte[] { 1, 2, 3 }); await this.TransmitAndVerifyAsync(channel1_1.AsStream(), channel2_1.AsStream(), new byte[] { 4, 5, 6 }); }
public void CopyOfFrozenIsNotFrozen() { MultiplexingStream.Options frozen = this.options.GetFrozenCopy(); var thawedOptions = new MultiplexingStream.Options(frozen); Assert.False(thawedOptions.IsFrozen); thawedOptions.ProtocolMajorVersion = 500; Assert.False(thawedOptions.SeededChannels.IsReadOnly); thawedOptions.SeededChannels.Add(new MultiplexingStream.ChannelOptions()); Assert.NotEmpty(thawedOptions.SeededChannels); Assert.Empty(frozen.SeededChannels); Assert.Empty(this.options.SeededChannels); }
public MultiplexingStreamSeededChannelTests(ITestOutputHelper logger) : base(logger) { this.options = new MultiplexingStream.Options { ProtocolMajorVersion = 3, SeededChannels = { new MultiplexingStream.ChannelOptions { }, new MultiplexingStream.ChannelOptions { }, new MultiplexingStream.ChannelOptions { }, }, }; var mx1TraceSource = new TraceSource(nameof(this.mx1), SourceLevels.All); var mx2TraceSource = new TraceSource(nameof(this.mx2), SourceLevels.All); mx1TraceSource.Listeners.Add(new XunitTraceListener(this.Logger, this.TestId, this.TestTimer)); mx2TraceSource.Listeners.Add(new XunitTraceListener(this.Logger, this.TestId, this.TestTimer)); Func <string, MultiplexingStream.QualifiedChannelId, string, TraceSource> traceSourceFactory = (string mxInstanceName, MultiplexingStream.QualifiedChannelId id, string name) => { var traceSource = new TraceSource(mxInstanceName + " channel " + id, SourceLevels.All); traceSource.Listeners.Clear(); // remove DefaultTraceListener traceSource.Listeners.Add(new XunitTraceListener(this.Logger, this.TestId, this.TestTimer)); return(traceSource); }; Func <MultiplexingStream.QualifiedChannelId, string, TraceSource> mx1TraceSourceFactory = (MultiplexingStream.QualifiedChannelId id, string name) => traceSourceFactory(nameof(this.mx1), id, name); Func <MultiplexingStream.QualifiedChannelId, string, TraceSource> mx2TraceSourceFactory = (MultiplexingStream.QualifiedChannelId id, string name) => traceSourceFactory(nameof(this.mx2), id, name); (this.transport1, this.transport2) = FullDuplexStream.CreatePair(new PipeOptions(pauseWriterThreshold: 2 * 1024 * 1024)); this.mx1 = MultiplexingStream.Create(this.transport1, new MultiplexingStream.Options(this.options) { TraceSource = mx1TraceSource, DefaultChannelTraceSourceFactoryWithQualifier = mx1TraceSourceFactory }); this.mx2 = MultiplexingStream.Create(this.transport2, new MultiplexingStream.Options(this.options) { TraceSource = mx2TraceSource, DefaultChannelTraceSourceFactoryWithQualifier = mx2TraceSourceFactory }); }