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

Commit dee5c34

Browse files
committed
Compiles
1 parent 5573f26 commit dee5c34

31 files changed

+3298
-46
lines changed

src/System.IO.Pipelines/System.Threading.Channels.sln renamed to src/System.IO.Pipelines/System.IO.Pipelines.sln

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 14
3-
VisualStudioVersion = 14.0.25420.1
2+
# Visual Studio 15
3+
VisualStudioVersion = 15.0.27325.3006
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO.Pipelines.Tests", "tests\System.IO.Pipelines.Tests.csproj", "{9E984EB2-827E-4029-9647-FB5F8B67C553}"
66
ProjectSection(ProjectDependencies) = postProject
77
{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977} = {1032D5F6-5AE7-4002-A0E4-FEBEADFEA977}
88
EndProjectSection
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO.Pipelines.Performance.Tests", "tests\Performance\System.IO.Pipelines.Performance.Tests.csproj", "{11ABE2F8-4FB9-48AC-91AA-D04503059550}"
11-
ProjectSection(ProjectDependencies) = postProject
12-
{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977} = {1032D5F6-5AE7-4002-A0E4-FEBEADFEA977}
13-
EndProjectSection
14-
EndProject
1510
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO.Pipelines", "src\System.IO.Pipelines.csproj", "{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977}"
1611
ProjectSection(ProjectDependencies) = postProject
1712
{9C524CA0-92FF-437B-B568-BCE8A794A69A} = {9C524CA0-92FF-437B-B568-BCE8A794A69A}
@@ -35,10 +30,6 @@ Global
3530
{9E984EB2-827E-4029-9647-FB5F8B67C553}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
3631
{9E984EB2-827E-4029-9647-FB5F8B67C553}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
3732
{9E984EB2-827E-4029-9647-FB5F8B67C553}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
38-
{11ABE2F8-4FB9-48AC-91AA-D04503059550}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
39-
{11ABE2F8-4FB9-48AC-91AA-D04503059550}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
40-
{11ABE2F8-4FB9-48AC-91AA-D04503059550}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
41-
{11ABE2F8-4FB9-48AC-91AA-D04503059550}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
4233
{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
4334
{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
4435
{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
@@ -53,8 +44,10 @@ Global
5344
EndGlobalSection
5445
GlobalSection(NestedProjects) = preSolution
5546
{9E984EB2-827E-4029-9647-FB5F8B67C553} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
56-
{11ABE2F8-4FB9-48AC-91AA-D04503059550} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
5747
{1032D5F6-5AE7-4002-A0E4-FEBEADFEA977} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
5848
{9C524CA0-92FF-437B-B568-BCE8A794A69A} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
5949
EndGlobalSection
50+
GlobalSection(ExtensibilityGlobals) = postSolution
51+
SolutionGuid = {895BDE3D-0E51-485D-908E-16FB1A74FA64}
52+
EndGlobalSection
6053
EndGlobal
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
// ------------------------------------------------------------------------------
5+
// Changes to this file must follow the http://aka.ms/api-review process.
6+
// ------------------------------------------------------------------------------
7+
8+
namespace System.IO.Pipelines
9+
{
10+
public partial struct FlushResult
11+
{
12+
private int _dummy;
13+
public FlushResult(bool isCanceled, bool isCompleted) { throw null; }
14+
public bool IsCanceled { get { throw null; } }
15+
public bool IsCompleted { get { throw null; } }
16+
}
17+
public partial interface IDuplexPipe : System.IDisposable
18+
{
19+
System.IO.Pipelines.PipeReader Input { get; }
20+
System.IO.Pipelines.PipeWriter Output { get; }
21+
}
22+
public partial interface IPipeAwaiter<out T>
23+
{
24+
bool IsCompleted { get; }
25+
T GetResult();
26+
void OnCompleted(System.Action continuation);
27+
}
28+
public sealed partial class Pipe
29+
{
30+
public Pipe() { }
31+
public Pipe(System.IO.Pipelines.PipeOptions options) { }
32+
public System.IO.Pipelines.PipeReader Reader { get { throw null; } }
33+
public System.IO.Pipelines.PipeWriter Writer { get { throw null; } }
34+
public void Reset() { }
35+
}
36+
public partial struct PipeAwaiter<T> : System.Runtime.CompilerServices.ICriticalNotifyCompletion, System.Runtime.CompilerServices.INotifyCompletion
37+
{
38+
private object _dummy;
39+
public PipeAwaiter(System.IO.Pipelines.IPipeAwaiter<T> awaiter) { throw null; }
40+
public bool IsCompleted { get { throw null; } }
41+
public System.IO.Pipelines.PipeAwaiter<T> GetAwaiter() { throw null; }
42+
public T GetResult() { throw null; }
43+
public void OnCompleted(System.Action continuation) { }
44+
public void UnsafeOnCompleted(System.Action continuation) { }
45+
}
46+
public partial class PipeOptions
47+
{
48+
public PipeOptions(System.Buffers.MemoryPool<byte> pool = null, System.IO.Pipelines.PipeScheduler readerScheduler = null, System.IO.Pipelines.PipeScheduler writerScheduler = null, long pauseWriterThreshold = (long)0, long resumeWriterThreshold = (long)0, int minimumSegmentSize = 2048) { }
49+
public static System.IO.Pipelines.PipeOptions Default { get { throw null; } }
50+
public int MinimumSegmentSize { get { throw null; } }
51+
public long PauseWriterThreshold { get { throw null; } }
52+
public System.Buffers.MemoryPool<byte> Pool { get { throw null; } }
53+
public System.IO.Pipelines.PipeScheduler ReaderScheduler { get { throw null; } }
54+
public long ResumeWriterThreshold { get { throw null; } }
55+
public System.IO.Pipelines.PipeScheduler WriterScheduler { get { throw null; } }
56+
}
57+
public abstract partial class PipeReader
58+
{
59+
protected PipeReader() { }
60+
public abstract void AdvanceTo(System.SequencePosition consumed);
61+
public abstract void AdvanceTo(System.SequencePosition consumed, System.SequencePosition examined);
62+
public abstract void CancelPendingRead();
63+
public abstract void Complete(System.Exception exception = null);
64+
public abstract void OnWriterCompleted(System.Action<System.Exception, object> callback, object state);
65+
public abstract System.IO.Pipelines.PipeAwaiter<System.IO.Pipelines.ReadResult> ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
66+
public abstract bool TryRead(out System.IO.Pipelines.ReadResult result);
67+
}
68+
public abstract partial class PipeScheduler
69+
{
70+
protected PipeScheduler() { }
71+
public static System.IO.Pipelines.PipeScheduler Inline { get { throw null; } }
72+
public static System.IO.Pipelines.PipeScheduler ThreadPool { get { throw null; } }
73+
public abstract void Schedule(System.Action action);
74+
public abstract void Schedule(System.Action<object> action, object state);
75+
}
76+
public abstract partial class PipeWriter : System.Buffers.IBufferWriter
77+
{
78+
protected PipeWriter() { }
79+
public abstract void Advance(int bytes);
80+
public abstract void CancelPendingFlush();
81+
public abstract void Commit();
82+
public abstract void Complete(System.Exception exception = null);
83+
public abstract System.IO.Pipelines.PipeAwaiter<System.IO.Pipelines.FlushResult> FlushAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
84+
public abstract System.Memory<byte> GetMemory(int minimumLength = 0);
85+
public abstract System.Span<byte> GetSpan(int minimumLength = 0);
86+
public abstract void OnReaderCompleted(System.Action<System.Exception, object> callback, object state);
87+
public virtual System.IO.Pipelines.PipeAwaiter<System.IO.Pipelines.FlushResult> WriteAsync(System.ReadOnlyMemory<byte> source) { throw null; }
88+
}
89+
public partial struct ReadResult
90+
{
91+
private object _dummy;
92+
public ReadResult(System.Buffers.ReadOnlySequence<byte> buffer, bool isCanceled, bool isCompleted) { throw null; }
93+
public System.Buffers.ReadOnlySequence<byte> Buffer { get { throw null; } }
94+
public bool IsCanceled { get { throw null; } }
95+
public bool IsCompleted { get { throw null; } }
96+
}
97+
}

src/System.IO.Pipelines/ref/System.IO.Pipelines.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
<Compile Include="System.IO.Pipelines.cs" />
1111
</ItemGroup>
1212
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard'">
13+
<Reference Include="System.Buffers" />
14+
<Reference Include="System.Memory" />
1315
<Reference Include="netstandard" />
1416
</ItemGroup>
1517
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.3'">
18+
<Reference Include="System.Buffers" />
19+
<Reference Include="System.Memory" />
1620
<Reference Include="System.Runtime" />
17-
<Reference Include="System.Threading.Tasks" />
1821
</ItemGroup>
1922
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
2023
</Project>

src/System.IO.Pipelines/src/System.IO.Pipelines.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@
3232
<Compile Include="System\IO\Pipelines\ThrowHelper.cs" />
3333
</ItemGroup>
3434
<ItemGroup>
35+
<Reference Include="System.Buffers" />
3536
<Reference Include="System.Collections" />
3637
<Reference Include="System.Collections.Concurrent" />
3738
<Reference Include="System.Diagnostics.Debug" />
39+
<Reference Include="System.Memory" />
3840
<Reference Include="System.Resources.ResourceManager" />
3941
<Reference Include="System.Runtime" />
4042
<Reference Include="System.Runtime.Extensions" />
4143
<Reference Include="System.Threading" />
4244
<Reference Include="System.Threading.Tasks" />
4345
<Reference Include="System.Threading.Tasks.Extensions" />
44-
<Reference Include="System.Memory" />
4546
</ItemGroup>
4647
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
4748
</Project>

src/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace System.IO.Pipelines
1111
/// <summary>
1212
/// Default <see cref="PipeWriter"/> and <see cref="PipeReader"/> implementation.
1313
/// </summary>
14-
public sealed class Pipe : IPipeAwaiter<ReadResult>, IPipeAwaiter<FlushResult>
14+
public sealed class Pipe
1515
{
1616
private const int SegmentPoolSize = 16;
1717

@@ -61,6 +61,9 @@ public sealed class Pipe : IPipeAwaiter<ReadResult>, IPipeAwaiter<FlushResult>
6161

6262
private bool _disposed;
6363

64+
private DefaultPipeReader _reader;
65+
private DefaultPipeWriter _writer;
66+
6467
internal long Length => _length;
6568

6669
/// <summary>
@@ -97,6 +100,10 @@ public Pipe(PipeOptions options)
97100

98101
_bufferSegmentPool = new BufferSegment[SegmentPoolSize];
99102

103+
_readingState = default;
104+
_readerCompletion = default;
105+
_writerCompletion = default;
106+
100107
_pool = options.Pool;
101108
_minimumSegmentSize = options.MinimumSegmentSize;
102109
_maximumSizeHigh = options.PauseWriterThreshold;
@@ -105,8 +112,8 @@ public Pipe(PipeOptions options)
105112
_writerScheduler = options.WriterScheduler ?? PipeScheduler.Inline;
106113
_readerAwaitable = new PipeAwaitable(completed: false);
107114
_writerAwaitable = new PipeAwaitable(completed: true);
108-
Reader = new DefaultPipeReader(this);
109-
Writer = new DefaultPipeWriter(this);
115+
_reader = new DefaultPipeReader(this);
116+
_writer = new DefaultPipeWriter(this);
110117
}
111118

112119
private void ResetState()
@@ -315,7 +322,7 @@ internal PipeAwaiter<FlushResult> FlushAsync(CancellationToken cancellationToken
315322

316323
TrySchedule(_readerScheduler, awaitable);
317324

318-
return new PipeAwaiter<FlushResult>(this);
325+
return new PipeAwaiter<FlushResult>(_writer);
319326
}
320327

321328
internal void CompleteWriter(Exception exception)
@@ -490,9 +497,6 @@ internal void OnWriterCompleted(Action<Exception, object> callback, object state
490497
}
491498
}
492499

493-
/// <summary>
494-
/// Cancel to currently pending call to <see cref="ReadAsync"/> without completing the <see cref="PipeReader"/>.
495-
/// </summary>
496500
internal void CancelPendingRead()
497501
{
498502
Action awaitable;
@@ -503,9 +507,6 @@ internal void CancelPendingRead()
503507
TrySchedule(_readerScheduler, awaitable);
504508
}
505509

506-
/// <summary>
507-
/// Cancel to currently pending call to <see cref="WritableBuffer.FlushAsync"/> without completing the <see cref="PipeWriter"/>.
508-
/// </summary>
509510
internal void CancelPendingFlush()
510511
{
511512
Action awaitable;
@@ -547,7 +548,7 @@ internal PipeAwaiter<ReadResult> ReadAsync(CancellationToken token)
547548
cancellationTokenRegistration = _readerAwaitable.AttachToken(token, _signalReaderAwaitable, this);
548549
}
549550
cancellationTokenRegistration.Dispose();
550-
return new PipeAwaiter<ReadResult>(this);
551+
return new PipeAwaiter<ReadResult>(_reader);
551552
}
552553

553554
internal bool TryRead(out ReadResult result)
@@ -618,9 +619,9 @@ private void CompletePipe()
618619
}
619620
}
620621

