//Incoming internal Http2Stream(HeadersList headers, int id, WriteQueue writeQueue, FlowControlManager flowCrtlManager, ICompressionProcessor comprProc, Priority priority = Priority.Pri3) : this(id, writeQueue, flowCrtlManager, comprProc, priority) { Headers = headers; }
public WriteQueue(Stream stream, ICompressionProcessor processor, bool isPriorityTurnedOn) { if (stream == null) { throw new ArgumentNullException("io stream is null"); } //if (streams == null) // throw new ArgumentNullException("streams collection is null"); //Priorities are turned on for debugging IsPriorityTurnedOn = isPriorityTurnedOn; //_streams = streams; _proc = processor; if (IsPriorityTurnedOn) { _messageQueue = new PriorityQueue(); } else { _messageQueue = new QueueWrapper(); } _stream = stream; _disposed = false; }
//Incoming internal Http2Stream(List<Tuple<string, string, IAdditionalHeaderInfo>> headers, int id, WriteQueue writeQueue, FlowControlManager flowCrtlManager, ICompressionProcessor comprProc, Priority priority = Priority.Pri3) : this(id, writeQueue, flowCrtlManager, comprProc, priority) { Headers = headers; }
//Outgoing internal Http2Stream(int id, WriteQueue writeQueue, FlowControlManager flowCrtlManager, ICompressionProcessor comprProc, int priority = Constants.DefaultStreamPriority) { if (id <= 0) throw new ArgumentOutOfRangeException("invalid id for stream"); if (writeQueue == null || flowCrtlManager == null || comprProc == null) throw new ArgumentNullException("writeQueue or flowControlManager or compr proc is null"); if (priority < 0 || priority > Constants.MaxPriority) throw new ArgumentOutOfRangeException("priority out of range"); _id = id; Priority = priority; _writeQueue = writeQueue; _compressionProc = comprProc; _flowCrtlManager = flowCrtlManager; _unshippedFrames = new Queue<DataFrame>(16); Headers = new HeadersList(); SentDataAmount = 0; ReceivedDataAmount = 0; IsFlowControlBlocked = false; IsFlowControlEnabled = _flowCrtlManager.IsFlowControlEnabled; WindowSize = _flowCrtlManager.StreamsInitialWindowSize; _flowCrtlManager.NewStreamOpenedHandler(this); OnFrameSent += (sender, args) => FramesSent++; }
//Incoming internal Http2Stream(HeadersList headers, int id, WriteQueue writeQueue, FlowControlManager flowCrtlManager, ICompressionProcessor comprProc, int priority = Constants.DefaultStreamPriority) : this(id, writeQueue, flowCrtlManager, comprProc, priority) { if (headers == null) throw new ArgumentNullException("cannot create stream with null headers"); Headers = headers; }
public Http2Session(SecureSocket sessionSocket, ConnectionEnd end, bool usePriorities, bool useFlowControl, IDictionary<string, object> handshakeResult = null) { _ourEnd = end; _usePriorities = usePriorities; _useFlowControl = useFlowControl; _handshakeHeaders = new Dictionary<string, string>(16); ApplyHandshakeResults(handshakeResult); if (_ourEnd == ConnectionEnd.Client) { _remoteEnd = ConnectionEnd.Server; _lastId = -1; // Streams opened by client are odd } else { _remoteEnd = ConnectionEnd.Client; _lastId = 0; // Streams opened by server are even } _goAwayReceived = false; _settingsManager = new SettingsManager(); _comprProc = new CompressionProcessor(_ourEnd); _sessionSocket = sessionSocket; _frameReader = new FrameReader(_sessionSocket); ActiveStreams = new ActiveStreams(); _writeQueue = new WriteQueue(_sessionSocket, ActiveStreams, _usePriorities); if (_sessionSocket != null && sessionSocket.SecureProtocol == SecureProtocol.None) { OurMaxConcurrentStreams = int.Parse(_handshakeHeaders[":max_concurrent_streams"]); RemoteMaxConcurrentStreams = int.Parse(_handshakeHeaders[":max_concurrent_streams"]); InitialWindowSize = int.Parse(_handshakeHeaders[":initial_window_size"]); } else { OurMaxConcurrentStreams = 100; //Spec recommends value 100 by default RemoteMaxConcurrentStreams = 100; InitialWindowSize = 2000000; } _flowControlManager = new FlowControlManager(this); if (!_useFlowControl) { _flowControlManager.Options = (byte) FlowControlOptions.DontUseFlowControl; } SessionWindowSize = 0; _toBeContinuedHeaders = new HeadersList(); }
public Http2Session(SecureSocket sessionSocket, ConnectionEnd end, bool usePriorities, bool useFlowControl, IDictionary <string, object> handshakeResult = null) { _ourEnd = end; _usePriorities = usePriorities; _useFlowControl = useFlowControl; _handshakeHeaders = new Dictionary <string, string>(16); ApplyHandshakeResults(handshakeResult); if (_ourEnd == ConnectionEnd.Client) { _remoteEnd = ConnectionEnd.Server; _lastId = -1; // Streams opened by client are odd } else { _remoteEnd = ConnectionEnd.Client; _lastId = 0; // Streams opened by server are even } _goAwayReceived = false; _settingsManager = new SettingsManager(); _comprProc = new CompressionProcessor(_ourEnd); _sessionSocket = sessionSocket; _frameReader = new FrameReader(_sessionSocket); ActiveStreams = new ActiveStreams(); _writeQueue = new WriteQueue(_sessionSocket, ActiveStreams, _usePriorities); OurMaxConcurrentStreams = 100; //Spec recommends value 100 by default RemoteMaxConcurrentStreams = 100; _flowControlManager = new FlowControlManager(this); if (!_useFlowControl) { _flowControlManager.Options = (byte)FlowControlOptions.DontUseFlowControl; } SessionWindowSize = 0; }
//Outgoing internal Http2Stream(int id, WriteQueue writeQueue, FlowControlManager flowCrtlManager, ICompressionProcessor comprProc, Priority priority = Priority.Pri3) { _id = id; Priority = priority; _writeQueue = writeQueue; _compressionProc = comprProc; _flowCrtlManager = flowCrtlManager; _unshippedFrames = new Queue <DataFrame>(16); SentDataAmount = 0; ReceivedDataAmount = 0; IsFlowControlBlocked = false; IsFlowControlEnabled = _flowCrtlManager.IsStreamsFlowControlledEnabled; WindowSize = _flowCrtlManager.StreamsInitialWindowSize; _flowCrtlManager.NewStreamOpenedHandler(this); }
//Outgoing internal Http2Stream(int id, WriteQueue writeQueue, FlowControlManager flowCrtlManager, ICompressionProcessor comprProc, Priority priority = Priority.Pri3) { _id = id; Priority = priority; _writeQueue = writeQueue; _compressionProc = comprProc; _flowCrtlManager = flowCrtlManager; _unshippedFrames = new Queue<DataFrame>(16); SentDataAmount = 0; ReceivedDataAmount = 0; IsFlowControlBlocked = false; IsFlowControlEnabled = _flowCrtlManager.IsStreamsFlowControlledEnabled; WindowSize = _flowCrtlManager.StreamsInitialWindowSize; _flowCrtlManager.NewStreamOpenedHandler(this); }
public WriteQueue(Stream stream, ActiveStreams streams, ICompressionProcessor processor, bool isPriorityTurnedOn) { if (stream == null) throw new ArgumentNullException("io stream is null"); if (streams == null) throw new ArgumentNullException("streams collection is null"); //Priorities are turned on for debugging IsPriorityTurnedOn = isPriorityTurnedOn; _streams = streams; _proc = processor; if (IsPriorityTurnedOn) { _messageQueue = new PriorityQueue(); } else { _messageQueue = new QueueWrapper(); } _stream = stream; _disposed = false; }
private void Close(ResetStatusCode status) { if (_disposed) return; Http2Logger.LogDebug("Session closing"); _disposed = true; // Dispose of all streams foreach (var stream in ActiveStreams.Values) { //Cancel all opened streams stream.Dispose(ResetStatusCode.Cancel); } if (!_goAwayReceived) WriteGoAway(status); OnSettingsSent = null; OnFrameReceived = null; //Missing GoAway means connection was forcibly closed by the remote ep. This means that we can //send nothing into this connection. No need trying to send GoAway. //Hence we may not check for !_goAwayReceived if (_writeQueue != null) { _writeQueue.Flush(); _writeQueue.Dispose(); } if (_frameReader != null) { _frameReader.Dispose(); _frameReader = null; } if (_comprProc != null) { _comprProc.Dispose(); _comprProc = null; } if (_ioStream != null) { _ioStream.Close(); _ioStream = null; } if (_pingReceived != null) { _pingReceived.Dispose(); _pingReceived = null; } if (_settingsAckReceived != null) { _settingsAckReceived.Dispose(); _settingsAckReceived = null; } if (OnSessionDisposed != null) { OnSessionDisposed(this, null); } OnSessionDisposed = null; Http2Logger.LogDebug("Session closed"); }
public Http2Session(Stream stream, ConnectionEnd end, bool usePriorities, bool useFlowControl, bool isSecure, CancellationToken cancel, int initialWindowSize = Constants.InitialFlowControlWindowSize, int maxConcurrentStreams = Constants.DefaultMaxConcurrentStreams) { if (stream == null) throw new ArgumentNullException("stream is null"); if (cancel == null) throw new ArgumentNullException("cancellation token is null"); if (maxConcurrentStreams <= 0) throw new ArgumentOutOfRangeException("maxConcurrentStreams cant be less or equal then 0"); if (initialWindowSize <= 0 && useFlowControl) throw new ArgumentOutOfRangeException("initialWindowSize cant be less or equal then 0"); _ourEnd = end; _usePriorities = usePriorities; _useFlowControl = useFlowControl; _isSecure = isSecure; _cancelSessionToken = cancel; if (_ourEnd == ConnectionEnd.Client) { _remoteEnd = ConnectionEnd.Server; _lastId = -1; // Streams opened by client are odd //if we got unsecure connection then server will respond with id == 1. We cant initiate //new stream with id == 1. if (!(stream is SslStream)) { _lastId = 3; } } else { _remoteEnd = ConnectionEnd.Client; _lastId = 0; // Streams opened by server are even } _goAwayReceived = false; _comprProc = new CompressionProcessor(_ourEnd); _ioStream = stream; _frameReader = new FrameReader(_ioStream); ActiveStreams = new ActiveStreams(); _writeQueue = new WriteQueue(_ioStream, ActiveStreams, _comprProc, _usePriorities); OurMaxConcurrentStreams = maxConcurrentStreams; RemoteMaxConcurrentStreams = maxConcurrentStreams; InitialWindowSize = initialWindowSize; _flowControlManager = new FlowControlManager(this); if (!_useFlowControl) { _flowControlManager.Options = (byte) FlowControlOptions.DontUseFlowControl; } SessionWindowSize = 0; _headersSequences = new HeadersSequenceList(); _promisedResources = new Dictionary<int, string>(); }
private void Close(ResetStatusCode status) { if (_disposed) return; Http2Logger.LogDebug("Session closing"); _disposed = true; // Dispose of all streams foreach (var stream in StreamDictionary.Values) { //Cancel all opened streams stream.Close(ResetStatusCode.None); } if (!_goAwayReceived) { WriteGoAway(status); //TODO fix delay. wait for goAway send and then dispose WriteQueue //Wait for GoAway send using (var goAwayDelay = new ManualResetEvent(false)) { goAwayDelay.WaitOne(500); } } OnSettingsSent = null; OnFrameReceived = null; if (_frameReader != null) { _frameReader.Dispose(); _frameReader = null; } if (_writeQueue != null) { _writeQueue.Flush(); _writeQueue.Dispose(); } if (_comprProc != null) { _comprProc.Dispose(); _comprProc = null; } if (_ioStream != null) { _ioStream.Close(); _ioStream = null; } if (_pingReceived != null) { _pingReceived.Dispose(); _pingReceived = null; } if (_settingsAckReceived != null) { _settingsAckReceived.Dispose(); _settingsAckReceived = null; } if (OnSessionDisposed != null) { OnSessionDisposed(this, null); } OnSessionDisposed = null; Http2Logger.LogDebug("Session closed"); }
private void Close(ResetStatusCode status) { if (_disposed) { return; } Http2Logger.LogDebug("Session closing"); _disposed = true; // Dispose of all streams foreach (var stream in StreamDictionary.Values) { //Cancel all opened streams stream.Close(ResetStatusCode.None); } if (!_goAwayReceived) { WriteGoAway(status); //TODO fix delay. wait for goAway send and then dispose WriteQueue //Wait for GoAway send using (var goAwayDelay = new ManualResetEvent(false)) { goAwayDelay.WaitOne(500); } } OnSettingsSent = null; OnFrameReceived = null; if (_frameReader != null) { _frameReader.Dispose(); _frameReader = null; } if (_writeQueue != null) { _writeQueue.Flush(); _writeQueue.Dispose(); } if (_comprProc != null) { _comprProc.Dispose(); _comprProc = null; } if (_ioStream != null) { _ioStream.Close(); _ioStream = null; } if (_pingReceived != null) { _pingReceived.Dispose(); _pingReceived = null; } if (_settingsAckReceived != null) { _settingsAckReceived.Dispose(); _settingsAckReceived = null; } if (OnSessionDisposed != null) { OnSessionDisposed(this, null); } OnSessionDisposed = null; Http2Logger.LogDebug("Session closed"); }
public Http2Session(Stream stream, ConnectionEnd end, bool usePriorities, bool useFlowControl, bool isSecure, CancellationToken cancel, int initialWindowSize = Constants.InitialFlowControlWindowSize, int maxConcurrentStreams = Constants.DefaultMaxConcurrentStreams) { if (stream == null) { throw new ArgumentNullException("stream is null"); } if (cancel == null) { throw new ArgumentNullException("cancellation token is null"); } if (maxConcurrentStreams <= 0) { throw new ArgumentOutOfRangeException("maxConcurrentStreams cant be less or equal then 0"); } if (initialWindowSize <= 0 && useFlowControl) { throw new ArgumentOutOfRangeException("initialWindowSize cant be less or equal then 0"); } _ourEnd = end; _usePriorities = usePriorities; _useFlowControl = useFlowControl; _isSecure = isSecure; _cancelSessionToken = cancel; if (_ourEnd == ConnectionEnd.Client) { _remoteEnd = ConnectionEnd.Server; _lastId = -1; // Streams opened by client are odd //if we got unsecure connection then server will respond with id == 1. We cant initiate //new stream with id == 1. if (!(stream is SslStream)) { _lastId = 3; } } else { _remoteEnd = ConnectionEnd.Client; _lastId = 0; // Streams opened by server are even } _goAwayReceived = false; _comprProc = new CompressionProcessor(); _ioStream = stream; _frameReader = new FrameReader(_ioStream); _writeQueue = new WriteQueue(_ioStream, _comprProc, _usePriorities); OurMaxConcurrentStreams = maxConcurrentStreams; RemoteMaxConcurrentStreams = maxConcurrentStreams; InitialWindowSize = initialWindowSize; _flowControlManager = new FlowControlManager(this); if (!_useFlowControl) { _flowControlManager.Options = (byte)FlowControlOptions.DontUseFlowControl; } SessionWindowSize = 0; _headersSequences = new HeadersSequenceList(); _promisedResources = new Dictionary <int, string>(); StreamDictionary = new StreamDictionary(); for (byte i = 0; i < OurMaxConcurrentStreams; i++) { var http2Stream = new Http2Stream(new HeadersList(), i + 1, _writeQueue, _flowControlManager) { Idle = true }; StreamDictionary.Add(new KeyValuePair <int, Http2Stream>(i + 1, http2Stream)); } _flowControlManager.SetStreamDictionary(StreamDictionary); _writeQueue.SetStreamDictionary(StreamDictionary); }