Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Commit 0e5f123

Browse files
alexischrakoeplinger
authored andcommitted
[corlib] Import System.IO.Stream/BufferedStream from CoreFX (#26)
Merge with mono/mono#10880
1 parent b6a822b commit 0e5f123

File tree

1 file changed

+30
-2
lines changed
  • src/System.Private.CoreLib/shared/System/IO

1 file changed

+30
-2
lines changed

src/System.Private.CoreLib/shared/System/IO/Stream.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
namespace System.IO
2727
{
28+
#if MONO
29+
[Serializable]
30+
#endif
2831
public abstract partial class Stream : MarshalByRefObject, IDisposable
2932
{
3033
public static readonly Stream Null = new NullStream();
@@ -35,8 +38,14 @@ public abstract partial class Stream : MarshalByRefObject, IDisposable
3538
private const int DefaultCopyBufferSize = 81920;
3639

3740
// To implement Async IO operations on streams that don't support async IO
38-
41+
#if MONO
42+
[NonSerialized]
43+
#endif
3944
private ReadWriteTask _activeReadWriteTask;
45+
46+
#if MONO
47+
[NonSerialized]
48+
#endif
4049
private SemaphoreSlim _asyncActiveSemaphore;
4150

4251
internal SemaphoreSlim EnsureAsyncActiveSemaphoreInitialized()
@@ -372,8 +381,9 @@ public virtual ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken c
372381
else
373382
{
374383
byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
375-
return FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer);
376384

385+
#if !__MonoCS__
386+
return FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer);
377387
async ValueTask<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Memory<byte> localDestination)
378388
{
379389
try
@@ -387,9 +397,27 @@ async ValueTask<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Mem
387397
ArrayPool<byte>.Shared.Return(localBuffer);
388398
}
389399
}
400+
#else
401+
return new ValueTask<int> (FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer));
402+
#endif
390403
}
391404
}
392405

406+
#if __MonoCS__
407+
internal async Task<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Memory<byte> localDestination)
408+
{
409+
try
410+
{
411+
int result = await readTask.ConfigureAwait(false);
412+
new Span<byte>(localBuffer, 0, result).CopyTo(localDestination.Span);
413+
return result;
414+
}
415+
finally
416+
{
417+
ArrayPool<byte>.Shared.Return(localBuffer);
418+
}
419+
}
420+
#endif
393421
private Task<int> BeginEndReadAsync(byte[] buffer, int offset, int count)
394422
{
395423
if (!HasOverriddenBeginEndRead())

0 commit comments

Comments
 (0)