621-
bool IPipeAwaiter<ReadResult>.IsCompleted => _readerAwaitable.IsCompleted;
622+
internal bool IsReadAsyncCompleted => _readerAwaitable.IsCompleted;
622623

623-
void IPipeAwaiter<ReadResult>.OnCompleted(Action continuation)
624+
internal void OnReadAsyncCompleted(Action continuation)
624625
{
625626
Action awaitable;
626627
bool doubleCompletion;
@@ -635,7 +636,7 @@ void IPipeAwaiter<ReadResult>.OnCompleted(Action continuation)
635636
TrySchedule(_readerScheduler, awaitable);
636637
}
637638

638-
ReadResult IPipeAwaiter<ReadResult>.GetResult()
639+
internal ReadResult GetReadAsyncResult()
639640
{
640641
if (!_readerAwaitable.IsCompleted)
641642
{
@@ -682,9 +683,9 @@ private void GetResult(ref ReadResult result)
682683
}
683684
}
684685

685-
bool IPipeAwaiter<FlushResult>.IsCompleted => _writerAwaitable.IsCompleted;
686+
internal bool IsFlushAsyncCompleted => _writerAwaitable.IsCompleted;
686687

687-
FlushResult IPipeAwaiter<FlushResult>.GetResult()
688+
internal FlushResult GetFlushAsyncResult()
688689
{
689690
var result = new FlushResult();
690691
lock (_sync)
@@ -708,7 +709,7 @@ FlushResult IPipeAwaiter<FlushResult>.GetResult()
708709
return result;
709710
}
710711

