Example #1
0
        private void Socket_onMessage(byte[] buffer, int offset, int length)
        {
            var inputN = _kcp.Input(buffer, offset, length, true, ackNoDelay);

            if (inputN < 0)
            {
                return;
            }
            _buffer.Clear();
            while (true)
            {
                var size = _kcp.PeekSize();
                if (size <= 0)
                {
                    break;
                }

                _buffer.EnsureWritableBytes(size);

                var n = _kcp.Recv(_buffer.buffer, _buffer.writer, size);
                if (n > 0)
                {
                    _buffer.writer += n;
                }
            }

            // 有数据待接收
            if (_buffer.canRead > 0)
            {
                _listen.OnMessage(socket, _buffer.buffer, _buffer.reader, _buffer.canRead);
                // 读完重置读写指针
                if (_buffer.reader == _buffer.writer)
                {
                    _buffer.Clear();
                }
            }
        }
Example #2
0
            internal void Reset()
            {
                conv     = 0;
                cmd      = 0;
                frg      = 0;
                wnd      = 0;
                ts       = 0;
                sn       = 0;
                una      = 0;
                rto      = 0;
                xmit     = 0;
                resendts = 0;
                fastack  = 0;
                acked    = 0;

                data.Clear();
                data.Dispose();
                data = null;
            }