Override the APM methods on AsyncWindowsFileStreamStrategy. (#55203)
authorTheodore Tsirpanis <12659251+teo-tsirpanis@users.noreply.github.com>
Wed, 14 Jul 2021 19:01:43 +0000 (22:01 +0300)
committerGitHub <noreply@github.com>
Wed, 14 Jul 2021 19:01:43 +0000 (15:01 -0400)
* Override the APM methods on AsyncWindowsFileStreamStrategy.

Closes #55172.

* Address PR feedback.

* Update src/libraries/System.Private.CoreLib/src/System/IO/Strategies/AsyncWindowsFileStreamStrategy.cs

* Update AsyncWindowsFileStreamStrategy.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Private.CoreLib/src/System/IO/Strategies/AsyncWindowsFileStreamStrategy.cs

index c83b58921c4e64477873779c433eafad81176bcb..0f59f6748a1a43cba85bbe1f63c26b8c1334cd72 100644 (file)
@@ -28,7 +28,7 @@ namespace System.IO.Strategies
         public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
             => ReadAsyncInternal(destination, cancellationToken);
 
-        private unsafe ValueTask<int> ReadAsyncInternal(Memory<byte> destination, CancellationToken cancellationToken = default)
+        private unsafe ValueTask<int> ReadAsyncInternal(Memory<byte> destination, CancellationToken cancellationToken)
         {
             if (!CanRead)
             {
@@ -139,5 +139,15 @@ namespace System.IO.Strategies
                 }
             }
         }
+
+        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<int>(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);
     }
 }