711-
void IPipeAwaiter<FlushResult>.OnCompleted(Action continuation)
712+
internal void OnFlushAsyncCompleted(Action continuation)
712713
{
713714
Action awaitable;
714715
bool doubleCompletion;
@@ -743,10 +744,19 @@ private void WriterCancellationRequested()
743744
TrySchedule(_writerScheduler, action);
744745
}
745746

746-
public PipeReader Reader { get; }
747+
/// <summary>
748+
/// Gets the <see cref="PipeReader"/> for this pipe.
749+
/// </summary>
750+
public PipeReader Reader => _reader;
747751

748-
public PipeWriter Writer { get; }
752+
/// <summary>
753+
/// Gets the <see cref="PipeWriter"/> for this pipe.
754+
/// </summary>
755+
public PipeWriter Writer => _writer;
749756

757+
/// <summary>
758+
/// Resets the pipe
759+
/// </summary>
750760
public void Reset()
751761
{
752762
lock (_sync)
@@ -761,7 +771,7 @@ public void Reset()
761771
}
762772
}
763773

764-
private sealed class DefaultPipeReader : PipeReader
774+
private sealed class DefaultPipeReader : PipeReader, IPipeAwaiter<ReadResult>
765775
{
766776
private readonly Pipe _pipe;
767777

@@ -804,9 +814,15 @@ public override void OnWriterCompleted(Action<Exception, object> callback, objec
804814
{
805815
_pipe.OnWriterCompleted(callback, state);
806816
}
817+
818+
public bool IsCompleted => _pipe.IsReadAsyncCompleted;
819+
820+
public ReadResult GetResult() => _pipe.GetReadAsyncResult();
821+
822+
public void OnCompleted(Action continuation) => _pipe.OnReadAsyncCompleted(continuation);
807823
}
808824

809-
private sealed class DefaultPipeWriter : PipeWriter
825+
private sealed class DefaultPipeWriter : PipeWriter, IPipeAwaiter<FlushResult>
810826
{
811827
private readonly Pipe _pipe;
812828

@@ -854,6 +870,12 @@ public override Span<byte> GetSpan(int minimumLength = 0)
854870
{
855871
return _pipe.GetSpan(minimumLength);
856872
}
873+
874+
public bool IsCompleted => _pipe.IsFlushAsyncCompleted;
875+
876+
public FlushResult GetResult() => _pipe.GetFlushAsyncResult();
877+
878+
public void OnCompleted(Action continuation) => _pipe.OnFlushAsyncCompleted(continuation);
857879
}
858880
}
859881
}

