Exemple #1
0
        public bool Send(byte[] data)
        {
            if (Type == StreamType.ServerUnidirectional)
            {
                throw new StreamException("Cannot send data on unidirectional stream.");
            }

            _connection.IncrementRate(data.Length);

            var packet = _connection.PacketCreator.CreateDataPacket(StreamId.IntegerValue, data);

            if (_connection.MaximumReached())
            {
                packet.AttachFrame(new StreamDataBlockedFrame(StreamId.IntegerValue, (ulong)data.Length));
            }

            return(_connection.SendData(packet));
        }
Exemple #2
0
        public bool Send(byte[] data)
        {
            if (Type == StreamType.ServerUnidirectional)
            {
                throw new StreamException("Cannot send data on unidirectional stream.");
            }

            _connection.IncrementRate(data.Length);

            int numberOfPackets = (data.Length / QuicSettings.PMTU) + 1;
            int leftoverCarry   = data.Length % QuicSettings.PMTU;

            for (int i = 0; i < numberOfPackets; i++)
            {
                bool eos      = false;
                int  dataSize = QuicSettings.PMTU;
                if (i == numberOfPackets - 1)
                {
                    eos      = true;
                    dataSize = leftoverCarry;
                }

                byte[] buffer = new byte[dataSize];
                Buffer.BlockCopy(data, (Int32)_sendOffset, buffer, 0, dataSize);

                ShortHeaderPacket packet = _connection.PacketCreator.CreateDataPacket(this.StreamId.IntegerValue, buffer, _sendOffset, eos);
                if (i == 0 && data.Length >= QuicSettings.MaxStreamData)
                {
                    packet.AttachFrame(new MaxStreamDataFrame(this.StreamId.IntegerValue, (UInt64)(data.Length + 1)));
                }

                if (_connection.MaximumReached())
                {
                    packet.AttachFrame(new StreamDataBlockedFrame(StreamId.IntegerValue, (UInt64)data.Length));
                }

                _sendOffset += (UInt64)buffer.Length;

                _connection.SendData(packet);
            }

            return(true);
        }