Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
ActiveStreams collection renamed to StreamDictionary
Browse files Browse the repository at this point in the history
Added Continuation frame handler
Update references
  • Loading branch information
vsemogutor committed Feb 11, 2014
1 parent cbe4ddb commit 61b6b85
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Microsoft.Http2.Protocol.FlowControl
internal class FlowControlManager
{
private readonly Http2Session _flowControlledSession;
private ActiveStreams _streamCollection;
private StreamDictionary _streamDictionary;
private Int32 _options;
private bool _wasFlowControlSet;
/// <summary>
Expand All @@ -47,7 +47,7 @@ public Int32 Options

if (!IsFlowControlEnabled)
{
foreach (var stream in _streamCollection.Values)
foreach (var stream in _streamDictionary.Values)
{
DisableStreamFlowControl(stream);
}
Expand Down Expand Up @@ -86,16 +86,16 @@ public FlowControlManager(Http2Session flowControlledSession)
StreamsInitialWindowSize = Constants.InitialFlowControlWindowSize;

_flowControlledSession = flowControlledSession;
_streamCollection = _flowControlledSession.ActiveStreams;
_streamDictionary = _flowControlledSession.StreamDictionary;

Options = Constants.InitialFlowControlOptionsValue;
_wasFlowControlSet = false;
IsSessionBlocked = false;
}

public void SetStreamsCollection(ActiveStreams streams)
public void SetStreamDictionary(StreamDictionary streams)
{
_streamCollection = streams;
_streamDictionary = streams;
}

/// <summary>
Expand All @@ -110,7 +110,7 @@ public bool IsStreamFlowControlled(Http2Stream stream)
if (stream == null)
throw new ArgumentNullException("stream is null");

return _streamCollection.IsStreamFlowControlled(stream);
return _streamDictionary.IsStreamFlowControlled(stream);
}

public void NewStreamOpenedHandler(Http2Stream stream)
Expand Down Expand Up @@ -139,7 +139,7 @@ public void DisableStreamFlowControl(Http2Stream stream)
if (stream == null)
throw new ArgumentNullException("stream is null");

_streamCollection.DisableFlowControl(stream);
_streamDictionary.DisableFlowControl(stream);
}

/// <summary>
Expand All @@ -153,12 +153,12 @@ public void DataFrameSentHandler(object sender, DataFrameSentEventArgs args)
int id = args.Id;

//Stream was closed after a data final frame.
if (!_streamCollection.ContainsKey(id))
if (!_streamDictionary.ContainsKey(id))
{
return;
}

