44using System ;
55using System . IO ;
66using System . IO . Pipelines ;
7+ using System . Threading ;
78using System . Threading . Tasks ;
89using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Http ;
910using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Infrastructure ;
1213
1314namespace Microsoft . AspNetCore . Server . Kestrel . Core . Adapter . Internal
1415{
15- public class AdaptedPipeline : IDuplexPipe
16+ public class AdaptedPipeline : IDuplexPipe , IDisposable
1617 {
1718 private static readonly int MinAllocBufferSize = KestrelMemoryPool . MinimumSegmentSize / 2 ;
1819
1920 private readonly IDuplexPipe _transport ;
2021
21- public AdaptedPipeline ( IDuplexPipe transport ,
22- Pipe inputPipe ,
22+ public AdaptedPipeline ( Pipe inputPipe ,
2323 Pipe outputPipe ,
24- IKestrelTrace log )
24+ ILogger log ,
25+ IDuplexPipe transport = null )
2526 {
2627 _transport = transport ;
2728 Input = inputPipe ;
@@ -33,7 +34,7 @@ public AdaptedPipeline(IDuplexPipe transport,
3334
3435 public Pipe Output { get ; }
3536
36- public IKestrelTrace Log { get ; }
37+ public ILogger Log { get ; }
3738
3839 PipeReader IDuplexPipe . Input => Input . Reader ;
3940
@@ -111,7 +112,8 @@ private async Task WriteOutputAsync(Stream stream)
111112 finally
112113 {
113114 Output . Reader . Complete ( ) ;
114- _transport . Output . Complete ( ) ;
115+
116+ _transport ? . Output . Complete ( ) ;
115117 }
116118 }
117119
@@ -163,10 +165,17 @@ private async Task ReadInputAsync(Stream stream)
163165 finally
164166 {
165167 Input . Writer . Complete ( error ) ;
168+
166169 // The application could have ended the input pipe so complete
167170 // the transport pipe as well
168- _transport . Input . Complete ( ) ;
171+ _transport ? . Input . Complete ( ) ;
169172 }
170173 }
174+
175+ public void Dispose ( )
176+ {
177+ Input . Reader . Complete ( ) ;
178+ Output . Writer . Complete ( ) ;
179+ }
171180 }
172181}
0 commit comments