示例#1
0
        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);
        }
示例#2
0
        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) => { };
        }
示例#3
0
        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);
        }