Exemplo n.º 1
0
        /**
         * Creates a new instance.
         *
         * @param output output for kcp
         */
        public Ukcp(KcpOutput output, KcpListener kcpListener, IMessageExecutor iMessageExecutor,
                    ReedSolomon reedSolomon, ChannelConfig channelConfig)
        {
            this._channelConfig    = channelConfig;
            this.kcp               = new Kcp(channelConfig.Conv, output);
            this.active            = true;
            this._kcpListener      = kcpListener;
            this._iMessageExecutor = iMessageExecutor;
            //默认2<<11   可以修改
            _writeQueue = new MpscArrayQueue <IByteBuffer>(2 << 10);
            _readQueue  = new MpscArrayQueue <IByteBuffer>(2 << 10);
            //recieveList = new SpscLinkedQueue<>();
            int headerSize = 0;

            if (channelConfig.KcpTag)
            {
                headerSize += KCP_TAG;
            }

            //init crc32
            if (channelConfig.Crc32Check)
            {
                var kcpOutput = kcp.Output;
                kcpOutput   = new Crc32OutPut(kcpOutput, headerSize);
                kcp.Output  = kcpOutput;
                headerSize += HEADER_CRC;
            }

            //init fec
            if (reedSolomon != null)
            {
                var kcpOutput = kcp.Output;
                _fecEncode  = new FecEncode(headerSize, reedSolomon, channelConfig.Mtu);
                _fecDecode  = new FecDecode(3 * reedSolomon.getTotalShardCount(), reedSolomon, channelConfig.Mtu);
                kcpOutput   = new FecOutPut(kcpOutput, _fecEncode);
                kcp.Output  = kcpOutput;
                headerSize += Fec.fecHeaderSizePlus2;
            }

            kcp.setReserved(headerSize);
            intKcpConfig(channelConfig);
        }