private Task ProcessRstStreamFrameAsync() { if (_currentHeadersStream != null) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId == 0) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 4) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 4), Http2ErrorCode.FRAME_SIZE_ERROR); } ThrowIfIncomingFrameSentToIdleStream(); if (_streams.TryGetValue(_incomingFrame.StreamId, out var stream)) { stream.Abort(error: null); } return(TaskHelpers.CompletedTask()); }
private Task ProcessPingFrameAsync() { if (_currentHeadersStream != null) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId != 0) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdNotZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 8) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 8), Http2ErrorCode.FRAME_SIZE_ERROR); } if ((_incomingFrame.PingFlags & Http2PingFrameFlags.ACK) == Http2PingFrameFlags.ACK) { // TODO: verify that payload is equal to the outgoing PING frame return(TaskHelpers.CompletedTask()); } return(_frameWriter.WritePingAsync(Http2PingFrameFlags.ACK, _incomingFrame.Payload)); }
private Task WriteAsync( ArraySegment <byte> buffer, CancellationToken cancellationToken) { var writableBuffer = default(PipeWriter); long bytesWritten = 0; lock (_contextLock) { if (_completed) { return(TaskHelpers.CompletedTask()); } writableBuffer = _pipeWriter; var writer = OutputWriter.Create(writableBuffer); if (buffer.Count > 0) { writer.Write(new ReadOnlySpan <byte>(buffer.Array, buffer.Offset, buffer.Count)); bytesWritten += buffer.Count; } writableBuffer.Commit(); } return(FlushAsync(writableBuffer, bytesWritten, cancellationToken)); }
internal protected virtual Task OnOpenAsync(TimeSpan timeout) { #if !FEATURE_NETNATIVE // Avoid Reflection in NET Native and rely on CoreCLR to catch this problem. // All product types are required to override this method Contract.Assert(String.IsNullOrEmpty(GetType().Namespace) || !GetType().Namespace.StartsWith("System.ServiceModel"), String.Format("Type '{0}' is required to override OnOpenAsync", GetType())); #endif // The code below executes only for custom CommunicationObjects because // all WCF product code is required to override OnOpenAsync() and not to call // this base implementation. // If we have already executed this code path, just return a completed Task. // This is a safeguard against product code that failed to override OnOpenAsync(). if (_onOpenAsyncCalled) { return(TaskHelpers.CompletedTask()); } _onOpenAsyncCalled = true; // External types cannot override this method because it is not public. // If the caller started this open synchronously, we must use the synchronous // methods they may have overridden, but we call then asynchronously. if (_isSynchronousOpen) { return(CallActionAsync <TimeSpan>(OnOpen, timeout)); } // This began as an asynchronous open, so just redirect this call to the APM path. return(Task.Factory.FromAsync(OnBeginOpen, OnEndOpen, timeout, TaskCreationOptions.RunContinuationsAsynchronously)); }
internal protected override Task OnOpenAsync(TimeSpan timeout) { PrepareOpen(); TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); CreateAndOpenTokenProviders(timeoutHelper.RemainingTime()); return(TaskHelpers.CompletedTask()); }
internal protected virtual Task OnOpenAsync(TimeSpan timeout) { // All WCF product types are required to override this method and not call base. // No external types will be able to reach here because it is not public. Contract.Assert(false, String.Format("Type '{0}' is required to override OnOpenAsync", GetType())); return(TaskHelpers.CompletedTask()); }
private Task ProcessUnknownFrameAsync() { if (_currentHeadersStream != null) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } return(TaskHelpers.CompletedTask()); }
public override Task StopAsync() { if (!_context.HasStartedConsumingRequestBody) { return(TaskHelpers.CompletedTask()); } _canceled = true; _context.Input.CancelPendingRead(); return(_pumpTask); }
private Task FlushAsync(PipeWriter writableBuffer, long bytesWritten, CancellationToken cancellationToken) { var awaitable = writableBuffer.FlushAsync(cancellationToken); if (awaitable.IsCompleted) { // The flush task can't fail today return(TaskHelpers.CompletedTask()); } return(FlushAsyncAwaited(awaitable, bytesWritten, cancellationToken)); }
private Task WriteChunkSizeAsync(int size) { if (size > 0) { int bytesEncoded = IntEncoder.Encode(size, _encodedSize, 0); return(base.Connection.WriteAsync(_encodedSize, 0, bytesEncoded, false, TimeSpan.FromMilliseconds(this.WriteTimeout))); } else { return(TaskHelpers.CompletedTask()); } }
private Task DecodeTrailersAsync(bool endHeaders, Span <byte> payload) { _hpackDecoder.Decode(payload, endHeaders, handler: this); if (endHeaders) { var endStreamTask = _currentHeadersStream.OnDataAsync(Constants.EmptyData, endStream: true); ResetRequestHeaderParsingState(); return(endStreamTask); } return(TaskHelpers.CompletedTask()); }
private Task ProcessGoAwayFrameAsync() { if (_currentHeadersStream != null) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId != 0) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdNotZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } StopProcessingNextRequest(); return(TaskHelpers.CompletedTask()); }
public Task WriteAsync <T>(Action <PipeWriter, T> callback, T state) { lock (_contextLock) { if (_completed) { return(TaskHelpers.CompletedTask()); } var buffer = _pipeWriter; callback(buffer, state); buffer.Commit(); } return(FlushAsync()); }
public virtual Task OpenAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(TaskHelpers.FromCancellation(cancellationToken)); } else { try { Open(); return(TaskHelpers.CompletedTask()); } catch (Exception e) { return(TaskHelpers.FromException(e)); } } }
internal protected virtual Task OnOpenAsync(TimeSpan timeout) { #if !FEATURE_NETNATIVE // Avoid Reflection in NET Native and rely on CoreCLR to catch this problem. // All product types are required to override this method Contract.Assert(String.IsNullOrEmpty(GetType().Namespace) || !GetType().Namespace.StartsWith("System.ServiceModel"), String.Format("Type '{0}' is required to override OnOpenAsync", GetType())); #endif // If we have already executed this code path, just return a completed Task. // It means this type did not override OnOpenAsync or OnBeginOpen. if (_onOpenAsyncCalled) { return(TaskHelpers.CompletedTask()); } // External types cannot override this method because it is not public. // Redirect this call to the APM path. _onOpenAsyncCalled = true; return(Task.Factory.FromAsync(OnBeginOpen, OnEndOpen, timeout, TaskCreationOptions.RunContinuationsAsynchronously)); }
private Task DecodeHeadersAsync <TContext>(IHttpApplication <TContext> application, bool endHeaders, Span <byte> payload) { try { _hpackDecoder.Decode(payload, endHeaders, handler: this); if (endHeaders) { StartStream(application); ResetRequestHeaderParsingState(); } } catch (Http2StreamErrorException ex) { Log.Http2StreamError(ConnectionId, ex); ResetRequestHeaderParsingState(); return(_frameWriter.WriteRstStreamAsync(ex.StreamId, ex.ErrorCode)); } return(TaskHelpers.CompletedTask()); }
private Task ProcessPriorityFrameAsync() { if (_currentHeadersStream != null) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.StreamId == 0) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamIdZero(_incomingFrame.Type), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.PriorityStreamDependency == _incomingFrame.StreamId) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorStreamSelfDependency(_incomingFrame.Type, _incomingFrame.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 5) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 5), Http2ErrorCode.FRAME_SIZE_ERROR); } return(TaskHelpers.CompletedTask()); }
private Task ProcessWindowUpdateFrameAsync() { if (_currentHeadersStream != null) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorHeadersInterleaved(_incomingFrame.Type, _incomingFrame.StreamId, _currentHeadersStream.StreamId), Http2ErrorCode.PROTOCOL_ERROR); } if (_incomingFrame.Length != 4) { throw new Http2ConnectionErrorException(CoreStrings.FormatHttp2ErrorUnexpectedFrameLength(_incomingFrame.Type, 4), Http2ErrorCode.FRAME_SIZE_ERROR); } ThrowIfIncomingFrameSentToIdleStream(); if (_incomingFrame.WindowUpdateSizeIncrement == 0) { // http://httpwg.org/specs/rfc7540.html#rfc.section.6.9 // A receiver MUST treat the receipt of a WINDOW_UPDATE // frame with an flow-control window increment of 0 as a // stream error (Section 5.4.2) of type PROTOCOL_ERROR; // errors on the connection flow-control window MUST be // treated as a connection error (Section 5.4.1). // // http://httpwg.org/specs/rfc7540.html#rfc.section.5.4.1 // An endpoint can end a connection at any time. In // particular, an endpoint MAY choose to treat a stream // error as a connection error. // // Since server initiated stream resets are not yet properly // implemented and tested, we treat all zero length window // increments as connection errors for now. throw new Http2ConnectionErrorException(CoreStrings.Http2ErrorWindowUpdateIncrementZero, Http2ErrorCode.PROTOCOL_ERROR); } return(TaskHelpers.CompletedTask()); }
protected internal override Task OnCloseAsync(TimeSpan timeout) { return(TaskHelpers.CompletedTask()); }
protected override Task OnConsumeAsync() => TaskHelpers.CompletedTask();
internal protected override Task OnOpenAsync(TimeSpan timeout) { PrepareOpen(); return(TaskHelpers.CompletedTask()); }
public virtual Task WriteMessageAsync(Message message, Stream stream) { WriteMessage(message, stream); return(TaskHelpers.CompletedTask()); }
public override Task StopAsync() => TaskHelpers.CompletedTask();
protected internal override Task OnOpenAsync(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); return(TaskHelpers.CompletedTask()); }
public override Task StopAsync() { _context.RequestBodyPipe.Reader.Complete(); _context.RequestBodyPipe.Writer.Complete(); return(TaskHelpers.CompletedTask()); }
public override Task ConsumeAsync() => TaskHelpers.CompletedTask();
internal protected virtual Task OnOpenAsync(TimeSpan timeout) { Contract.Requires(false, "OnOpenAsync needs to be implemented on derived classes"); return(TaskHelpers.CompletedTask()); }
protected internal override Task OnOpenAsync(TimeSpan timeout) { this.OnOpen(timeout); return(TaskHelpers.CompletedTask()); }
public override Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default(CancellationToken)) => TaskHelpers.CompletedTask();