From ff82fd770c08479984510af98c7e9e0a87e1a74a Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 14 May 2018 17:54:29 -0400 Subject: [PATCH] Add missing Read/Write{Async} overrides on Streams in ref assemblies (dotnet/corefx#29658) For non-sealed types, not specifying an override in a ref can lead to a derived type skipping the method in the hierarchy when calling to base.Method(). Commit migrated from https://github.com/dotnet/corefx/commit/33b44346378ba0caebb1ab96ab015e4098868c16 --- .../ref/System.IO.Compression.Brotli.cs | 4 ++++ .../System.IO.Compression/ref/System.IO.Compression.cs | 6 ++++++ .../ref/System.IO.IsolatedStorage.cs | 7 +++++++ .../System/IO/IsolatedStorage/IsolatedStorageFileStream.cs | 10 ++++++++++ src/libraries/System.IO.Pipes/ref/System.IO.Pipes.cs | 4 ++++ src/libraries/System.Net.Security/ref/System.Net.Security.cs | 4 ++++ .../System.Net.Sockets/ref/System.Net.Sockets.netcoreapp.cs | 7 +++++++ .../src/System/Net/Sockets/NetworkStream.cs | 12 ++++++------ .../ref/System.Runtime.InteropServices.cs | 2 ++ src/libraries/System.Runtime/ref/System.Runtime.cs | 4 ++++ 10 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs b/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs index dd19907..8a76e27 100644 --- a/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs +++ b/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs @@ -40,12 +40,16 @@ namespace System.IO.Compression public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { throw null; } public override int EndRead(IAsyncResult asyncResult) { throw null; } public override int Read(byte[] buffer, int offset, int count) { throw null; } + public override int Read(System.Span buffer) { throw null; } public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { throw null; } public override void EndWrite(IAsyncResult asyncResult) { } public override void Write(byte[] buffer, int offset, int count) { } + public override void Write(System.ReadOnlySpan buffer) { throw null; } public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } } } diff --git a/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs b/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs index 67c9eb0..323445b 100644 --- a/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs +++ b/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs @@ -37,12 +37,14 @@ namespace System.IO.Compression public override int EndRead(IAsyncResult asyncResult) { throw null; } public override int Read(byte[] array, int offset, int count) { throw null; } public override System.Threading.Tasks.Task ReadAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { throw null; } public override void EndWrite(IAsyncResult asyncResult) { } public override void Write(byte[] array, int offset, int count) { } public override System.Threading.Tasks.Task WriteAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } } public partial class GZipStream : System.IO.Stream { @@ -61,13 +63,17 @@ namespace System.IO.Compression public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { throw null; } public override int EndRead(IAsyncResult asyncResult) { throw null; } public override int Read(byte[] array, int offset, int count) { throw null; } + public override int Read(System.Span buffer) { throw null; } public override System.Threading.Tasks.Task ReadAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { throw null; } public override void EndWrite(IAsyncResult asyncResult) { } public override void Write(byte[] array, int offset, int count) { } + public override void Write(System.ReadOnlySpan buffer) { } public override System.Threading.Tasks.Task WriteAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } } public partial class ZipArchive : System.IDisposable { diff --git a/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs b/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs index fd9e8a2..9a8009d 100644 --- a/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs +++ b/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs @@ -127,13 +127,20 @@ namespace System.IO.IsolatedStorage public override void EndWrite(System.IAsyncResult asyncResult) { } public override void Flush() { } public override void Flush(bool flushToDisk) { } + public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; } public override void Lock(long position, long length) { } public override int Read(byte[] buffer, int offset, int count) { throw null; } + public override int Read(System.Span buffer) { throw null; } + public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override int ReadByte() { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } public override void Unlock(long position, long length) { } public override void Write(byte[] buffer, int offset, int count) { } + public override void Write(System.ReadOnlySpan buffer) { } + public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override void WriteByte(byte value) { } } diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs index 84f5588..4e59bab 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs @@ -242,6 +242,11 @@ namespace System.IO.IsolatedStorage return _fs.Read(buffer, offset, count); } + public override int Read(System.Span buffer) + { + return _fs.Read(buffer); + } + public override Task ReadAsync(byte[] buffer, int offset, int count, Threading.CancellationToken cancellationToken) { return _fs.ReadAsync(buffer, offset, count, cancellationToken); @@ -269,6 +274,11 @@ namespace System.IO.IsolatedStorage _fs.Write(buffer, offset, count); } + public override void Write(System.ReadOnlySpan buffer) + { + _fs.Write(buffer); + } + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { return _fs.WriteAsync(buffer, offset, count, cancellationToken); diff --git a/src/libraries/System.IO.Pipes/ref/System.IO.Pipes.cs b/src/libraries/System.IO.Pipes/ref/System.IO.Pipes.cs index 2b0142f..eb08501 100644 --- a/src/libraries/System.IO.Pipes/ref/System.IO.Pipes.cs +++ b/src/libraries/System.IO.Pipes/ref/System.IO.Pipes.cs @@ -122,12 +122,16 @@ namespace System.IO.Pipes public override void EndWrite(System.IAsyncResult asyncResult) { throw null; } public override void Flush() { } public override int Read(byte[] buffer, int offset, int count) { throw null; } + public override int Read(System.Span buffer) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override int ReadByte() { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } protected void InitializeHandle(Microsoft.Win32.SafeHandles.SafePipeHandle handle, bool isExposed, bool isAsync) { } public override void SetLength(long value) { } public void WaitForPipeDrain() { } public override void Write(byte[] buffer, int offset, int count) { } + public override void Write(System.ReadOnlySpan buffer) { } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override void WriteByte(byte value) { } } public delegate void PipeStreamImpersonationWorker(); diff --git a/src/libraries/System.Net.Security/ref/System.Net.Security.cs b/src/libraries/System.Net.Security/ref/System.Net.Security.cs index 785eadd..403259d 100644 --- a/src/libraries/System.Net.Security/ref/System.Net.Security.cs +++ b/src/libraries/System.Net.Security/ref/System.Net.Security.cs @@ -206,11 +206,15 @@ namespace System.Net.Security public override void Flush() { } public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; } public override int Read(byte[] buffer, int offset, int count) { throw null; } + public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, CancellationToken cancellationToken = default) { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } public virtual System.Threading.Tasks.Task ShutdownAsync() { throw null; } public void Write(byte[] buffer) { } public override void Write(byte[] buffer, int offset, int count) { } + public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } } } namespace System.Security.Authentication diff --git a/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.netcoreapp.cs b/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.netcoreapp.cs index 75030f8..24df43e 100644 --- a/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.netcoreapp.cs +++ b/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.netcoreapp.cs @@ -8,6 +8,13 @@ namespace System.Net.Sockets { + public partial class NetworkStream : System.IO.Stream + { + public override int Read(System.Span buffer) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } + public override void Write(System.ReadOnlySpan buffer) { } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } + } public partial class Socket : System.IDisposable { public int Receive(Span buffer) { throw null; } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetworkStream.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetworkStream.cs index d8ab22b..1bdf6a1 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetworkStream.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetworkStream.cs @@ -305,20 +305,20 @@ namespace System.Net.Sockets #endif } - public override int Read(Span destination) + public override int Read(Span buffer) { if (GetType() != typeof(NetworkStream)) { // NetworkStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior // to this Read(Span) overload being introduced. In that case, this Read(Span) overload // should use the behavior of Read(byte[],int,int) overload. - return base.Read(destination); + return base.Read(buffer); } if (_cleanedUp) throw new ObjectDisposedException(GetType().FullName); if (!CanRead) throw new InvalidOperationException(SR.net_writeonlystream); - int bytesRead = _streamSocket.Receive(destination, SocketFlags.None, out SocketError errorCode); + int bytesRead = _streamSocket.Receive(buffer, SocketFlags.None, out SocketError errorCode); if (errorCode != SocketError.Success) { var exception = new SocketException((int)errorCode); @@ -396,21 +396,21 @@ namespace System.Net.Sockets #endif } - public override void Write(ReadOnlySpan source) + public override void Write(ReadOnlySpan buffer) { if (GetType() != typeof(NetworkStream)) { // NetworkStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior // to this Write(ReadOnlySpan) overload being introduced. In that case, this Write(ReadOnlySpan) // overload should use the behavior of Write(byte[],int,int) overload. - base.Write(source); + base.Write(buffer); return; } if (_cleanedUp) throw new ObjectDisposedException(GetType().FullName); if (!CanWrite) throw new InvalidOperationException(SR.net_readonlystream); - _streamSocket.Send(source, SocketFlags.None, out SocketError errorCode); + _streamSocket.Send(buffer, SocketFlags.None, out SocketError errorCode); if (errorCode != SocketError.Success) { var exception = new SocketException((int)errorCode); diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index bf31dbc..067d9cf 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -108,12 +108,14 @@ namespace System.IO public override int Read(byte[] buffer, int offset, int count) { throw null; } public override int Read(System.Span destination) { throw null; } public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override int ReadByte() { throw null; } public override long Seek(long offset, System.IO.SeekOrigin loc) { throw null; } public override void SetLength(long value) { } public override void Write(byte[] buffer, int offset, int count) { } public override void Write(System.ReadOnlySpan source) { } public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override void WriteByte(byte value) { } } } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index abab3f4..7b1ed27 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -5075,13 +5075,17 @@ namespace System.IO public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; } public virtual void Lock(long position, long length) { } public override int Read(byte[] array, int offset, int count) { throw null; } + public override int Read(System.Span buffer) { throw null; } public override System.Threading.Tasks.Task ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask ReadAsync(System.Memory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override int ReadByte() { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } public virtual void Unlock(long position, long length) { } public override void Write(byte[] array, int offset, int count) { } + public override void Write(System.ReadOnlySpan buffer) { throw null; } public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask WriteAsync(System.ReadOnlyMemory buffer, System.Threading.CancellationToken cancellationToken = default) { throw null; } public override void WriteByte(byte value) { } } public enum HandleInheritability -- 2.7.4