src/System.IO.Pipelines/src/System/IO/Pipelines/PipeAwaiter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public struct PipeAwaiter<T> : ICriticalNotifyCompletion
1313
{
1414
private readonly IPipeAwaiter<T> _awaiter;
1515

16+
/// <summary>
17+
/// Create new instance of <see cref="PipeAwaiter{T}"/> that wraps async operation implemented by <paramref name="awaiter"/>
18+
/// </summary>
1619
public PipeAwaiter(IPipeAwaiter<T> awaiter)
1720
{
1821
_awaiter = awaiter;

src/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class PipeReader
1616
/// </summary>
1717
/// <param name="result">The <see cref="ReadResult"/></param>
1818
/// <returns>True if data was available, or if the call was canceled or the writer was completed.</returns>
19-
/// <remarks>If the pipe returns false, there's no need to call <see cref="AdvanceTo"/>.</remarks>
19+
/// <remarks>If the pipe returns false, there's no need to call <see cref="AdvanceTo(SequencePosition, SequencePosition)"/>.</remarks>
2020
public abstract bool TryRead(out ReadResult result);
2121

2222
/// <summary>

src/System.IO.Pipelines/src/System/IO/Pipelines/PipeScheduler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public abstract class PipeScheduler
2323
public static PipeScheduler Inline => _inlineScheduler;
2424

2525
/// <summary>
26-
/// Requests <see cref="action"/> to be run on scheduler
26+
/// Requests <paramref name="action"/> to be run on scheduler
2727
/// </summary>
2828
public abstract void Schedule(Action action);
2929

3030
/// <summary>
31-
/// Requests <see cref="action"/> to be run on scheduler with <see cref="state"/> being passed in
31+
/// Requests <paramref name="action"/> to be run on scheduler with <paramref name="state"/> being passed in
3232
/// </summary>
3333
public abstract void Schedule(Action<object> action, object state);
3434
}

0 commit comments

Comments
 (0)