From 6387a9eb56098a889021190747d31f07246dd9f2 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 24 Feb 2023 11:59:28 -0500 Subject: [PATCH] Add and use public TaskToAsyncResult helper type (#82557) * Add and use public TaskToAsyncResult helper type * Disable thread blocking test on browser --- .../Common/src/System/IO/ReadOnlyMemoryStream.cs | 4 +- .../Common/src/System/Threading/Tasks/TaskToApm.cs | 133 ---------------- .../System/Threading/Tasks/TaskToAsyncResult.cs | 171 +++++++++++++++++++++ src/libraries/Common/tests/Common.Tests.csproj | 2 - .../StreamConformanceTests.csproj | 1 - .../Compression/CompressionStreamUnitTestBase.cs | 8 +- .../Common/tests/System/IO/ConnectedStreams.cs | 16 +- .../Common/tests/System/IO/DelayStream.cs | 8 +- .../src/System.IO.Compression.Brotli.csproj | 4 +- .../IO/Compression/dec/BrotliStream.Decompress.cs | 4 +- .../IO/Compression/enc/BrotliStream.Compress.cs | 4 +- .../System.IO.Compression.Brotli.Tests.csproj | 2 - .../src/System.IO.Compression.csproj | 2 - .../DeflateManaged/DeflateManagedStream.cs | 4 +- .../IO/Compression/DeflateZLib/DeflateStream.cs | 8 +- .../src/System/IO/Compression/GZipStream.cs | 4 +- .../tests/System.IO.Compression.Tests.csproj | 1 - .../src/System.IO.Pipelines.csproj | 6 +- .../src/System/IO/Pipelines/PipeReaderStream.cs | 4 +- .../src/System/IO/Pipelines/PipeWriterStream.cs | 4 +- .../System.IO.Pipes/src/System.IO.Pipes.csproj | 2 - .../src/System/IO/Pipes/NamedPipeServerStream.cs | 4 +- .../src/System/IO/Pipes/PipeStream.Unix.cs | 8 +- .../src/System/IO/Pipes/PipeStream.Windows.cs | 8 +- .../System.IO.Ports/src/System.IO.Ports.csproj | 6 +- .../src/System/IO/Ports/SerialStream.Unix.cs | 6 +- .../System.IO/tests/System.IO.Tests.csproj | 1 - .../src/System.Memory.Data.csproj | 5 +- .../src/System.Net.Http.WinHttpHandler.csproj | 6 +- .../src/System/Net/Http/WinHttpRequestStream.cs | 4 +- .../src/System/Net/Http/WinHttpResponseStream.cs | 4 +- ...ystem.Net.Http.WinHttpHandler.Unit.Tests.csproj | 2 - .../System.Net.Http/src/System.Net.Http.csproj | 6 - .../src/System/Net/Http/HttpBaseStream.cs | 8 +- .../src/System/Net/Http/HttpContent.cs | 4 +- .../src/System/Net/Http/MultipartContent.cs | 4 +- .../System.Net.Http.Functional.Tests.csproj | 2 - .../UnitTests/System.Net.Http.Unit.Tests.csproj | 2 - .../src/System.Net.HttpListener.csproj | 2 - .../src/System.Net.NameResolution.csproj | 2 - .../src/System/Net/Dns.cs | 25 ++- .../src/System.Net.NetworkInformation.csproj | 3 +- .../NetworkInformation/SystemIPGlobalProperties.cs | 4 +- .../NetworkInformation/UnixIPGlobalProperties.cs | 4 +- .../System.Net.Quic/src/System.Net.Quic.csproj | 1 - .../src/System/Net/Quic/QuicStream.Stream.cs | 8 +- .../System.Net.Quic.Functional.Tests.csproj | 1 - .../src/System.Net.Requests.csproj | 2 - .../src/System/Net/FileWebRequest.cs | 8 +- .../src/System.Net.Security.csproj | 2 - .../src/System/Net/Security/NegotiateStream.cs | 16 +- .../src/System/Net/Security/SslStream.cs | 20 +-- .../System.Net.Security.Enterprise.Tests.csproj | 4 +- .../System.Net.Security.Tests.csproj | 2 - .../tests/FunctionalTests/result.txt | Bin 42566 -> 0 bytes .../System.Net.Security.Unit.Tests.csproj | 2 - .../src/System.Net.Sockets.csproj | 2 - .../src/System/Net/Sockets/Socket.cs | 64 ++++---- .../src/System/Net/Sockets/TCPListener.cs | 6 +- .../System.Net.Sockets.Tests.csproj | 2 - .../src/System.Private.CoreLib.Shared.projitems | 4 +- .../src/System/IO/BufferedStream.cs | 8 +- .../IO/Strategies/BufferedFileStreamStrategy.cs | 8 +- .../System/IO/Strategies/OSFileStreamStrategy.cs | 8 +- .../System.Private.CoreLib/src/System/IO/Stream.cs | 8 +- .../src/System/Text/TranscodingStream.cs | 8 +- src/libraries/System.Runtime/ref/System.Runtime.cs | 10 +- .../src/System.Security.Cryptography.csproj | 4 +- .../System/Security/Cryptography/CryptoStream.cs | 8 +- .../System.Security.Cryptography.Tests.csproj | 2 - .../tests/System.Text.Encoding.Tests.csproj | 3 +- .../tests/System.Threading.Tasks.Tests.csproj | 1 + .../tests/TaskToAsyncResultTests.cs | 164 ++++++++++++++++++++ src/mono/mono/tests/threadpool-exceptions8.cs | 2 +- 74 files changed, 524 insertions(+), 366 deletions(-) delete mode 100644 src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs create mode 100644 src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs delete mode 100644 src/libraries/System.Net.Security/tests/FunctionalTests/result.txt create mode 100644 src/libraries/System.Threading.Tasks/tests/TaskToAsyncResultTests.cs diff --git a/src/libraries/Common/src/System/IO/ReadOnlyMemoryStream.cs b/src/libraries/Common/src/System/IO/ReadOnlyMemoryStream.cs index 5e73fd5..8bc8320 100644 --- a/src/libraries/Common/src/System/IO/ReadOnlyMemoryStream.cs +++ b/src/libraries/Common/src/System/IO/ReadOnlyMemoryStream.cs @@ -143,12 +143,12 @@ namespace System.IO #endif public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), callback, state); public override int EndRead(IAsyncResult asyncResult) { EnsureNotClosed(); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } #if !NETFRAMEWORK && !NETSTANDARD2_0 diff --git a/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs b/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs deleted file mode 100644 index a308e1d..0000000 --- a/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Helper methods for using Tasks to implement the APM pattern. -// -// Example usage, wrapping a Task-returning FooAsync method with Begin/EndFoo methods: -// -// public IAsyncResult BeginFoo(..., AsyncCallback? callback, object? state) => -// TaskToApm.Begin(FooAsync(...), callback, state); -// -// public int EndFoo(IAsyncResult asyncResult) => -// TaskToApm.End(asyncResult); - -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace System.Threading.Tasks -{ - /// - /// Provides support for efficiently using Tasks to implement the APM (Begin/End) pattern. - /// - internal static class TaskToApm - { - /// - /// Marshals the Task as an IAsyncResult, using the supplied callback and state - /// to implement the APM pattern. - /// - /// The Task to be marshaled. - /// The callback to be invoked upon completion. - /// The state to be stored in the IAsyncResult. - /// An IAsyncResult to represent the task's asynchronous operation. - public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state) => - new TaskAsyncResult(task, state, callback); - - /// Processes an IAsyncResult returned by Begin. - /// The IAsyncResult to unwrap. - public static void End(IAsyncResult asyncResult) - { - if (GetTask(asyncResult) is Task t) - { - t.GetAwaiter().GetResult(); - return; - } - - ThrowArgumentException(asyncResult); - } - - /// Processes an IAsyncResult returned by Begin. - /// The IAsyncResult to unwrap. - public static TResult End(IAsyncResult asyncResult) - { - if (GetTask(asyncResult) is Task task) - { - return task.GetAwaiter().GetResult(); - } - - ThrowArgumentException(asyncResult); - return default!; // unreachable - } - - /// Gets the task represented by the IAsyncResult. - public static Task? GetTask(IAsyncResult asyncResult) => (asyncResult as TaskAsyncResult)?._task; - - /// Throws an argument exception for the invalid . - [DoesNotReturn] - private static void ThrowArgumentException(IAsyncResult asyncResult) - { - throw asyncResult is null ? - new ArgumentNullException(nameof(asyncResult)) : - new ArgumentException(null, nameof(asyncResult)); - } - - /// Provides a simple IAsyncResult that wraps a Task. - /// - /// We could use the Task as the IAsyncResult if the Task's AsyncState is the same as the object state, - /// but that's very rare, in particular in a situation where someone cares about allocation, and always - /// using TaskAsyncResult simplifies things and enables additional optimizations. - /// - internal sealed class TaskAsyncResult : IAsyncResult - { - /// The wrapped Task. - internal readonly Task _task; - /// Callback to invoke when the wrapped task completes. - private readonly AsyncCallback? _callback; - - /// Initializes the IAsyncResult with the Task to wrap and the associated object state. - /// The Task to wrap. - /// The new AsyncState value. - /// Callback to invoke when the wrapped task completes. - internal TaskAsyncResult(Task task, object? state, AsyncCallback? callback) - { - Debug.Assert(task != null); - _task = task; - AsyncState = state; - - if (task.IsCompleted) - { - // Synchronous completion. Invoke the callback. No need to store it. - CompletedSynchronously = true; - callback?.Invoke(this); - } - else if (callback != null) - { - // Asynchronous completion, and we have a callback; schedule it. We use OnCompleted rather than ContinueWith in - // order to avoid running synchronously if the task has already completed by the time we get here but still run - // synchronously as part of the task's completion if the task completes after (the more common case). - _callback = callback; - _task.ConfigureAwait(continueOnCapturedContext: false) - .GetAwaiter() - .OnCompleted(InvokeCallback); // allocates a delegate, but avoids a closure - } - } - - /// Invokes the callback. - private void InvokeCallback() - { - Debug.Assert(!CompletedSynchronously); - Debug.Assert(_callback != null); - _callback.Invoke(this); - } - - /// Gets a user-defined object that qualifies or contains information about an asynchronous operation. - public object? AsyncState { get; } - /// Gets a value that indicates whether the asynchronous operation completed synchronously. - /// This is set lazily based on whether the has completed by the time this object is created. - public bool CompletedSynchronously { get; } - /// Gets a value that indicates whether the asynchronous operation has completed. - public bool IsCompleted => _task.IsCompleted; - /// Gets a that is used to wait for an asynchronous operation to complete. - public WaitHandle AsyncWaitHandle => ((IAsyncResult)_task).AsyncWaitHandle; - } - } -} diff --git a/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs b/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs new file mode 100644 index 0000000..fdfd25e --- /dev/null +++ b/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs @@ -0,0 +1,171 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics; + +namespace System.Threading.Tasks +{ + /// + /// Provides methods for using to implement the Asynchronous Programming Model + /// pattern based on "Begin" and "End" methods. + /// +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + static class TaskToAsyncResult + { + /// Creates a new from the specified , optionally invoking when the task has completed. + /// The to be wrapped in an . + /// The callback to be invoked upon 's completion. If , no callback will be invoked. + /// The state to be stored in the . + /// An to represent the task's asynchronous operation. This instance will also be passed to when it's invoked. + /// is null. + /// + /// In conjunction with the or methods, this method may be used + /// to implement the Begin/End pattern (also known as the Asynchronous Programming Model pattern, or APM). It is recommended to not expose this pattern + /// in new code; the methods on are intended only to help implement such Begin/End methods when they must be exposed, for example + /// because a base class provides virtual methods for the pattern, or when they've already been exposed and must remain for compatibility. These methods enable + /// implementing all of the core asynchronous logic via s and then easily implementing Begin/End methods around that functionality. + /// + public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state) + { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(task); +#else + if (task is null) + { + throw new ArgumentNullException(nameof(task)); + } +#endif + + return new TaskAsyncResult(task, state, callback); + } + + /// Waits for the wrapped by the returned by to complete. + /// The for which to wait. + /// is null. + /// was not produced by a call to . + /// This will propagate any exception stored in the wrapped . + public static void End(IAsyncResult asyncResult) => + Unwrap(asyncResult).GetAwaiter().GetResult(); + + /// Waits for the wrapped by the returned by to complete. + /// The for which to wait. + /// The result of the wrapped by the . + /// is null. + /// was not produced by a call to . + /// This will propagate any exception stored in the wrapped . + public static TResult End(IAsyncResult asyncResult) => + Unwrap(asyncResult).GetAwaiter().GetResult(); + + /// Extracts the underlying from an created by . + /// The created by . + /// The wrapped by the . + /// is null. + /// was not produced by a call to . + public static Task Unwrap(IAsyncResult asyncResult) + { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(asyncResult); +#else + if (asyncResult is null) + { + throw new ArgumentNullException(nameof(asyncResult)); + } +#endif + + if ((asyncResult as TaskAsyncResult)?._task is not Task task) + { + throw new ArgumentException(null, nameof(asyncResult)); + } + + return task; + } + + /// Extracts the underlying from an created by . + /// The created by . + /// The wrapped by the . + /// is null. + /// + /// was not produced by a call to , + /// or the provided to was used a generic type parameter + /// that's different from the supplied to this call. + /// + public static Task Unwrap(IAsyncResult asyncResult) + { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(asyncResult); +#else + if (asyncResult is null) + { + throw new ArgumentNullException(nameof(asyncResult)); + } +#endif + + if ((asyncResult as TaskAsyncResult)?._task is not Task task) + { + throw new ArgumentException(null, nameof(asyncResult)); + } + + return task; + } + + /// Provides a simple that wraps a . + /// + /// We could use the Task as the IAsyncResult if the Task's AsyncState is the same as the object state, + /// but that's very rare, in particular in a situation where someone cares about allocation, and always + /// using TaskAsyncResult simplifies things and enables additional optimizations. + /// + private sealed class TaskAsyncResult : IAsyncResult + { + /// The wrapped Task. + internal readonly Task _task; + /// Callback to invoke when the wrapped task completes. + private readonly AsyncCallback? _callback; + + /// Initializes the IAsyncResult with the Task to wrap and the associated object state. + /// The Task to wrap. + /// The new AsyncState value. + /// Callback to invoke when the wrapped task completes. + internal TaskAsyncResult(Task task, object? state, AsyncCallback? callback) + { + Debug.Assert(task is not null); + + _task = task; + AsyncState = state; + + if (task.IsCompleted) + { + // The task has already completed. Treat this as synchronous completion. + // Invoke the callback; no need to store it. + CompletedSynchronously = true; + callback?.Invoke(this); + } + else if (callback is not null) + { + // Asynchronous completion, and we have a callback; schedule it. We use OnCompleted rather than ContinueWith in + // order to avoid running synchronously if the task has already completed by the time we get here but still run + // synchronously as part of the task's completion if the task completes after (the more common case). + _callback = callback; + _task.ConfigureAwait(continueOnCapturedContext: false) + .GetAwaiter() + .OnCompleted(() => _callback.Invoke(this)); + } + } + + /// + public object? AsyncState { get; } + + /// + public bool CompletedSynchronously { get; } + + /// + public bool IsCompleted => _task.IsCompleted; + + /// + public WaitHandle AsyncWaitHandle => ((IAsyncResult)_task).AsyncWaitHandle; + } + } +} diff --git a/src/libraries/Common/tests/Common.Tests.csproj b/src/libraries/Common/tests/Common.Tests.csproj index 372048c..5ed2a1e 100644 --- a/src/libraries/Common/tests/Common.Tests.csproj +++ b/src/libraries/Common/tests/Common.Tests.csproj @@ -100,8 +100,6 @@ Link="System\Net\Sockets\Fletcher32.cs" /> - diff --git a/src/libraries/Common/tests/StreamConformanceTests/StreamConformanceTests.csproj b/src/libraries/Common/tests/StreamConformanceTests/StreamConformanceTests.csproj index 5514898..eebde98 100644 --- a/src/libraries/Common/tests/StreamConformanceTests/StreamConformanceTests.csproj +++ b/src/libraries/Common/tests/StreamConformanceTests/StreamConformanceTests.csproj @@ -8,7 +8,6 @@ - diff --git a/src/libraries/Common/tests/System/IO/Compression/CompressionStreamUnitTestBase.cs b/src/libraries/Common/tests/System/IO/Compression/CompressionStreamUnitTestBase.cs index 31156d7..17ec46f 100644 --- a/src/libraries/Common/tests/System/IO/Compression/CompressionStreamUnitTestBase.cs +++ b/src/libraries/Common/tests/System/IO/Compression/CompressionStreamUnitTestBase.cs @@ -549,10 +549,10 @@ namespace System.IO.Compression isSync = sync; } - public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state); - public override int EndRead(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); - public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state); - public override void EndWrite(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), callback, state); + public override int EndRead(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), callback, state); + public override void EndWrite(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/libraries/Common/tests/System/IO/ConnectedStreams.cs b/src/libraries/Common/tests/System/IO/ConnectedStreams.cs index b8f3fe1..f5da8c8 100644 --- a/src/libraries/Common/tests/System/IO/ConnectedStreams.cs +++ b/src/libraries/Common/tests/System/IO/ConnectedStreams.cs @@ -159,14 +159,14 @@ namespace System.IO } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), callback, state); public override int EndRead(IAsyncResult asyncResult) { ThrowIfDisposed(); ThrowIfReadingNotSupported(); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -229,14 +229,14 @@ namespace System.IO } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), callback, state); public override void EndWrite(IAsyncResult asyncResult) { ThrowIfDisposed(); ThrowIfWritingNotSupported(); - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); } public override long Length => throw new NotSupportedException(); @@ -348,12 +348,12 @@ namespace System.IO } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), callback, state); public override int EndRead(IAsyncResult asyncResult) { ThrowIfDisposed(); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -402,12 +402,12 @@ namespace System.IO } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), callback, state); public override void EndWrite(IAsyncResult asyncResult) { ThrowIfDisposed(); - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); } public override long Length => throw new NotSupportedException(); diff --git a/src/libraries/Common/tests/System/IO/DelayStream.cs b/src/libraries/Common/tests/System/IO/DelayStream.cs index aeb6678..e0ece4e 100644 --- a/src/libraries/Common/tests/System/IO/DelayStream.cs +++ b/src/libraries/Common/tests/System/IO/DelayStream.cs @@ -43,9 +43,9 @@ namespace System.IO } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), callback, state); - public override int EndRead(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public override int EndRead(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { @@ -72,9 +72,9 @@ namespace System.IO } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), callback, state); - public override void EndWrite(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public override void EndWrite(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public override void Write(byte[] buffer, int offset, int count) { diff --git a/src/libraries/System.IO.Compression.Brotli/src/System.IO.Compression.Brotli.csproj b/src/libraries/System.IO.Compression.Brotli/src/System.IO.Compression.Brotli.csproj index 6c884b2..df43122 100644 --- a/src/libraries/System.IO.Compression.Brotli/src/System.IO.Compression.Brotli.csproj +++ b/src/libraries/System.IO.Compression.Brotli/src/System.IO.Compression.Brotli.csproj @@ -1,4 +1,4 @@ - + true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent) @@ -20,8 +20,6 @@ - diff --git a/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs b/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs index be4fe9d..ac596b9 100644 --- a/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs +++ b/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs @@ -96,7 +96,7 @@ namespace System.IO.Compression /// The current implementation does not support the read operation. /// This call cannot be completed. public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); /// Waits for the pending asynchronous read to complete. (Consider using the method instead.) /// The reference to the pending asynchronous request to finish. @@ -105,7 +105,7 @@ namespace System.IO.Compression /// did not originate from a method on the current stream. /// The end operation cannot be performed because the stream is closed. public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); /// Asynchronously reads a sequence of bytes from the current Brotli stream, writes them to a byte array starting at a specified index, advances the position within the Brotli stream by the number of bytes read, and monitors cancellation requests. /// The buffer to write the data into. diff --git a/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliStream.Compress.cs b/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliStream.Compress.cs index 1ecfc0b..207c552 100644 --- a/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliStream.Compress.cs +++ b/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliStream.Compress.cs @@ -94,13 +94,13 @@ namespace System.IO.Compression /// The current implementation does not support the write operation. /// The write operation cannot be performed because the stream is closed. public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); /// Handles the end of an asynchronous write operation. (Consider using the method instead.) /// The object that represents the asynchronous call. /// The underlying stream is closed or . public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); /// Asynchronously writes compressed bytes to the underlying Brotli stream from the specified byte array. /// The buffer that contains the data to compress. diff --git a/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj b/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj index 64fa67a..167caaa 100644 --- a/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj +++ b/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj @@ -24,8 +24,6 @@ Link="Common\System\IO\Compression\ZipTestHelper.cs" /> - diff --git a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj index d05a1d7..798fccd 100644 --- a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj @@ -39,8 +39,6 @@ - diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs index 96baf10..d161f74 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs @@ -152,10 +152,10 @@ namespace System.IO.Compression } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); private ValueTask ReadAsyncInternal(Memory buffer, CancellationToken cancellationToken) { diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs index 2afd554..18b6cb9 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs @@ -356,13 +356,13 @@ namespace System.IO.Compression throw new InvalidDataException(SR.TruncatedData); public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override int EndRead(IAsyncResult asyncResult) { EnsureDecompressionMode(); EnsureNotDisposed(); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -758,13 +758,13 @@ namespace System.IO.Compression } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override void EndWrite(IAsyncResult asyncResult) { EnsureCompressionMode(); EnsureNotDisposed(); - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs index f59e473..c4b743b 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs @@ -72,7 +72,7 @@ namespace System.IO.Compression } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override int EndRead(IAsyncResult asyncResult) => _deflateStream.EndRead(asyncResult); @@ -100,7 +100,7 @@ namespace System.IO.Compression } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override void EndWrite(IAsyncResult asyncResult) => _deflateStream.EndWrite(asyncResult); diff --git a/src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj b/src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj index 518be0f..7715606 100644 --- a/src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj +++ b/src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj @@ -39,7 +39,6 @@ - diff --git a/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj b/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj index 33678ec..21a7012 100644 --- a/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj +++ b/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj @@ -11,8 +11,6 @@ System.IO.Pipelines.PipeReader - @@ -57,6 +55,10 @@ System.IO.Pipelines.PipeReader + + + + diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReaderStream.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReaderStream.cs index 19128cc..798defa 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReaderStream.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReaderStream.cs @@ -75,10 +75,10 @@ namespace System.IO.Pipelines public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); public sealed override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, default), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, default), callback, state); public sealed override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriterStream.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriterStream.cs index dc9c34a..2dc15a5 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriterStream.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriterStream.cs @@ -61,10 +61,10 @@ namespace System.IO.Pipelines public override void SetLength(long value) => throw new NotSupportedException(); public sealed override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, default), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, default), callback, state); public sealed override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override void Write(byte[] buffer, int offset, int count) => WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj index 8f50a32..4047a77 100644 --- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj +++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj @@ -24,8 +24,6 @@ - diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.cs index a0652e7..069ff0e 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.cs @@ -162,10 +162,10 @@ namespace System.IO.Pipes } public System.IAsyncResult BeginWaitForConnection(AsyncCallback? callback, object? state) => - TaskToApm.Begin(WaitForConnectionAsync(), callback, state); + TaskToAsyncResult.Begin(WaitForConnectionAsync(), callback, state); public void EndWaitForConnection(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); // Server can only connect from Disconnected state private void CheckConnectOperationsServer() diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs index ce0607a..bba2948 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs @@ -103,10 +103,10 @@ namespace System.IO.Pipes } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + => TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); public override int EndRead(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); public override void Write(byte[] buffer, int offset, int count) { @@ -177,10 +177,10 @@ namespace System.IO.Pipes } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); + => TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); public override void EndWrite(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); internal static string GetPipePath(string serverName, string pipeName) { diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs index 229b604..aed30e5 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs @@ -109,7 +109,7 @@ namespace System.IO.Pipes public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) { if (_isAsync) - return TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + return TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); else return base.BeginRead(buffer, offset, count, callback, state); } @@ -117,7 +117,7 @@ namespace System.IO.Pipes public override int EndRead(IAsyncResult asyncResult) { if (_isAsync) - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); else return base.EndRead(asyncResult); } @@ -205,7 +205,7 @@ namespace System.IO.Pipes public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) { if (_isAsync) - return TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); + return TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); else return base.BeginWrite(buffer, offset, count, callback, state); } @@ -213,7 +213,7 @@ namespace System.IO.Pipes public override void EndWrite(IAsyncResult asyncResult) { if (_isAsync) - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); else base.EndWrite(asyncResult); } diff --git a/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj b/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj index 5797c2c5..958fd6b 100644 --- a/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj +++ b/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj @@ -138,8 +138,10 @@ System.IO.Ports.SerialPort Link="Common\Interop\Unix\Interop.IOErrors.cs" /> - + + + + diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index 2d22028..b207ac3 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -520,7 +520,7 @@ namespace System.IO.Ports public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) { - return TaskToApm.Begin(ReadAsync(array, offset, numBytes), userCallback, stateObject); + return TaskToAsyncResult.Begin(ReadAsync(array, offset, numBytes), userCallback, stateObject); } // Will wait `timeout` miliseconds or until reading or writing is possible @@ -576,7 +576,7 @@ namespace System.IO.Ports public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback userCallback, object stateObject) { - return TaskToApm.Begin(WriteAsync(array, offset, count), userCallback, stateObject); + return TaskToAsyncResult.Begin(WriteAsync(array, offset, count), userCallback, stateObject); } public override void EndWrite(IAsyncResult asyncResult) @@ -586,7 +586,7 @@ namespace System.IO.Ports { try { - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } catch (OperationCanceledException) { diff --git a/src/libraries/System.IO/tests/System.IO.Tests.csproj b/src/libraries/System.IO/tests/System.IO.Tests.csproj index c0d66ac..c7286f4 100644 --- a/src/libraries/System.IO/tests/System.IO.Tests.csproj +++ b/src/libraries/System.IO/tests/System.IO.Tests.csproj @@ -61,7 +61,6 @@ - diff --git a/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj b/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj index 0ed88b1..639e4a3 100644 --- a/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj +++ b/src/libraries/System.Memory.Data/src/System.Memory.Data.csproj @@ -12,7 +12,6 @@ System.BinaryData - @@ -20,6 +19,10 @@ System.BinaryData + + + + diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj index 3921f51..e6dd2f5 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj @@ -79,8 +79,6 @@ System.Net.Http.WinHttpHandler Link="Common\System\Runtime\ExceptionServices\ExceptionStackTrace.cs" /> - @@ -112,6 +110,10 @@ System.Net.Http.WinHttpHandler Link="Common\DisableRuntimeMarshalling.cs" /> + + + + diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs index c50f09b..ebbb43e 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs @@ -143,10 +143,10 @@ namespace System.Net.Http } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override long Seek(long offset, SeekOrigin origin) { diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs index fd0bfee..dccbaea 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs @@ -210,10 +210,10 @@ namespace System.Net.Http } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); private async Task ReadAsyncCore(byte[] buffer, int offset, int count, CancellationToken token) { diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj index 739f32d..791b003 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj @@ -57,8 +57,6 @@ Link="Common\System\Text\SimpleRegex.cs" /> - - - - diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpBaseStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpBaseStream.cs index 0bcc913..1d90cd6 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpBaseStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpBaseStream.cs @@ -13,16 +13,16 @@ namespace System.Net.Http public sealed override bool CanSeek => false; public sealed override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, default), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, default), callback, state); public sealed override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public sealed override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, default), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, default), callback, state); public sealed override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public sealed override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs index 4fa0beb..13e4122 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs @@ -1031,10 +1031,10 @@ namespace System.Net.Http } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override void WriteByte(byte value) { diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs b/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs index eb7893a..156abcc 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs @@ -533,10 +533,10 @@ namespace System.Net.Http ReadAsyncPrivate(buffer, cancellationToken); public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(ReadAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState); + TaskToAsyncResult.Begin(ReadAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public async ValueTask ReadAsyncPrivate(Memory buffer, CancellationToken cancellationToken) { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 90c828e..f09fad6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -45,8 +45,6 @@ Link="Common\Interop\Unix\Interop.Libraries.cs" /> - - - diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 127119d..254be8e 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -19,8 +19,6 @@ Link="Common\System\Net\Logging\NetEventSource.Common.cs" /> - diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs index cf049da..0ee39a3 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs @@ -164,16 +164,16 @@ namespace System.Net } public static IAsyncResult BeginGetHostEntry(IPAddress address, AsyncCallback? requestCallback, object? stateObject) => - TaskToApm.Begin(GetHostEntryAsync(address), requestCallback, stateObject); + TaskToAsyncResult.Begin(GetHostEntryAsync(address), requestCallback, stateObject); public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCallback? requestCallback, object? stateObject) => - TaskToApm.Begin(GetHostEntryAsync(hostNameOrAddress), requestCallback, stateObject); + TaskToAsyncResult.Begin(GetHostEntryAsync(hostNameOrAddress), requestCallback, stateObject); public static IPHostEntry EndGetHostEntry(IAsyncResult asyncResult) { ArgumentNullException.ThrowIfNull(asyncResult); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } public static IPAddress[] GetHostAddresses(string hostNameOrAddress) @@ -241,13 +241,13 @@ namespace System.Net (Task)GetHostEntryOrAddressesCoreAsync(hostNameOrAddress, justReturnParsedIp: true, throwOnIIPAny: true, justAddresses: true, family, cancellationToken); public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, AsyncCallback? requestCallback, object? state) => - TaskToApm.Begin(GetHostAddressesAsync(hostNameOrAddress), requestCallback, state); + TaskToAsyncResult.Begin(GetHostAddressesAsync(hostNameOrAddress), requestCallback, state); public static IPAddress[] EndGetHostAddresses(IAsyncResult asyncResult) { ArgumentNullException.ThrowIfNull(asyncResult); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } [Obsolete("GetHostByName has been deprecated. Use GetHostEntry instead.")] @@ -265,14 +265,14 @@ namespace System.Net [Obsolete("BeginGetHostByName has been deprecated. Use BeginGetHostEntry instead.")] public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? requestCallback, object? stateObject) => - TaskToApm.Begin(GetHostEntryCoreAsync(hostName, justReturnParsedIp: true, throwOnIIPAny: true, AddressFamily.Unspecified, CancellationToken.None), requestCallback, stateObject); + TaskToAsyncResult.Begin(GetHostEntryCoreAsync(hostName, justReturnParsedIp: true, throwOnIIPAny: true, AddressFamily.Unspecified, CancellationToken.None), requestCallback, stateObject); [Obsolete("EndGetHostByName has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) { ArgumentNullException.ThrowIfNull(asyncResult); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] @@ -328,7 +328,7 @@ namespace System.Net [Obsolete("BeginResolve has been deprecated. Use BeginGetHostEntry instead.")] public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestCallback, object? stateObject) => - TaskToApm.Begin(GetHostEntryCoreAsync(hostName, justReturnParsedIp: false, throwOnIIPAny: false, AddressFamily.Unspecified, CancellationToken.None), requestCallback, stateObject); + TaskToAsyncResult.Begin(GetHostEntryCoreAsync(hostName, justReturnParsedIp: false, throwOnIIPAny: false, AddressFamily.Unspecified, CancellationToken.None), requestCallback, stateObject); [Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndResolve(IAsyncResult asyncResult) @@ -337,16 +337,11 @@ namespace System.Net try { - ipHostEntry = TaskToApm.End(asyncResult); + ipHostEntry = TaskToAsyncResult.End(asyncResult); } catch (SocketException ex) { - object? asyncState = asyncResult switch - { - Task t => t.AsyncState, - TaskToApm.TaskAsyncResult twar => twar._task.AsyncState, - _ => null - }; + object? asyncState = TaskToAsyncResult.Unwrap(asyncResult).AsyncState; IPAddress? address = asyncState switch { diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj index e8621ab..c9b2bbb 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj +++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj @@ -1,4 +1,4 @@ - + true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-android;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent) @@ -51,7 +51,6 @@ - diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs index b460cef..3090e47 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalProperties.cs @@ -368,10 +368,10 @@ namespace System.Net.NetworkInformation } public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback? callback, object? state) => - TaskToApm.Begin(GetUnicastAddressesAsync(), callback, state); + TaskToAsyncResult.Begin(GetUnicastAddressesAsync(), callback, state); public override UnicastIPAddressInformationCollection EndGetUnicastAddresses(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override UnicastIPAddressInformationCollection GetUnicastAddresses() => GetUnicastAddressesAsync().GetAwaiter().GetResult(); diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs index 9de6b8b..f26aa57 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/UnixIPGlobalProperties.cs @@ -43,12 +43,12 @@ namespace System.Net.NetworkInformation public override IAsyncResult BeginGetUnicastAddresses(AsyncCallback? callback, object? state) { Task t = GetUnicastAddressesAsync(); - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } public override UnicastIPAddressInformationCollection EndGetUnicastAddresses(IAsyncResult asyncResult) { - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } public sealed override Task GetUnicastAddressesAsync() diff --git a/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj b/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj index b7b6b7e..ebbed23 100644 --- a/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj +++ b/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj @@ -22,7 +22,6 @@ - diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.Stream.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.Stream.cs index 8bf9799..dd6fa5a 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.Stream.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.Stream.cs @@ -90,11 +90,11 @@ public partial class QuicStream : Stream /// public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(ReadAsync(buffer, offset, count, default), callback, state); + => TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, default), callback, state); /// public override int EndRead(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); /// public override int Read(byte[] buffer, int offset, int count) @@ -153,11 +153,11 @@ public partial class QuicStream : Stream /// public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(WriteAsync(buffer, offset, count, default), callback, state); + => TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, default), callback, state); /// public override void EndWrite(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); /// public override void Write(byte[] buffer, int offset, int count) diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj index c088044..2b31dee 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj @@ -16,7 +16,6 @@ - diff --git a/src/libraries/System.Net.Requests/src/System.Net.Requests.csproj b/src/libraries/System.Net.Requests/src/System.Net.Requests.csproj index 051c2bc..505dc8a 100644 --- a/src/libraries/System.Net.Requests/src/System.Net.Requests.csproj +++ b/src/libraries/System.Net.Requests/src/System.Net.Requests.csproj @@ -76,8 +76,6 @@ Link="Common\System\Net\SecurityProtocol.cs" /> - t = Task.Factory.StartNew(s => ((FileWebRequest)s!).CreateWriteStream(), this, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } public override Task GetRequestStreamAsync() @@ -219,7 +219,7 @@ namespace System.Net CheckAndMarkAsyncGetResponsePending(); Task t = Task.Factory.StartNew(s => ((FileWebRequest)s!).CreateResponse(), this, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } public override Task GetResponseAsync() @@ -236,14 +236,14 @@ namespace System.Net public override Stream EndGetRequestStream(IAsyncResult asyncResult) { - Stream stream = TaskToApm.End(asyncResult); + Stream stream = TaskToAsyncResult.End(asyncResult); _writePending = false; return stream; } public override WebResponse EndGetResponse(IAsyncResult asyncResult) { - WebResponse response = TaskToApm.End(asyncResult); + WebResponse response = TaskToAsyncResult.End(asyncResult); _readPending = false; return response; } diff --git a/src/libraries/System.Net.Security/src/System.Net.Security.csproj b/src/libraries/System.Net.Security/src/System.Net.Security.csproj index bc44d7a..b594f3f 100644 --- a/src/libraries/System.Net.Security/src/System.Net.Security.csproj +++ b/src/libraries/System.Net.Security/src/System.Net.Security.csproj @@ -90,8 +90,6 @@ - - TaskToApm.Begin(AuthenticateAsClientAsync(credential, binding, targetName, requiredProtectionLevel, allowedImpersonationLevel), asyncCallback, asyncState); + TaskToAsyncResult.Begin(AuthenticateAsClientAsync(credential, binding, targetName, requiredProtectionLevel, allowedImpersonationLevel), asyncCallback, asyncState); - public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public virtual void AuthenticateAsServer() => AuthenticateAsServer((NetworkCredential)CredentialCache.DefaultCredentials, policy: null, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); @@ -149,9 +149,9 @@ namespace System.Net.Security public virtual IAsyncResult BeginAuthenticateAsServer( NetworkCredential credential, ExtendedProtectionPolicy? policy, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(AuthenticateAsServerAsync(credential, policy, requiredProtectionLevel, requiredImpersonationLevel), asyncCallback, asyncState); + TaskToAsyncResult.Begin(AuthenticateAsServerAsync(credential, policy, requiredProtectionLevel, requiredImpersonationLevel), asyncCallback, asyncState); - public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public virtual void AuthenticateAsClient() => AuthenticateAsClient((NetworkCredential)CredentialCache.DefaultCredentials, binding: null, string.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); @@ -518,16 +518,16 @@ namespace System.Net.Security } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(ReadAsync(buffer, offset, count), asyncCallback, asyncState); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), asyncCallback, asyncState); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(WriteAsync(buffer, offset, count), asyncCallback, asyncState); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), asyncCallback, asyncState); public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); private void ThrowIfExceptional() { diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs index a086fc9..9f4ac13 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs @@ -248,9 +248,9 @@ namespace System.Net.Security } internal IAsyncResult BeginAuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(AuthenticateAsClientAsync(sslClientAuthenticationOptions, cancellationToken)!, asyncCallback, asyncState); + TaskToAsyncResult.Begin(AuthenticateAsClientAsync(sslClientAuthenticationOptions, cancellationToken)!, asyncCallback, asyncState); - public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); // // Server side auth. @@ -287,13 +287,13 @@ namespace System.Net.Security } private IAsyncResult BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback? asyncCallback, object? asyncState) => - TaskToApm.Begin(AuthenticateAsServerAsync(sslServerAuthenticationOptions, cancellationToken)!, asyncCallback, asyncState); + TaskToAsyncResult.Begin(AuthenticateAsServerAsync(sslServerAuthenticationOptions, cancellationToken)!, asyncCallback, asyncState); - public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); - internal IAsyncResult BeginShutdown(AsyncCallback? asyncCallback, object? asyncState) => TaskToApm.Begin(ShutdownAsync(), asyncCallback, asyncState); + internal IAsyncResult BeginShutdown(AsyncCallback? asyncCallback, object? asyncState) => TaskToAsyncResult.Begin(ShutdownAsync(), asyncCallback, asyncState); - internal static void EndShutdown(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + internal static void EndShutdown(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public TransportContext TransportContext => new SslStreamContext(this); @@ -767,25 +767,25 @@ namespace System.Net.Security public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) { ThrowIfExceptionalOrNotAuthenticated(); - return TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + return TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); } public override int EndRead(IAsyncResult asyncResult) { ThrowIfExceptionalOrNotAuthenticated(); - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState) { ThrowIfExceptionalOrNotAuthenticated(); - return TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + return TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); } public override void EndWrite(IAsyncResult asyncResult) { ThrowIfExceptionalOrNotAuthenticated(); - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) diff --git a/src/libraries/System.Net.Security/tests/EnterpriseTests/System.Net.Security.Enterprise.Tests.csproj b/src/libraries/System.Net.Security/tests/EnterpriseTests/System.Net.Security.Enterprise.Tests.csproj index 809f2f3..3714c1b 100644 --- a/src/libraries/System.Net.Security/tests/EnterpriseTests/System.Net.Security.Enterprise.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/EnterpriseTests/System.Net.Security.Enterprise.Tests.csproj @@ -19,7 +19,5 @@ Link="Common\System\Net\EnterpriseTests\EnterpriseTestConfiguration.cs" /> - - \ No newline at end of file + diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index 56e1f32..0db9e97 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -91,8 +91,6 @@ Link="CommonTest\System\Security\Cryptography\X509Certificates\RevocationResponder.cs" /> - n>q`|lHX==R;Id+)~j{^BOC=T_Wv_l^GFcfacD zkvq`w19$A+=-06u>ep}jd#Wc6^~|w;Uvsxy-)-o-=Kic->-v3De{ZYAU-Y}Dzwh-# zPj@_3Sv&3z?hCi2b0_Yj&L67mw`X;4`MQhR#r>yxg1@`E+iLHt)J?VWNdJ?P#{Sn( zZKS2N_ds=1E8m_zKj_@VUmf{=(YH4`f1>-}yMO7*zOGZwM87GU(m3X*??0ieP=Ef} zU4M5^lss{({^?b~%lB&qY}@4P$>Qj%t&p zP1`mLC7affrC*xgpQq%rOZr<5QwhWI6AGBT0nWcSoC^k#ES=yzo$1{0z!Q);A zo+@rn9op3CS2ZoNI_r^_G`x0ZOV|PCGtAoB=BISunzgez?V6QeP17=M_tfjMzlxG* zH0D+N3$%evTG^bQO-iq(<`dCsB+9kzou~OPZbfry#7|fEw#vSQ8TjIKe3~ZB+uEFR z&FiS9?^AKpTYyh`sQAc{{{Bb5h|?{~e{a^#<`isJ zel<6yP8v| zy1b?|y6TbG=@FbfJ*U&8DV58kjEmEJ`F@wTavoe-UV4_AJJM-HQD6A^Csu-aXxp=f z@>YZ>e-Uq$Kb7s}G%Ycm3zvy^rnfdrwGSH8W7&So_q3ZE305XA17ZA@!J<~RZgy(c z>3fz}SLL7Cr{^WpvS~dZN3%TYy8Bj<^4t2muK#?=uHIJmZe5?dI=&%anM_H~-K+eN z}2v9hyd z>wB5JYaNRAE6VFD{s#g9DL_JqDxc^KwGn-vt-er7T>9_6PuRk~{C;YrUg`+aI%{2q zL4d|1l?QIX>@OM3v1&cinXzgK*H=|HHNO`eD#Wo^7=|AW}f@SX*Xq54abk&oX|o4AX|}!n28hKDZ+d4YZUvvhwjZz$zmdhPaKeXOF<$Oi0 zNVEptE1H3b3e+0=5jpmn;mA{nQ8YZ(sYfs6@80pxT@wd@L3`yMs=tq4pf>&v#~O?jy`~H<0?oW5LeI_1R3&po@X~z z8r)%8mV85kWCIUoTH0cHd%BD3cuKU*o-==r7SliQY9;~b0`5b5_jC^L@3HuSW2_sv zE#%|t9Nqu!uLcyr*Xrdrp7w3^6v?6G^afptm0?uyMbcwuEsHf$;Df}kPV3lqIO4L5 zY8B%BZ*{c`e5k7-o}MT^WUTyv{I7j-B6? zo(konaW%k7h8f&0UM^Ek;DVPEkTk-ocy zz6sCFE4DFKUHh81<7@5tdO<7DpMmN~dNS}bOjLj?u`L{^y@^+9a}v&>Ex>#y$2%&S z83Vrg#A_t9M~o9><~)`s1k!(9Be5ob0p9{0l9iTxt^KIh#1*&~hV) zD^BXSB0M+m`Q=kl3J%zn-eVr~vtLgXTao;%6D}%#F19oI=gRrWtfH-hGCzt)1*3%p zz#3TG4r_o<#T;^^BjWBukJm$+Vta`9rDuIsc9CsHKLvZds$(Q0%#MmJQO|wl>9dm3 z{dncmXU5F8liJGKQ+7UivR*rr`^!pfLo3&n-C%#?`v+&Tj-5@gcqH4pDLuQZ_D=NVsVpgWHGdwP zAK!=M5goROI^JD&j`C0%kLb!oz2x4Hz6P_^$V$~*@CQ$^-LogtwO}DO)!vbOkur`- zcy3-iIfT8S(uWCAHT(sXg<~8N=AZomXnxumg*m zL)}qcpjzKwh8fhwYt~qX%Vj?8znVSBTgAAnE=$s7NxCe_^x47r^JZ0^-SR~Fi@nE0 zzu8eX%9Wh~ROdmeua@NiE(iUJJmM_%!tX2<%?cNBB1RoNCFqJM**8nKIKkQ0brp6Fd#R4J)Ms zzQ#}^c5i&1`vL~e?g6m@cEb=yTrbLJ|6BFhO3JZET2MFWI`B#C#*xHb%B4R<5{!i^3#^2vc3$PjY`z{0eJRc0PHs9x9^4Dx}xNc36cD zVYE0Tak1al`ObBBG!OJEiW$c~R$IO^eptJ{GntyO_M*xITmIQi=Q|h8KUr0IHGOA1 zmwG-+;^UNgLD}>5WIv5J;u&TF`8jM{T8B955Jw&2s6!kPE3nn}S>2Of_hGtgx$zY} z#im#Tv8%WUxRN$^E2u-gp#QT}><~x2miDtClGY)Pig&eG1`dvM#U0{k9vi?YUUNo$)CO@$Z^UGr7P;5my#8I+C zNVhJVy|2m9l99cfD?B^I(Pc&)#Xi?X$MWl}^amv~`z{@M3t;b}VQ&dr`%;XSvE4>i za+n5NJwHB+UlySrlJ)gm-O@~-NGI=pV{eXtvtY+*-lf61f1&}^_mpEJ+CV6@$q@k= zbw_)7&ojGIJjz9wDC3wICsq8camX{j^Fy*H>{xU6qZG=j{?nh|C~s)@qD74|`_S0# zUbgqusoyDZ;{GPd47+apB+av?okq4Kso{OjVa@)~BhHX&;(0-?k>&(pSNz=AqqB_9 z^1dIDk7H>B+r@{yrQxXjeMPzlY!$6}SJGn8mcOZg@vZ}(AJ^T|h<>hIm&NE^U5)`2 ziX4N0&Y~XYyNlR0w{ecWh|=@b^W;Up(;Mvfwg3EUz4sk2B=Ev6B(I6OV}gSK4^@u1=}Jd@@rY>%x?DCet?vA&wf_Vm1Qe!6UpSJ8}x!7dAPkjGHtaI;j1jkD?d%0MSuvt0wc-nsbW$h?J29)hJXE}oO z+7FA##^>rs`9b&Dp4Z80lKM}VTkETt3F2Kp^IhjtOzWaiu8#g2N;9knDvtEyjpZY* z)A9pE>63NS2VJ&6-Z8P<^m|&Wa?|a`erL}nv>E%oHZ}H})@NPpw~PHENAucQBg|Ce z8Fd%?Ez)cAi)h4A2E!fE+|J<(^=J$L`mZ+j|~F>4!m4!rNg z=Zty(r|r8)8Mxx1U&Ts diff --git a/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj b/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj index 2a2655a..6618a8d 100644 --- a/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj @@ -80,8 +80,6 @@ Link="ProductionCode\Common\System\Net\TlsFrameHelper.cs" /> - diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj index e50db90..457d891 100644 --- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj +++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj @@ -73,8 +73,6 @@ Link="Common\System\Net\TcpValidationHelpers.cs" /> - diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs index 8aa270f..6c10d2c 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs @@ -2236,21 +2236,21 @@ namespace System.Net.Sockets } public IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ConnectAsync(remoteEP), callback, state); + TaskToAsyncResult.Begin(ConnectAsync(remoteEP), callback, state); public IAsyncResult BeginConnect(string host, int port, AsyncCallback? requestCallback, object? state) => - TaskToApm.Begin(ConnectAsync(host, port), requestCallback, state); + TaskToAsyncResult.Begin(ConnectAsync(host, port), requestCallback, state); public IAsyncResult BeginConnect(IPAddress address, int port, AsyncCallback? requestCallback, object? state) => - TaskToApm.Begin(ConnectAsync(address, port), requestCallback, state); + TaskToAsyncResult.Begin(ConnectAsync(address, port), requestCallback, state); public IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback? requestCallback, object? state) => - TaskToApm.Begin(ConnectAsync(addresses, port), requestCallback, state); + TaskToAsyncResult.Begin(ConnectAsync(addresses, port), requestCallback, state); - public void EndConnect(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public void EndConnect(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback? callback, object? state) => - TaskToApm.Begin(DisconnectAsync(reuseSocket).AsTask(), callback, state); + TaskToAsyncResult.Begin(DisconnectAsync(reuseSocket).AsTask(), callback, state); public void Disconnect(bool reuseSocket) { @@ -2273,14 +2273,14 @@ namespace System.Net.Sockets _localEndPoint = null; } - public void EndDisconnect(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public void EndDisconnect(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public IAsyncResult BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback? callback, object? state) { ThrowIfDisposed(); ValidateBufferArguments(buffer, offset, size); - return TaskToApm.Begin(SendAsync(new ReadOnlyMemory(buffer, offset, size), socketFlags, default).AsTask(), callback, state); + return TaskToAsyncResult.Begin(SendAsync(new ReadOnlyMemory(buffer, offset, size), socketFlags, default).AsTask(), callback, state); } public IAsyncResult? BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback? callback, object? state) @@ -2296,14 +2296,14 @@ namespace System.Net.Sockets } errorCode = SocketError.Success; - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } public IAsyncResult BeginSend(IList> buffers, SocketFlags socketFlags, AsyncCallback? callback, object? state) { ThrowIfDisposed(); - return TaskToApm.Begin(SendAsync(buffers, socketFlags), callback, state); + return TaskToAsyncResult.Begin(SendAsync(buffers, socketFlags), callback, state); } public IAsyncResult? BeginSend(IList> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback? callback, object? state) @@ -2318,10 +2318,10 @@ namespace System.Net.Sockets } errorCode = SocketError.Success; - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } - public int EndSend(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public int EndSend(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public int EndSend(IAsyncResult asyncResult, out SocketError errorCode) => EndSendReceive(asyncResult, out errorCode); @@ -2342,10 +2342,10 @@ namespace System.Net.Sockets if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"::DoBeginSendFile() SRC:{LocalEndPoint} DST:{RemoteEndPoint} fileName:{fileName}"); - return TaskToApm.Begin(SendFileAsync(fileName, preBuffer, postBuffer, flags).AsTask(), callback, state); + return TaskToAsyncResult.Begin(SendFileAsync(fileName, preBuffer, postBuffer, flags).AsTask(), callback, state); } - public void EndSendFile(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public void EndSendFile(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback? callback, object? state) { @@ -2354,16 +2354,16 @@ namespace System.Net.Sockets ArgumentNullException.ThrowIfNull(remoteEP); Task t = SendToAsync(buffer.AsMemory(offset, size), socketFlags, remoteEP).AsTask(); - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } - public int EndSendTo(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public int EndSendTo(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback? callback, object? state) { ThrowIfDisposed(); ValidateBufferArguments(buffer, offset, size); - return TaskToApm.Begin(ReceiveAsync(new ArraySegment(buffer, offset, size), socketFlags, fromNetworkStream: false, default).AsTask(), callback, state); + return TaskToAsyncResult.Begin(ReceiveAsync(new ArraySegment(buffer, offset, size), socketFlags, fromNetworkStream: false, default).AsTask(), callback, state); } public IAsyncResult? BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback? callback, object? state) @@ -2379,13 +2379,13 @@ namespace System.Net.Sockets } errorCode = SocketError.Success; - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } public IAsyncResult BeginReceive(IList> buffers, SocketFlags socketFlags, AsyncCallback? callback, object? state) { ThrowIfDisposed(); - return TaskToApm.Begin(ReceiveAsync(buffers, socketFlags), callback, state); + return TaskToAsyncResult.Begin(ReceiveAsync(buffers, socketFlags), callback, state); } public IAsyncResult? BeginReceive(IList> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback? callback, object? state) @@ -2400,21 +2400,17 @@ namespace System.Net.Sockets } errorCode = SocketError.Success; - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } - public int EndReceive(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public int EndReceive(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); public int EndReceive(IAsyncResult asyncResult, out SocketError errorCode) => EndSendReceive(asyncResult, out errorCode); private static int EndSendReceive(IAsyncResult asyncResult, out SocketError errorCode) { - if (TaskToApm.GetTask(asyncResult) is not Task ti) - { - ArgumentNullException.ThrowIfNull(asyncResult); - throw new ArgumentException(null, nameof(asyncResult)); - } + Task ti = TaskToAsyncResult.Unwrap(asyncResult); if (!ti.IsCompleted) { @@ -2448,7 +2444,7 @@ namespace System.Net.Sockets EndPoint resultEp = t.Result.RemoteEndPoint; if (!remoteEP.Equals(resultEp)) remoteEP = resultEp; } - IAsyncResult asyncResult = TaskToApm.Begin(t, callback, state); + IAsyncResult asyncResult = TaskToAsyncResult.Begin(t, callback, state); if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"size:{size} returning AsyncResult:{asyncResult}"); return asyncResult; } @@ -2461,7 +2457,7 @@ namespace System.Net.Sockets throw new ArgumentException(SR.Format(SR.net_InvalidEndPointAddressFamily, endPoint.AddressFamily, _addressFamily), nameof(endPoint)); } - SocketReceiveMessageFromResult result = TaskToApm.End(asyncResult); + SocketReceiveMessageFromResult result = TaskToAsyncResult.End(asyncResult); if (!endPoint.Equals(result.RemoteEndPoint)) { endPoint = result.RemoteEndPoint; @@ -2486,7 +2482,7 @@ namespace System.Net.Sockets if (!remoteEP.Equals(resultEp)) remoteEP = resultEp; } - return TaskToApm.Begin(t, callback, state); + return TaskToAsyncResult.Begin(t, callback, state); } public int EndReceiveFrom(IAsyncResult asyncResult, ref EndPoint endPoint) @@ -2497,7 +2493,7 @@ namespace System.Net.Sockets throw new ArgumentException(SR.Format(SR.net_InvalidEndPointAddressFamily, endPoint.AddressFamily, _addressFamily), nameof(endPoint)); } - SocketReceiveFromResult result = TaskToApm.End(asyncResult); + SocketReceiveFromResult result = TaskToAsyncResult.End(asyncResult); if (!endPoint.Equals(result.RemoteEndPoint)) { endPoint = result.RemoteEndPoint; @@ -2506,9 +2502,9 @@ namespace System.Net.Sockets } public IAsyncResult BeginAccept(AsyncCallback? callback, object? state) => - TaskToApm.Begin(AcceptAsync(), callback, state); + TaskToAsyncResult.Begin(AcceptAsync(), callback, state); - public Socket EndAccept(IAsyncResult asyncResult) => TaskToApm.End(asyncResult); + public Socket EndAccept(IAsyncResult asyncResult) => TaskToAsyncResult.End(asyncResult); // This method provides support for legacy BeginAccept methods that take a "receiveSize" argument and // allow data to be received as part of the accept operation. @@ -2547,7 +2543,7 @@ namespace System.Net.Sockets BeginAccept(acceptSocket: null, receiveSize, callback, state); public IAsyncResult BeginAccept(Socket? acceptSocket, int receiveSize, AsyncCallback? callback, object? state) => - TaskToApm.Begin(AcceptAndReceiveHelperAsync(acceptSocket, receiveSize), callback, state); + TaskToAsyncResult.Begin(AcceptAndReceiveHelperAsync(acceptSocket, receiveSize), callback, state); public Socket EndAccept(out byte[] buffer, IAsyncResult asyncResult) { @@ -2560,7 +2556,7 @@ namespace System.Net.Sockets public Socket EndAccept(out byte[] buffer, out int bytesTransferred, IAsyncResult asyncResult) { Socket s; - (s, buffer, bytesTransferred) = TaskToApm.End<(Socket, byte[], int)>(asyncResult); + (s, buffer, bytesTransferred) = TaskToAsyncResult.End<(Socket, byte[], int)>(asyncResult); return s; } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs index 6ee9ff7..4cb923f 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs @@ -201,13 +201,13 @@ namespace System.Net.Sockets } public IAsyncResult BeginAcceptSocket(AsyncCallback? callback, object? state) => - TaskToApm.Begin(AcceptSocketAsync(), callback, state); + TaskToAsyncResult.Begin(AcceptSocketAsync(), callback, state); public Socket EndAcceptSocket(IAsyncResult asyncResult) => EndAcceptCore(asyncResult); public IAsyncResult BeginAcceptTcpClient(AsyncCallback? callback, object? state) => - TaskToApm.Begin(AcceptTcpClientAsync(), callback, state); + TaskToAsyncResult.Begin(AcceptTcpClientAsync(), callback, state); public TcpClient EndAcceptTcpClient(IAsyncResult asyncResult) => EndAcceptCore(asyncResult); @@ -283,7 +283,7 @@ namespace System.Net.Sockets { try { - return TaskToApm.End(asyncResult); + return TaskToAsyncResult.End(asyncResult); } catch (SocketException) when (!_active) { diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj b/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj index ad1851d..a1367f4 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj @@ -92,8 +92,6 @@ Link="Common\System\Threading\Tasks\TaskTimeoutExtensions.cs" /> - Common\System\Threading\OpenExistingResult.cs - - Common\System\Threading\Tasks\TaskToApm.cs + + Common\System\Threading\Tasks\TaskToAsyncResult.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs index aabdf3c..40abcbd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs @@ -725,10 +725,10 @@ namespace System.IO } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override int ReadByte() { @@ -1138,10 +1138,10 @@ namespace System.IO } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override void WriteByte(byte value) { diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs index 9e8f37f..a221e80 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs @@ -456,10 +456,10 @@ namespace System.IO.Strategies } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + => TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); public override int EndRead(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); public override void Write(byte[] buffer, int offset, int count) { @@ -739,10 +739,10 @@ namespace System.IO.Strategies } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); + => TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); public override void EndWrite(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); public override void SetLength(long value) { diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs index 83746a5..febe3d1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs @@ -246,10 +246,10 @@ namespace System.IO.Strategies } public sealed override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count), callback, state); public sealed override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public sealed override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); @@ -261,10 +261,10 @@ namespace System.IO.Strategies } public sealed override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count), callback, state); public sealed override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public sealed override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs index f3b723b..8c1c9bb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs @@ -1041,16 +1041,16 @@ namespace System.IO Task.CompletedTask; public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(Task.s_defaultResultTask, callback, state); + TaskToAsyncResult.Begin(Task.s_defaultResultTask, callback, state); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(Task.CompletedTask, callback, state); + TaskToAsyncResult.Begin(Task.CompletedTask, callback, state); public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override int Read(byte[] buffer, int offset, int count) => 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs b/src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs index 65be587..198e999 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs @@ -83,10 +83,10 @@ namespace System.Text } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + => TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) - => TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); + => TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); protected override void Dispose(bool disposing) { @@ -162,10 +162,10 @@ namespace System.Text } public override int EndRead(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); public override void EndWrite(IAsyncResult asyncResult) - => TaskToApm.End(asyncResult); + => TaskToAsyncResult.End(asyncResult); #pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant #pragma warning disable CS8774 // Member must have a non-null value when exiting. diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 8388419..2de2139 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -4,8 +4,6 @@ // Changes to this file must follow the https://aka.ms/api-review process. // ------------------------------------------------------------------------------ -using System.Text; - namespace Microsoft.Win32.SafeHandles { public abstract partial class CriticalHandleMinusOneIsInvalid : System.Runtime.InteropServices.CriticalHandle @@ -14950,6 +14948,14 @@ namespace System.Threading.Tasks public new System.Threading.Tasks.Task WaitAsync(System.TimeSpan timeout) { throw null; } public new System.Threading.Tasks.Task WaitAsync(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } } + public static partial class TaskToAsyncResult + { + public static System.IAsyncResult Begin(System.Threading.Tasks.Task task, System.AsyncCallback? callback, object? state) { throw null; } + public static void End(System.IAsyncResult asyncResult) { throw null; } + public static TResult End(System.IAsyncResult asyncResult) { throw null; } + public static System.Threading.Tasks.Task Unwrap(System.IAsyncResult asyncResult) { throw null; } + public static System.Threading.Tasks.Task Unwrap(System.IAsyncResult asyncResult) { throw null; } + } public partial class UnobservedTaskExceptionEventArgs : System.EventArgs { public UnobservedTaskExceptionEventArgs(System.AggregateException exception) { } diff --git a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj index af007a2..197dba5 100644 --- a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj +++ b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj @@ -1,4 +1,4 @@ - + true $(DefineConstants);INTERNAL_ASYMMETRIC_IMPLEMENTATIONS @@ -269,8 +269,6 @@ Link="Common\System\Security\Cryptography\Utf8DataEncoding.cs" /> - diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoStream.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoStream.cs index c1cc9a9..f85b396 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoStream.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoStream.cs @@ -249,10 +249,10 @@ namespace System.Security.Cryptography } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); + TaskToAsyncResult.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state); public override int EndRead(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override int ReadByte() { @@ -488,10 +488,10 @@ namespace System.Security.Cryptography } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => - TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); + TaskToAsyncResult.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state); public override void EndWrite(IAsyncResult asyncResult) => - TaskToApm.End(asyncResult); + TaskToAsyncResult.End(asyncResult); public override void Write(byte[] buffer, int offset, int count) { diff --git a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj index bfbb590..86e3d51 100644 --- a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj +++ b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj @@ -215,8 +215,6 @@ Link="CommonTest\System\Security\Cryptography\CryptoUtils.cs" /> - diff --git a/src/libraries/System.Text.Encoding/tests/System.Text.Encoding.Tests.csproj b/src/libraries/System.Text.Encoding/tests/System.Text.Encoding.Tests.csproj index 305e53a..a0c5f7f 100644 --- a/src/libraries/System.Text.Encoding/tests/System.Text.Encoding.Tests.csproj +++ b/src/libraries/System.Text.Encoding/tests/System.Text.Encoding.Tests.csproj @@ -86,7 +86,6 @@ - @@ -99,4 +98,4 @@ - \ No newline at end of file + diff --git a/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj b/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj index 8bebfb2..468c31b 100644 --- a/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj +++ b/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj @@ -16,6 +16,7 @@ + diff --git a/src/libraries/System.Threading.Tasks/tests/TaskToAsyncResultTests.cs b/src/libraries/System.Threading.Tasks/tests/TaskToAsyncResultTests.cs new file mode 100644 index 0000000..57d703f --- /dev/null +++ b/src/libraries/System.Threading.Tasks/tests/TaskToAsyncResultTests.cs @@ -0,0 +1,164 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; +using System.Threading; +using System.Threading.Tasks; + +namespace System.Threading.Tasks.Tests +{ + public class TaskToAsyncResultTests + { + [Fact] + public void InvalidArguments_ThrowExceptions() + { + AssertExtensions.Throws("task", () => TaskToAsyncResult.Begin(null, null, null)); + AssertExtensions.Throws("task", () => TaskToAsyncResult.Begin(null, iar => { }, "test")); + + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.End(null)); + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.End(null)); + + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.End(new NonTaskIAsyncResult())); + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.End(new NonTaskIAsyncResult())); + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.End(Task.FromResult((long)42))); + + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.Unwrap(new NonTaskIAsyncResult())); + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.Unwrap(new NonTaskIAsyncResult())); + AssertExtensions.Throws("asyncResult", () => TaskToAsyncResult.Unwrap(Task.FromResult((long)42))); + } + + [Fact] + public async Task BeginFromTask_UnwrapTask_EndFromTask_Roundtrips() + { + var tcs = new TaskCompletionSource(); + object state = new object(); + + IAsyncResult ar = TaskToAsyncResult.Begin(tcs.Task, null, state); + Assert.NotNull(ar); + Assert.Same(state, ar.AsyncState); + Assert.NotNull(ar.AsyncWaitHandle); + Assert.False(ar.CompletedSynchronously); + Assert.False(ar.IsCompleted); + + Assert.Same(tcs.Task, TaskToAsyncResult.Unwrap(ar)); + Assert.Same(tcs.Task, TaskToAsyncResult.Unwrap(ar)); + + tcs.SetResult(42); + await tcs.Task; + + Assert.True(ar.IsCompleted); + Assert.False(ar.CompletedSynchronously); + Assert.True(ar.AsyncWaitHandle.WaitOne(0)); + + TaskToAsyncResult.End(ar); + Assert.Equal(42, TaskToAsyncResult.End(ar)); + } + + [Fact] + public void BeginFromTask_CompletedSynchronously_CallbackInvokedSynchronously() + { + Task t = Task.FromResult(42); + object state = new object(); + + int id = Environment.CurrentManagedThreadId; + + IAsyncResult arCallback = null; + IAsyncResult ar = TaskToAsyncResult.Begin(t, iar => + { + arCallback = iar; + + Assert.True(iar.CompletedSynchronously); + Assert.True(iar.IsCompleted); + Assert.Same(state, iar.AsyncState); + + Assert.Equal(id, Environment.CurrentManagedThreadId); + + Assert.Equal(42, TaskToAsyncResult.End(iar)); + }, state); + + Assert.Same(ar, arCallback); + Assert.True(ar.CompletedSynchronously); + Assert.True(ar.IsCompleted); + Assert.Same(state, ar.AsyncState); + } + + [Fact] + public async void BeginFromTask_CompletedAsynchronously_CallbackInvokedAsynchronously() + { + var tcs = new TaskCompletionSource(); + var invoked = new TaskCompletionSource(); + + var tl = new ThreadLocal(); + tl.Value = 42; + IAsyncResult ar = TaskToAsyncResult.Begin(tcs.Task, iar => + { + Assert.NotEqual(42, tl.Value); + Assert.False(iar.CompletedSynchronously); + Assert.True(iar.IsCompleted); + Assert.Null(iar.AsyncState); + invoked.SetResult(); + }, null); + tl.Value = 0; + + Assert.False(invoked.Task.IsCompleted); + Assert.False(ar.CompletedSynchronously); + Assert.False(ar.IsCompleted); + Assert.Null(ar.AsyncState); + Assert.NotNull(ar.AsyncWaitHandle); + Assert.False(ar.AsyncWaitHandle.WaitOne(0)); + + tcs.SetResult(); + await invoked.Task; + + Assert.False(ar.CompletedSynchronously); + Assert.True(ar.IsCompleted); + Assert.Null(ar.AsyncState); + Assert.NotNull(ar.AsyncWaitHandle); + Assert.True(ar.AsyncWaitHandle.WaitOne(0)); + } + + [Fact] + public void EndFromTask_PropagatesExceptions() + { + IAsyncResult ar = TaskToAsyncResult.Begin(Task.FromException(new FormatException()), null, null); + Assert.Throws(() => TaskToAsyncResult.End(ar)); + + ar = TaskToAsyncResult.Begin(Task.FromException(new FormatException()), null, null); + Assert.Throws(() => TaskToAsyncResult.End(ar)); + } + + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + public async Task WithFromAsync_IAsyncResult_Roundtrips() + { + var tcs = new TaskCompletionSource(); + var invoked = new TaskCompletionSource(); + _ = Task.Factory.FromAsync(TaskToAsyncResult.Begin(tcs.Task, null, null), iar => + { + invoked.SetResult(); + }); + tcs.SetResult(); + await invoked.Task; + } + + [Fact] + public async Task WithFromAsync_Delegate_Roundtrips() + { + var tcs = new TaskCompletionSource(); + var invoked = new TaskCompletionSource(); + _ = Task.Factory.FromAsync( + (callback, state) => TaskToAsyncResult.Begin(tcs.Task, callback, state), + iar => invoked.SetResult(), + new object()); + tcs.SetResult(); + await invoked.Task; + } + } + + internal sealed class NonTaskIAsyncResult : IAsyncResult + { + public object? AsyncState { get; set; } + public WaitHandle AsyncWaitHandle { get; set; } + public bool CompletedSynchronously { get; set; } + public bool IsCompleted { get; set; } + } +} diff --git a/src/mono/mono/tests/threadpool-exceptions8.cs b/src/mono/mono/tests/threadpool-exceptions8.cs index 2049b6e..33ed30d 100644 --- a/src/mono/mono/tests/threadpool-exceptions8.cs +++ b/src/mono/mono/tests/threadpool-exceptions8.cs @@ -70,7 +70,7 @@ public class Tests { var d = new UnhandledExceptionEventHandler (helper.OnUnhandled); AppDomain.CurrentDomain.UnhandledException += d; - // this is TaskToApm.Begin (..., callback) where the callback is helper.WhenCompleted + // this is TaskToAsyncResult.Begin (..., callback) where the callback is helper.WhenCompleted Task.Delay (100).GetAwaiter().OnCompleted (helper.WhenCompleted); var wasSet = helper.WaitForExn (10000); // wait upto 10 seconds for the task to throw -- 2.7.4