@@ -39,7 +39,10 @@ public enum FramingType
3939 // 1 byte reads
4040 ByteByByte ,
4141
42- // coalesce reads to biggest chunks possible
42+ // Receive data at chunks, not necessarily respecting frame boundaries
43+ Chunked ,
44+
45+ // Coalesce reads to biggest chunks possible
4346 Coalescing
4447 }
4548
@@ -129,7 +132,6 @@ public async Task Handshake_Success(FramingType framingType, SslProtocols sslPro
129132 Assert . True ( serverStream . ReadCalled , "Mocked read method was not used" ) ;
130133
131134 await TestHelper . PingPong ( client , server ) ;
132-
133135 }
134136
135137 internal class ConfigurableReadStream : Stream
@@ -168,6 +170,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
168170 {
169171 case FramingType . ByteByByte :
170172 return await _stream . ReadAsync ( buffer . Length > 0 ? buffer . Slice ( 0 , 1 ) : buffer , cancellationToken ) ;
173+
171174 case FramingType . Coalescing :
172175 {
173176 if ( buffer . Length > 0 )
@@ -178,6 +181,24 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
178181 }
179182 return await _stream . ReadAsync ( buffer , cancellationToken ) ;
180183 }
184+ case FramingType . Chunked :
185+ {
186+ if ( buffer . Length > 0 )
187+ {
188+ // wait 10ms, this should be enough for the other side to write as much data
189+ // as it will ever write before receiving something back.
190+ await Task . Delay ( 10 ) ;
191+
192+ const int maxRead = 1519 ; // arbitrarily chosen chunk size
193+
194+ if ( buffer . Length > maxRead )
195+ {
196+ buffer = buffer . Slice ( 0 , maxRead ) ;
197+ }
198+ }
199+ return await _stream . ReadAsync ( buffer , cancellationToken ) ;
200+ }
201+
181202 default :
182203 throw new NotImplementedException ( ) ;
183204 }
0 commit comments