public void OnInputOrOutputCompleted() { lock (_stateLock) { if (_state != Http2ConnectionState.Closed) { _frameWriter.WriteGoAwayAsync(_highestOpenedStreamId, Http2ErrorCode.NO_ERROR); UpdateState(Http2ConnectionState.Closed); } } _frameWriter.Complete(); }
public void OnInputOrOutputCompleted() { _stopping = true; _frameWriter.Complete(); }
public async Task ProcessRequestsAsync <TContext>(IHttpApplication <TContext> application) { Exception error = null; var errorCode = Http2ErrorCode.NO_ERROR; try { ValidateTlsRequirements(); if (!await TryReadPrefaceAsync()) { return; } if (!_stopping) { await _frameWriter.WriteSettingsAsync(_serverSettings); } while (!_stopping) { var result = await Input.ReadAsync(); var readableBuffer = result.Buffer; var consumed = readableBuffer.Start; var examined = readableBuffer.End; try { if (!readableBuffer.IsEmpty) { if (Http2FrameReader.ReadFrame(readableBuffer, _incomingFrame, _serverSettings.MaxFrameSize, out consumed, out examined)) { Log.LogTrace($"Connection id {ConnectionId} received {_incomingFrame.Type} frame with flags 0x{_incomingFrame.Flags:x} and length {_incomingFrame.Length} for stream ID {_incomingFrame.StreamId}"); await ProcessFrameAsync <TContext>(application); } } else if (result.IsCompleted) { return; } } finally { Input.AdvanceTo(consumed, examined); } } } catch (ConnectionResetException ex) { // Don't log ECONNRESET errors when there are no active streams on the connection. Browsers like IE will reset connections regularly. if (_streams.Count > 0) { Log.RequestProcessingError(ConnectionId, ex); } error = ex; } catch (Http2ConnectionErrorException ex) { Log.Http2ConnectionError(ConnectionId, ex); error = ex; errorCode = ex.ErrorCode; } catch (HPackDecodingException ex) { Log.HPackDecodingError(ConnectionId, _currentHeadersStream.StreamId, ex); error = ex; errorCode = Http2ErrorCode.COMPRESSION_ERROR; } catch (Exception ex) { error = ex; errorCode = Http2ErrorCode.INTERNAL_ERROR; throw; } finally { try { foreach (var stream in _streams.Values) { stream.Http2Abort(error); } await _frameWriter.WriteGoAwayAsync(_highestOpenedStreamId, errorCode); _frameWriter.Complete(); } finally { Input.Complete(); _frameWriter.Abort(ex: null); } } }