Ejemplo n.º 1
0
        public bool SendNotify(Connection connection, byte[] data, object?userObject)
        {
            if (connection.SendWindow.IsFull)
            {
                return(false);
            }


            if (data.Length > (_config.MTU - NotifyPacketHeaderSize))
            {
                Log.Error($"[SendNotify]: Data too large, above MTU-Header_Size({NotifyPacketHeaderSize}) {data.Length}");
                return(false);
            }

            var sequenceNumberForPacket = connection.SendSequencer.Next();

            var buffer = GetMtuBuffer();

            Buffer.BlockCopy(data, 0, buffer, NotifyPacketHeaderSize, data.Length);

            // Fill header data
            buffer[0] = (byte)PacketType.Notify;
            var offset = 1;

            ByteUtils.WriteULong(buffer, offset, _config.SequenceNumberBytes, sequenceNumberForPacket);
            offset += _config.SequenceNumberBytes;
            ByteUtils.WriteULong(buffer, offset, _config.SequenceNumberBytes, connection.LastReceivedSequence);
            offset += _config.SequenceNumberBytes;
            ByteUtils.WriteULong(buffer, offset, sizeof(ulong), connection.ReceiveMask);

            connection.SendWindow.Push(new SendEnvelope()
            {
                Sequence = sequenceNumberForPacket,
                SendTime = _timer.Now,
                UserData = userObject
            });

            SendInternal(connection, buffer, NotifyPacketHeaderSize + data.Length);
            return(true);
        }