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

Commit 59175ce

Browse files
committed
Remove some erroneous / unnecessary asserts in PipeStream on Unix
The ReadAsyncCore / WriteAsyncCore methods were erroneously asserting for CanRead/CanWrite, when the implementation should instead have been failing with an exception. It subsequently does, but in debug builds the asserts cause it to assert first. There were also a bunch of asserts that were unnecessary because the values were just verified by the caller and are about to be verified again by the asynchronously invoked method. I've simply removed all of these asserts.
1 parent fee1721 commit 59175ce

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,7 @@ private unsafe int ReadCore(byte[] buffer, int offset, int count)
125125
[SecuritySafeCritical]
126126
private Task<int> ReadAsyncCore(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
127127
{
128-
Debug.Assert(_handle != null, "_handle is null");
129-
Debug.Assert(!_handle.IsClosed, "_handle is closed");
130-
Debug.Assert(CanRead, "can't read");
131-
Debug.Assert(buffer != null, "buffer is null");
132-
Debug.Assert(offset >= 0, "offset is negative");
133-
Debug.Assert(count >= 0, "count is negative");
134-
128+
// Delegate to the base Stream's ReadAsync, which will just invoke Read asynchronously.
135129
return base.ReadAsync(buffer, offset, count, cancellationToken);
136130
}
137131

@@ -164,13 +158,7 @@ private unsafe void WriteCore(byte[] buffer, int offset, int count)
164158
[SecuritySafeCritical]
165159
private Task WriteAsyncCore(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
166160
{
167-
Debug.Assert(_handle != null, "_handle is null");
168-
Debug.Assert(!_handle.IsClosed, "_handle is closed");
169-
Debug.Assert(CanWrite, "can't write");
170-
Debug.Assert(buffer != null, "buffer is null");
171-
Debug.Assert(offset >= 0, "offset is negative");
172-
Debug.Assert(count >= 0, "count is negative");
173-
161+
// Delegate to the base Stream's WriteAsync, which will just invoke Write asynchronously.
174162
return base.WriteAsync(buffer, offset, count, cancellationToken);
175163
}
176164

0 commit comments

Comments
 (0)