Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Christoforides <alexis@thenull.net>2018-11-07 15:26:46 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2018-11-07 15:26:46 +0300
commit0e5f123f6b1792bf19fe21143a6d668b6ce8f483 (patch)
tree21f59d43b10776b114ea3d40a75d51857a75d384
parentb6a822b7424dab39eee81f0c08160f996c9e9e27 (diff)
[corlib] Import System.IO.Stream/BufferedStream from CoreFX (#26)
Merge with https://github.com/mono/mono/pull/10880
-rw-r--r--src/System.Private.CoreLib/shared/System/IO/Stream.cs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/System.Private.CoreLib/shared/System/IO/Stream.cs b/src/System.Private.CoreLib/shared/System/IO/Stream.cs
index faeb69fb5..5243b48fc 100644
--- a/src/System.Private.CoreLib/shared/System/IO/Stream.cs
+++ b/src/System.Private.CoreLib/shared/System/IO/Stream.cs
@@ -25,6 +25,9 @@ using System.Threading.Tasks;
namespace System.IO
{
+#if MONO
+ [Serializable]
+#endif
public abstract partial class Stream : MarshalByRefObject, IDisposable
{
public static readonly Stream Null = new NullStream();
@@ -35,8 +38,14 @@ namespace System.IO
private const int DefaultCopyBufferSize = 81920;
// To implement Async IO operations on streams that don't support async IO
-
+#if MONO
+ [NonSerialized]
+#endif
private ReadWriteTask _activeReadWriteTask;
+
+#if MONO
+ [NonSerialized]
+#endif
private SemaphoreSlim _asyncActiveSemaphore;
internal SemaphoreSlim EnsureAsyncActiveSemaphoreInitialized()
@@ -372,8 +381,9 @@ namespace System.IO
else
{
byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
- return FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer);
+#if !__MonoCS__
+ return FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer);
async ValueTask<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Memory<byte> localDestination)
{
try
@@ -387,9 +397,27 @@ namespace System.IO
ArrayPool<byte>.Shared.Return(localBuffer);
}
}
+#else
+ return new ValueTask<int> (FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer));
+#endif
}
}
+#if __MonoCS__
+ internal async Task<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Memory<byte> localDestination)
+ {
+ try
+ {
+ int result = await readTask.ConfigureAwait(false);
+ new Span<byte>(localBuffer, 0, result).CopyTo(localDestination.Span);
+ return result;
+ }
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(localBuffer);
+ }
+ }
+#endif
private Task<int> BeginEndReadAsync(byte[] buffer, int offset, int count)
{
if (!HasOverriddenBeginEndRead())