From: David Fowler Date: Tue, 16 Jul 2019 17:35:33 +0000 (-0700) Subject: Change callbacks to virtual from being abstract (dotnet/corefx#39526) X-Git-Tag: submit/tizen/20210909.063632~11031^2~914 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd1e082130f7690687bac873da235355b9e658e5;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Change callbacks to virtual from being abstract (dotnet/corefx#39526) - Obsolete the callbacks as well Commit migrated from https://github.com/dotnet/corefx/commit/51cd78434953683040f93e69ed2a889e476f5cac --- diff --git a/src/libraries/System.IO.Pipelines/ref/System.IO.Pipelines.cs b/src/libraries/System.IO.Pipelines/ref/System.IO.Pipelines.cs index 58a5b39..08de47c 100644 --- a/src/libraries/System.IO.Pipelines/ref/System.IO.Pipelines.cs +++ b/src/libraries/System.IO.Pipelines/ref/System.IO.Pipelines.cs @@ -51,7 +51,8 @@ namespace System.IO.Pipelines public virtual System.Threading.Tasks.Task CopyToAsync(System.IO.Pipelines.PipeWriter destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.IO.Pipelines.PipeReader Create(System.IO.Stream stream, System.IO.Pipelines.StreamPipeReaderOptions readerOptions = null) { throw null; } - public abstract void OnWriterCompleted(System.Action callback, object state); + [System.Obsolete("OnWriterCompleted may not be invoked on all implementations of PipeReader. This will be removed in a future release.")] + public virtual void OnWriterCompleted(System.Action callback, object state) { } public abstract System.Threading.Tasks.ValueTask ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); public abstract bool TryRead(out System.IO.Pipelines.ReadResult result); } @@ -75,7 +76,8 @@ namespace System.IO.Pipelines public abstract System.Threading.Tasks.ValueTask FlushAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); public abstract System.Memory GetMemory(int sizeHint = 0); public abstract System.Span GetSpan(int sizeHint = 0); - public abstract void OnReaderCompleted(System.Action callback, object state); + [System.Obsolete("OnReaderCompleted may not be invoked on all implementations of PipeWriter. This will be removed in a future release.")] + public virtual void OnReaderCompleted(System.Action callback, object state) { } public virtual System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public readonly partial struct ReadResult diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeReader.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeReader.cs index f11b5db..2579397 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeReader.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeReader.cs @@ -34,7 +34,9 @@ namespace System.IO.Pipelines public override void Complete(Exception exception = null) => _pipe.CompleteReader(exception); +#pragma warning disable CS0672 // Member overrides obsolete member public override void OnWriterCompleted(Action callback, object state) => _pipe.OnWriterCompleted(callback, state); +#pragma warning restore CS0672 // Member overrides obsolete member public ValueTaskSourceStatus GetStatus(short token) => _pipe.GetReadAsyncStatus(); diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeWriter.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeWriter.cs index 5546eb8..94077bb 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeWriter.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeWriter.cs @@ -26,7 +26,9 @@ namespace System.IO.Pipelines public override void CancelPendingFlush() => _pipe.CancelPendingFlush(); +#pragma warning disable CS0672 // Member overrides obsolete member public override void OnReaderCompleted(Action callback, object state) => _pipe.OnReaderCompleted(callback, state); +#pragma warning restore CS0672 // Member overrides obsolete member public override ValueTask FlushAsync(CancellationToken cancellationToken = default) => _pipe.FlushAsync(cancellationToken); diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs index d3d6cd5..6dd5be2 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs @@ -100,7 +100,11 @@ namespace System.IO.Pipelines /// /// Registers a callback that gets executed when the side of the pipe is completed /// - public abstract void OnWriterCompleted(Action callback, object state); + [Obsolete("OnWriterCompleted may not be invoked on all implementations of PipeReader. This will be removed in a future release.")] + public virtual void OnWriterCompleted(Action callback, object state) + { + + } /// diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriter.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriter.cs index 3be0f29..960e257 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriter.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriter.cs @@ -46,7 +46,11 @@ namespace System.IO.Pipelines /// /// Registers a callback that gets executed when the side of the pipe is completed /// - public abstract void OnReaderCompleted(Action callback, object state); + [Obsolete("OnReaderCompleted may not be invoked on all implementations of PipeWriter. This will be removed in a future release.")] + public virtual void OnReaderCompleted(Action callback, object state) + { + + } /// /// Makes bytes written available to and runs continuation. diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs index 58e3e5c..340c13e 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs @@ -188,11 +188,6 @@ namespace System.IO.Pipelines } /// - public override void OnWriterCompleted(Action callback, object state) - { - } - - /// public override async ValueTask ReadAsync(CancellationToken cancellationToken = default) { // TODO ReadyAsync needs to throw if there are overlapping reads. diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs index f242874..dd81627 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs @@ -248,11 +248,6 @@ namespace System.IO.Pipelines } /// - public override void OnReaderCompleted(Action callback, object state) - { - } - - /// public override ValueTask FlushAsync(CancellationToken cancellationToken = default) { if (_bytesBuffered == 0) diff --git a/src/libraries/System.IO.Pipelines/tests/PipeCompletionCallbacksTests.cs b/src/libraries/System.IO.Pipelines/tests/PipeCompletionCallbacksTests.cs index 9a23b41..c56974b 100644 --- a/src/libraries/System.IO.Pipelines/tests/PipeCompletionCallbacksTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/PipeCompletionCallbacksTests.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Runtime.CompilerServices; using System.Threading.Tasks; using Xunit; diff --git a/src/libraries/System.IO.Pipelines/tests/PipePoolTests.cs b/src/libraries/System.IO.Pipelines/tests/PipePoolTests.cs index ce49a55..64c2b55 100644 --- a/src/libraries/System.IO.Pipelines/tests/PipePoolTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/PipePoolTests.cs @@ -184,7 +184,9 @@ namespace System.IO.Pipelines.Tests Assert.Equal(1, pool.CurrentlyRentedBlocks); +#pragma warning disable CS0618 // Type or member is obsolete pipe.Reader.OnWriterCompleted((exception, o) => Assert.Equal(0, pool.CurrentlyRentedBlocks), null); +#pragma warning restore CS0618 // Type or member is obsolete pipe.Reader.Complete(); pipe.Writer.Complete(); @@ -200,7 +202,9 @@ namespace System.IO.Pipelines.Tests Assert.Equal(1, pool.CurrentlyRentedBlocks); +#pragma warning disable CS0618 // Type or member is obsolete pipe.Writer.OnReaderCompleted((exception, o) => Assert.Equal(0, pool.CurrentlyRentedBlocks), null); +#pragma warning restore CS0618 // Type or member is obsolete pipe.Writer.Complete(); pipe.Reader.Complete(); diff --git a/src/libraries/System.IO.Pipelines/tests/PipeReaderStreamTests.nonnetstandard.cs b/src/libraries/System.IO.Pipelines/tests/PipeReaderStreamTests.nonnetstandard.cs index c3e2af1..0a94358 100644 --- a/src/libraries/System.IO.Pipelines/tests/PipeReaderStreamTests.nonnetstandard.cs +++ b/src/libraries/System.IO.Pipelines/tests/PipeReaderStreamTests.nonnetstandard.cs @@ -31,7 +31,9 @@ namespace System.IO.Pipelines.Tests } var readerCompletedTask = new TaskCompletionSource(); +#pragma warning disable CS0618 // Type or member is obsolete pipe.Writer.OnReaderCompleted(delegate { readerCompletedTask.SetResult(true); }, null); +#pragma warning restore CS0618 // Type or member is obsolete // Call Dispose{Async} multiple times; all should succeed. for (int i = 0; i < 2; i++) @@ -309,11 +311,6 @@ namespace System.IO.Pipelines.Tests throw new NotImplementedException(); } - public override void OnWriterCompleted(Action callback, object state) - { - throw new NotImplementedException(); - } - public override ValueTask ReadAsync(CancellationToken cancellationToken = default) { // Returns a ReadResult with no buffer and with IsCompleted and IsCancelled false @@ -332,7 +329,6 @@ namespace System.IO.Pipelines.Tests public override void AdvanceTo(SequencePosition consumed, SequencePosition examined) => throw new NotImplementedException(); public override void CancelPendingRead() => throw new NotImplementedException(); public override void Complete(Exception exception = null) => throw new NotImplementedException(); - public override void OnWriterCompleted(Action callback, object state) => throw new NotImplementedException(); public override ValueTask ReadAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); public override bool TryRead(out ReadResult result) => throw new NotImplementedException(); } @@ -362,11 +358,6 @@ namespace System.IO.Pipelines.Tests throw new NotImplementedException(); } - public override void OnWriterCompleted(Action callback, object state) - { - throw new NotImplementedException(); - } - public override ValueTask ReadAsync(CancellationToken cancellationToken = default) { ReadCalled = true; diff --git a/src/libraries/System.IO.Pipelines/tests/PipeWriterStreamTests.nonnetstandard.cs b/src/libraries/System.IO.Pipelines/tests/PipeWriterStreamTests.nonnetstandard.cs index bea4abd..e136a23 100644 --- a/src/libraries/System.IO.Pipelines/tests/PipeWriterStreamTests.nonnetstandard.cs +++ b/src/libraries/System.IO.Pipelines/tests/PipeWriterStreamTests.nonnetstandard.cs @@ -23,7 +23,9 @@ namespace System.IO.Pipelines.Tests Stream s = pipe.Writer.AsStream(); var writerCompletedTask = new TaskCompletionSource(); +#pragma warning disable CS0618 // Type or member is obsolete pipe.Reader.OnWriterCompleted(delegate { writerCompletedTask.SetResult(true); }, null); +#pragma warning restore CS0618 // Type or member is obsolete // Call Dispose{Async} multiple times; all should succeed. for (int i = 0; i < 2; i++) @@ -212,11 +214,6 @@ namespace System.IO.Pipelines.Tests throw new NotImplementedException(); } - public override void OnReaderCompleted(Action callback, object state) - { - throw new NotImplementedException(); - } - public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) { WriteAsyncCalled = true; @@ -236,7 +233,6 @@ namespace System.IO.Pipelines.Tests public override ValueTask FlushAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); public override Memory GetMemory(int sizeHint = 0) => throw new NotImplementedException(); public override Span GetSpan(int sizeHint = 0) => throw new NotImplementedException(); - public override void OnReaderCompleted(Action callback, object state) => throw new NotImplementedException(); } public static IEnumerable WriteCalls diff --git a/src/libraries/System.IO.Pipelines/tests/SchedulerFacts.cs b/src/libraries/System.IO.Pipelines/tests/SchedulerFacts.cs index 8312cb3..905b318 100644 --- a/src/libraries/System.IO.Pipelines/tests/SchedulerFacts.cs +++ b/src/libraries/System.IO.Pipelines/tests/SchedulerFacts.cs @@ -517,12 +517,14 @@ namespace System.IO.Pipelines.Tests Task reading = ExecuteOnNonThreadPoolThread(DoRead); PipeWriter buffer = pipe.Writer; +#pragma warning disable CS0618 // Type or member is obsolete pipe.Writer.OnReaderCompleted((state, exception) => { callbackRan = true; Assert.True(Thread.CurrentThread.IsThreadPoolThread); }, null); +#pragma warning restore CS0618 // Type or member is obsolete buffer.Write(Encoding.UTF8.GetBytes("Hello World")); await buffer.FlushAsync(); diff --git a/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs b/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs index 61359cd..c0ce8a3 100644 --- a/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs @@ -486,7 +486,9 @@ namespace System.IO.Pipelines.Tests { bool fired = false; PipeReader reader = PipeReader.Create(Stream.Null); +#pragma warning disable CS0618 // Type or member is obsolete reader.OnWriterCompleted((_, __) => { fired = true; }, null); +#pragma warning restore CS0618 // Type or member is obsolete reader.Complete(); Assert.False(fired); } diff --git a/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs b/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs index 555f3d8..e40d189 100644 --- a/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs @@ -511,7 +511,9 @@ namespace System.IO.Pipelines.Tests { bool fired = false; PipeWriter writer = PipeWriter.Create(Stream.Null); +#pragma warning disable CS0618 // Type or member is obsolete writer.OnReaderCompleted((_, __) => { fired = true; }, null); +#pragma warning restore CS0618 // Type or member is obsolete writer.Complete(); Assert.False(fired); }