Skip to content

Commit

Permalink
Fixed reusing of unclosed strea
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dimitrov committed Dec 1, 2020
1 parent c0b9ead commit efb916a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions QuicNet.Infrastructure/PacketProcessing/PacketCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public ShortHeaderPacket CreateConnectionClosePacket(ErrorCode code, string reas
return packet;
}

public ShortHeaderPacket CreateDataPacket(UInt64 streamId, byte[] data)
public ShortHeaderPacket CreateDataPacket(UInt64 streamId, byte[] data, UInt64 offset)
{
ShortHeaderPacket packet = new ShortHeaderPacket();
packet.PacketNumber = _ns.Get();
packet.DestinationConnectionId = (byte)_peerConnectionId;
packet.AttachFrame(new StreamFrame(streamId, data, 0, true));
packet.AttachFrame(new StreamFrame(streamId, data, offset, true));

return packet;
}
Expand Down
6 changes: 5 additions & 1 deletion QuicNet/Streams/QuicStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class QuicStream
private QuicConnection _connection;
private UInt64 _maximumStreamData;
private UInt64 _currentTransferRate;
private UInt64 _sendOffset;

public StreamState State { get; set; }
public StreamType Type { get; set; }
Expand All @@ -41,6 +42,7 @@ public QuicStream(QuicConnection connection, StreamId streamId)

_maximumStreamData = QuicSettings.MaxStreamData;
_currentTransferRate = 0;
_sendOffset = 0;

_connection = connection;
}
Expand All @@ -52,10 +54,12 @@ public bool Send(byte[] data)

_connection.IncrementRate(data.Length);

ShortHeaderPacket packet = _connection.PacketCreator.CreateDataPacket(this.StreamId.IntegerValue, data);
ShortHeaderPacket packet = _connection.PacketCreator.CreateDataPacket(this.StreamId.IntegerValue, data, _sendOffset);
if (_connection.MaximumReached())
packet.AttachFrame(new StreamDataBlockedFrame(StreamId.IntegerValue, (UInt64)data.Length));

_sendOffset += (UInt64)data.Length;

return _connection.SendData(packet);
}

Expand Down

0 comments on commit efb916a

Please sign in to comment.