/// <summary>
/// Opens the stream in current session.
/// </summary>
/// <param name="id">the stream id.</param>
/// <param name="headers">The S+M headers.</param>
/// <param name="isFinal">the final flag.</param>
/// <returns>The Stream.</returns>
private Http2Stream OpenStream(int id, ProtocolHeaders headers, bool isFinal)
{
if (id <= this.lastSeenStreamId)
{
this.End(StatusCode.ProtocolError);
return(null);
}
this.lastSeenStreamId = id;
// don't have to wait for stream opening
Http2Stream stream = new Http2Stream(id, this);
this.streams.Add(stream);
stream.OnClose += this.OnCloseStream;
if (IsServer)
{
stream.OpenServer(headers, isFinal);
// Settings must be sent for session once for session
if (stream.StreamId <= 2)
{
this.protocol.SendSettings(stream);
}
this.protocol.SendSynReply(stream);
}
else
{
stream.OpenClient(headers, isFinal);
}
if (this.OnStreamOpened != null)
{
this.OnStreamOpened(this, new StreamEventArgs(stream));
}
return(stream);
}