private async ValueTask <int> ReadAsyncCore(Memory <byte> destination, CancellationToken cancellationToken) { Debug.Assert(this is NamedPipeClientStream || this is NamedPipeServerStream, $"Expected a named pipe, got a {GetType()}"); try { return(await InternalHandle !.NamedPipeSocket.ReceiveAsync(destination, SocketFlags.None, cancellationToken).ConfigureAwait(false)); } catch (SocketException e) { throw GetIOExceptionForSocketException(e); } }
private async Task WriteAsyncCore(ReadOnlyMemory <byte> source, CancellationToken cancellationToken) { Debug.Assert(this is NamedPipeClientStream || this is NamedPipeServerStream, $"Expected a named pipe, got a {GetType()}"); try { while (source.Length > 0) { int bytesWritten = await _handle !.NamedPipeSocket.SendAsync(source, SocketFlags.None, cancellationToken).ConfigureAwait(false); Debug.Assert(bytesWritten > 0 && bytesWritten <= source.Length); source = source.Slice(bytesWritten); } } catch (SocketException e) { throw GetIOExceptionForSocketException(e); } }