private void Run() { this.filterPipeline = base.CreateFilterPipeline(); var scheduler = this.schedulerAllocator.Next(); this.session = new UdpSession(this.socket, options, this.memoryPool, scheduler, filterPipeline); session.Start(); }
public void Build_PredicateFuncs_Empty() { new TestCaseRunner() .Run(() => FilterPipeline.Build(new MiddlewareFunc <DummyContext, Task <PredicateFunc <DummyEntity> > > [0])) .Verify((actual, desc) => { var actualPredicate = actual(new DummyContext()).GetAwaiter().GetResult(); Assert.AreEqual(PredicateMiddleware <DummyContext, DummyEntity> .NullPredicate, actualPredicate, desc); }, (Type)null); }
public async Task Usage_IMiddleware() { var middlewares = new PredicateMiddleware <Uri, FileInfo>[] { new HttpsPredicate(), new StaticFilePredicate(), }; Func <Uri, Task <PredicateFunc <FileInfo> > > pipeline = FilterPipeline.Build(middlewares.Select(x => x.ToDelegate())); var predicate = await pipeline(new Uri("https://example.com/foo")); Assert.AreEqual(true, predicate(new FileInfo("foo.html"))); Assert.AreEqual(false, predicate(new FileInfo("bar.html"))); Assert.AreEqual(false, (await pipeline(new Uri("http://example.com/foo")))(new FileInfo("foo.html"))); }
public async Task Usage_MiddlewareFunc() { Func <Uri, Task <PredicateFunc <FileInfo> > > pipeline = FilterPipeline.Build(new MiddlewareFunc <Uri, Task <PredicateFunc <FileInfo> > >[] { next => async context => { if (!context.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { return(_ => false); } return(await next(context)); }, next => async context => { var nextPredicate = await next(context); var uriPath = context.AbsolutePath.TrimStart('/'); return(file => Path.GetFileNameWithoutExtension(file.Name).Equals(uriPath, StringComparison.OrdinalIgnoreCase) && nextPredicate(file)); }, }); var predicate = await pipeline(new Uri("https://example.com/foo")); Assert.AreEqual(true, predicate(new FileInfo("foo.html"))); Assert.AreEqual(false, predicate(new FileInfo("bar.html"))); Assert.AreEqual(false, (await pipeline(new Uri("http://example.com/foo")))(new FileInfo("foo.html"))); }
public void Build_PredicateFuncs_Null() { new TestCaseRunner() .Run(() => FilterPipeline.Build((MiddlewareFunc <DummyContext, Task <PredicateFunc <DummyEntity> > >[])null)) .Verify((actual, desc) => { }, typeof(ArgumentNullException)); }
public ATcpSession(Socket socket, ATcpOptions options, PipeScheduler scheduler, MemoryPool <byte> pool, FilterPipeline <ITcpSession> filterPipeline) { this.Id = IdGeneratorHelper.GetNextId(); this.Order = options.Order; this.MemoryPool = pool; this.Scheduler = scheduler; this.MemoryPool = pool; this.Scheduler = scheduler; this.minAllocBufferSize = this.MemoryPool.MaxBufferSize / 2; this.filterPipeline = filterPipeline; this.socket = new TcpSocket(socket, scheduler); this.LocalAddress = this.socket.BindAddress; this.RemoteAddress = this.socket.RemoteAddress; this.SettingSocket(this.socket, options); this.SettingPipeline(options.MaxPipelineReadBufferSize, options.MaxPipelineWriteBufferSize); }
public TcpSslSession(Socket socket, ATcpOptions options, PipeScheduler scheduler, MemoryPool <byte> pool, SslFeature sslFeature, FilterPipeline <ITcpSession> filterPipeline) : base(socket, options, scheduler, pool, filterPipeline) { var inputPipeOptions = StreamPipeOptionsHelper.ReaderOptionsCreator(pool); var outputPipeOptions = StreamPipeOptionsHelper.WriterOptionsCreator(pool); var sslDuplexPipe = new SslStreamDuplexPipe(base.Transport, inputPipeOptions, outputPipeOptions, sslFeature.sslStreamFactory); this.sslTransport = sslDuplexPipe; this.sslOptions = sslFeature.sslOptions; }
public TcpSession(Socket socket, ATcpOptions options, PipeScheduler scheduler, MemoryPool <byte> pool, FilterPipeline <ITcpSession> filterPipeline) : base(socket, options, scheduler, pool, filterPipeline) { this.readerFlushCallback = this.OnFilterReadFlush; this.writerFlushCallback = (writer) => { }; }
public KcpSession(uint conv, EndPoint remoteAddress, EndPoint localAddress, KcpOptions options, IUdpSession udpSession, IEventSubscriber subscriber, FilterPipeline <IKcpSession> pipeline, IKcpClosable closable) { this.Id = IdGeneratorHelper.GetNextId(); this.Conv = conv; this.LocalAddress = localAddress; this.RemoteAddress = remoteAddress; this.Order = options.Order; this.udpSession = udpSession; this.subscriber = subscriber; this.Pipeline = pipeline; this.closable = closable; var littleEndian = this.Order == BinaryOrder.LittleEndian; this.kcpKit = new KcpKit(conv, littleEndian, this.MemoryPool); this.kcpKit.SettingMtu(options.Mtu); this.kcpKit.SettingNoDelay(options.NoDelay); this.kcpKit.SettingWndSize(options.WndSize); this.kcpKit.SettingStreamMode(options.StreamMode); this.kcpKit.SettingReservedSize(options.ReservedSize); this.kcpKit.onRcv += this.OnKcpRcvEvent; this.kcpKit.onSnd += this.OnKcpSndEvent; this.kcpOperators = BinaryOrderOperatorsFactory.GetOperators(this.Order); this.rcvPool = new WrappedMemoryPool(this.MemoryPool, MemoryFlag.Kcp); this.sndPool = new WrappedMemoryPool(this.MemoryPool, MemoryFlag.Kcp); this.sndMemory = new WrappedMemory(this.MemoryPool.Rent(), MemoryFlag.Kcp); this.readerUdpMemory = new WrappedMemory(this.MemoryPool.Rent(), MemoryFlag.Udp); this.writerUdpMemory = new WrappedMemory(this.MemoryPool.Rent(), MemoryFlag.Udp); this.readerFlushDelegate = (pos, endPos) => { }; this.writerFlushDelegate = this.OnWriterComplete; this.runnableUnitDelegate = this.Update; this.subscriber.Register(this.runnableUnitDelegate); this.Pipeline.OnTransportActive(this); }
public UdpSession(Socket socket, UdpOptions options, MemoryPool <byte> memoryPool, PipeScheduler scheduler, FilterPipeline <IUdpSession> filterPipeline) { this.Id = IdGeneratorHelper.GetNextId(); this.socket = new UdpSocket(socket, scheduler); this.SettingSocket(this.socket, options); this.Order = options.Order; this.Scheduler = scheduler; this.MemoryPool = memoryPool; this.filterPipeline = filterPipeline; this.LocalAddress = this.socket.BindAddress; this.memoryBlockSize = this.MemoryPool.MaxBufferSize; this.rcvPipeline = new DgramPipeline(this.MemoryPool, scheduler, OnRcvPipelineRead); this.sndPipeline = new DgramPipeline(this.MemoryPool, scheduler, OnSndPipelineRead); this.readerFlushCallback = (startPos, endPos) => { }; this.writerFlushCallback = (writer) => { }; }