var stream = _streamCollection[id];
var stream = _streamDictionary[id];
if (!stream.IsFlowControlEnabled)
{
return;
Expand Down
3 changes: 3 additions & 0 deletions src/Libraries/Microsoft.Http2.Protocol/Framing/FrameReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ private static Frame GetFrameType(Frame preamble)
case FrameType.Headers:
return new HeadersFrame(preamble);

case FrameType.Continuation:
return new ContinuationFrame(preamble);

case FrameType.WindowUpdate:
return new WindowUpdateFrame(preamble);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public partial class Http2Session : IDisposable
public event EventHandler<System.EventArgs> OnSessionDisposed;

/// <summary>
/// Gets the active streams.
/// Gets the stream dictionary.
/// </summary>
/// <value>
/// The active streams collection.
/// The stream dictionary.
/// </value>
internal ActiveStreams ActiveStreams { get; private set; }
internal StreamDictionary StreamDictionary { get; private set; }

/// <summary>
/// How many parallel streams can our endpoint support
Expand Down Expand Up @@ -170,18 +170,18 @@ public Http2Session(Stream stream, ConnectionEnd end,
_headersSequences = new HeadersSequenceList();
_promisedResources = new Dictionary<int, string>();

ActiveStreams = new ActiveStreams();
StreamDictionary = new StreamDictionary();
for (byte i = 0; i < OurMaxConcurrentStreams; i++)
{
var http2Stream = new Http2Stream(new HeadersList(), i + 1, _writeQueue, _flowControlManager)
{
Idle = true
};
ActiveStreams.Add(new KeyValuePair<int, Http2Stream>(i + 1, http2Stream));
StreamDictionary.Add(new KeyValuePair<int, Http2Stream>(i + 1, http2Stream));
}

_flowControlManager.SetStreamsCollection(ActiveStreams);
_writeQueue.SetActiveStreams(ActiveStreams);
_flowControlManager.SetStreamDictionary(StreamDictionary);
_writeQueue.SetStreamDictionary(StreamDictionary);
}

private void SendSessionHeader()
Expand Down Expand Up @@ -537,7 +537,7 @@ public Http2Stream CreateStream(HeadersList headers, int streamId, int priority
if (priority < 0 || priority > Constants.MaxPriority)
throw new ArgumentOutOfRangeException("priority is not between 0 and MaxPriority");

if (ActiveStreams.GetOpenedStreamsBy(_remoteEnd) + 1 > OurMaxConcurrentStreams)
if (StreamDictionary.GetOpenedStreamsBy(_remoteEnd) + 1 > OurMaxConcurrentStreams)
{
throw new MaxConcurrentStreamsLimitException();
}
Expand All @@ -548,7 +548,7 @@ public Http2Stream CreateStream(HeadersList headers, int streamId, int priority
var streamSequence = new HeadersSequence(streamId, (new HeadersFrame(streamId, priority){Headers = headers}));
_headersSequences.Add(streamSequence);

var stream = ActiveStreams[streamId];
var stream = StreamDictionary[streamId];

stream.OnFrameSent += (o, args) =>
{
Expand Down Expand Up @@ -582,7 +582,7 @@ internal Http2Stream CreateStream(HeadersSequence sequence)
if (sequence.Priority < 0 || sequence.Priority > Constants.MaxPriority)
throw new ArgumentOutOfRangeException("priority is not between 0 and MaxPriority");

if (ActiveStreams.GetOpenedStreamsBy(_remoteEnd) + 1 > OurMaxConcurrentStreams)
if (StreamDictionary.GetOpenedStreamsBy(_remoteEnd) + 1 > OurMaxConcurrentStreams)
{
throw new MaxConcurrentStreamsLimitException();
}
Expand All @@ -591,7 +591,7 @@ internal Http2Stream CreateStream(HeadersSequence sequence)
int priority = sequence.Priority;
var headers = sequence.Headers;

var stream = ActiveStreams[id];
var stream = StreamDictionary[id];

if (sequence.WasEndStreamReceived)
stream.HalfClosedLocal = sequence.WasEndStreamReceived;
Expand Down Expand Up @@ -641,12 +641,12 @@ public Http2Stream CreateStream(int priority)
if (priority < 0 || priority > Constants.MaxPriority)
throw new ArgumentOutOfRangeException("priority is not between 0 and MaxPriority");

if (ActiveStreams.GetOpenedStreamsBy(_ourEnd) + 1 > RemoteMaxConcurrentStreams)
if (StreamDictionary.GetOpenedStreamsBy(_ourEnd) + 1 > RemoteMaxConcurrentStreams)
{
throw new MaxConcurrentStreamsLimitException();
}
int nextId = GetNextId();
var stream = ActiveStreams[nextId];
var stream = StreamDictionary[nextId];

var streamSequence = new HeadersSequence(nextId, (new HeadersFrame(nextId, priority)));
_headersSequences.Add(streamSequence);
Expand Down Expand Up @@ -717,14 +717,14 @@ public void SendRequest(HeadersList pairs, int priority, bool isEndStream)
}

/// <summary>
/// Gets the stream from active streams.
/// Gets the stream from stream dictionary.
/// </summary>
/// <param name="id">The stream id.</param>
/// <returns></returns>
internal Http2Stream GetStream(int id)
{
Http2Stream stream;
if (!ActiveStreams.TryGetValue(id, out stream))
if (!StreamDictionary.TryGetValue(id, out stream))
{
return null;
}
Expand Down Expand Up @@ -821,7 +821,7 @@ private void Close(ResetStatusCode status)
_disposed = true;

// Dispose of all streams
foreach (var stream in ActiveStreams.Values)
foreach (var stream in StreamDictionary.Values)
{
//Cancel all opened streams
stream.Close(ResetStatusCode.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ streams. This does not prohibit a server from sending PUSH_PROMISE
int newInitWindowSize = settingsFrame[i].Value;
int windowSizeDiff = newInitWindowSize - _flowControlManager.StreamsInitialWindowSize;

foreach (var stream in ActiveStreams.FlowControlledStreams.Values)
foreach (var stream in StreamDictionary.FlowControlledStreams.Values)
{
stream.WindowSize += windowSizeDiff;
}
Expand Down Expand Up @@ -496,7 +496,7 @@ private void HandlePushPromiseFrame(PushPromiseFrame frame, out Http2Stream stre
// An endpoint
// that receives any frame after receiving a RST_STREAM MUST treat
// that as a stream error (Section 5.4.2) of type STREAM_CLOSED.
if (ActiveStreams[frame.StreamId].Closed)
if (StreamDictionary[frame.StreamId].Closed)
{
throw new Http2StreamNotFoundException(frame.StreamId);
}
Expand All @@ -512,7 +512,7 @@ private void HandlePushPromiseFrame(PushPromiseFrame frame, out Http2Stream stre
|| frame.PromisedStreamId == 0
|| (frame.PromisedStreamId % 2) != 0
|| frame.PromisedStreamId < _lastPromisedId
|| !((ActiveStreams[frame.StreamId].Opened || ActiveStreams[frame.StreamId].HalfClosedLocal)))
|| !((StreamDictionary[frame.StreamId].Opened || StreamDictionary[frame.StreamId].HalfClosedLocal)))
{
throw new ProtocolError(ResetStatusCode.ProtocolError, "Incorrect Promised Stream id");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/Microsoft.Http2.Protocol/IO/WriteQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal sealed class WriteQueue : IDisposable
private readonly Stream _stream;
private bool _disposed;
private readonly object _writeLock = new object();
private ActiveStreams _streams;
private StreamDictionary _streams;
private readonly ICompressionProcessor _proc;
public bool IsPriorityTurnedOn { get; private set; }

Expand Down Expand Up @@ -49,7 +49,7 @@ public WriteQueue(Stream stream, ICompressionProcessor processor, bool isPriorit
_disposed = false;
}

public void SetActiveStreams(ActiveStreams streams)
public void SetStreamDictionary(StreamDictionary streams)
{
_streams = streams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveStreams.cs" />
<Compile Include="StreamDictionary.cs" />
<Compile Include="CommonHeaders.cs" />
<Compile Include="Compression\HeadersDeltaCompression\CompressionProcessor\CompressionProcessor.cs" />
<Compile Include="Compression\HeadersDeltaCompression\CompressionProcessor\CompressionProcStaticTable.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ namespace Microsoft.Http2.Protocol
/// <summary>
/// This collection consists of two collection - flow controlled and nonflowcontrolled streams.
/// </summary>
internal class ActiveStreams : IDictionary<int, Http2Stream>
internal class StreamDictionary : IDictionary<int, Http2Stream>
{
/// <summary>
/// Collection enumerator class
/// </summary>
private class ActiveStreamsEnumerator : IEnumerator<KeyValuePair<int, Http2Stream>>
private class StreamDictionaryEnumerator : IEnumerator<KeyValuePair<int, Http2Stream>>
{
private readonly ActiveStreams _collection;
private readonly StreamDictionary _collection;
private KeyValuePair<int, Http2Stream> _curPair;
private Dictionary<int, Http2Stream>.Enumerator _nonControlledEnum;
private Dictionary<int, Http2Stream>.Enumerator _controlledEnum;

public ActiveStreamsEnumerator(ActiveStreams collection)
public StreamDictionaryEnumerator(StreamDictionary collection)
{
_collection = collection;
_curPair = default(KeyValuePair<int, Http2Stream>);
Expand Down Expand Up @@ -79,7 +79,7 @@ object IEnumerator.Current
public Dictionary<int, Http2Stream> NonFlowControlledStreams { get; private set; }
public Dictionary<int, Http2Stream> FlowControlledStreams { get; private set; }

public ActiveStreams()
public StreamDictionary()
{
NonFlowControlledStreams = new Dictionary<int, Http2Stream>();
FlowControlledStreams = new Dictionary<int, Http2Stream>();
Expand Down Expand Up @@ -258,7 +258,7 @@ public void DisableFlowControl(Http2Stream stream)

public IEnumerator<KeyValuePair<int, Http2Stream>> GetEnumerator()
{
return new ActiveStreamsEnumerator(this);
return new StreamDictionaryEnumerator(this);
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
4 changes: 2 additions & 2 deletions tests/Http2.Katana.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ public void PriorityTestSuccessful()
}

[StandardFact]
public void ActiveStreamsSuccessful()
public void StreamDictionarySuccessful()
{
var session = new Http2Session(Stream.Null, ConnectionEnd.Client, true, true, true, new CancellationToken());
var testCollection = session.ActiveStreams;
var testCollection = session.StreamDictionary;
var fm = new FlowControlManager(session);

testCollection[1] = new Http2Stream(null, 1, null, fm);
Expand Down
6 changes: 3 additions & 3 deletions tests/Http2.Katana.Tests/Http2.Katana.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<Compile Include="..\..\src\Libraries\Microsoft.Http2.Protocol\IO\ResponseStream.cs">
<Link>Sources\Libraries\Microsoft.Http2.Protocol\IO\ResponseStream.cs</Link>
</Compile>
<Compile Include="..\..\src\Libraries\Microsoft.Http2.Protocol\StreamDictionary.cs">
<Link>Sources\Libraries\Microsoft.Http2.Protocol\StreamDictionary.cs</Link>
</Compile>
<Compile Include="..\..\src\Libraries\Microsoft.Http2.Protocol\Verbs.cs">
<Link>Sources\Libraries\Microsoft.Http2.Protocol\Verbs.cs</Link>
</Compile>
Expand Down Expand Up @@ -402,9 +405,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResponseMiddleware.cs" />
<Compile Include="TestHelpers.cs" />
<Compile Include="..\..\src\Libraries\Microsoft.Http2.Protocol\ActiveStreams.cs">
<Link>Sources\Libraries\Microsoft.Http2.Protocol\ActiveStreams</Link>
</Compile>
<Compile Include="..\..\src\Libraries\Microsoft.Http2.Protocol\Compression\HeadersDeltaCompression\Indexation.cs">
<Link>Sources\Libraries\Microsoft.Http2.Protocol\Compression\HeadersDeltaCompression\Indexation</Link>
</Compile>
Expand Down

0 comments on commit 61b6b85

Please sign in to comment.