@@ -118,8 +118,7 @@ public static void ReadBytes(this Stream stream, OperationContext operationConte
118
118
119
119
while ( count > 0 )
120
120
{
121
- var timeout = operationContext . Timeout == null ? socketTimeout : operationContext . RemainingTimeout ;
122
- var bytesRead = stream . Read ( buffer , offset , count , timeout , operationContext . CancellationToken ) ;
121
+ var bytesRead = stream . Read ( buffer , offset , count , operationContext . RemainingTimeoutOrDefault ( socketTimeout ) , operationContext . CancellationToken ) ;
123
122
if ( bytesRead == 0 )
124
123
{
125
124
throw new EndOfStreamException ( ) ;
@@ -140,8 +139,7 @@ public static void ReadBytes(this Stream stream, OperationContext operationConte
140
139
{
141
140
var backingBytes = buffer . AccessBackingBytes ( offset ) ;
142
141
var bytesToRead = Math . Min ( count , backingBytes . Count ) ;
143
- var timeout = operationContext . Timeout == null ? socketTimeout : operationContext . RemainingTimeout ;
144
- var bytesRead = stream . Read ( backingBytes . Array , backingBytes . Offset , bytesToRead , timeout , operationContext . CancellationToken ) ;
142
+ var bytesRead = stream . Read ( backingBytes . Array , backingBytes . Offset , bytesToRead , operationContext . RemainingTimeoutOrDefault ( socketTimeout ) , operationContext . CancellationToken ) ;
145
143
if ( bytesRead == 0 )
146
144
{
147
145
throw new EndOfStreamException ( ) ;
@@ -160,8 +158,7 @@ public static async Task ReadBytesAsync(this Stream stream, OperationContext ope
160
158
161
159
while ( count > 0 )
162
160
{
163
- var timeout = operationContext . Timeout == null ? socketTimeout : operationContext . RemainingTimeout ;
164
- var bytesRead = await stream . ReadAsync ( buffer , offset , count , timeout , operationContext . CancellationToken ) . ConfigureAwait ( false ) ;
161
+ var bytesRead = await stream . ReadAsync ( buffer , offset , count , operationContext . RemainingTimeoutOrDefault ( socketTimeout ) , operationContext . CancellationToken ) . ConfigureAwait ( false ) ;
165
162
if ( bytesRead == 0 )
166
163
{
167
164
throw new EndOfStreamException ( ) ;
@@ -182,8 +179,7 @@ public static async Task ReadBytesAsync(this Stream stream, OperationContext ope
182
179
{
183
180
var backingBytes = buffer . AccessBackingBytes ( offset ) ;
184
181
var bytesToRead = Math . Min ( count , backingBytes . Count ) ;
185
- var timeout = operationContext . Timeout == null ? socketTimeout : operationContext . RemainingTimeout ;
186
- var bytesRead = await stream . ReadAsync ( backingBytes . Array , backingBytes . Offset , bytesToRead , timeout , operationContext . CancellationToken ) . ConfigureAwait ( false ) ;
182
+ var bytesRead = await stream . ReadAsync ( backingBytes . Array , backingBytes . Offset , bytesToRead , operationContext . RemainingTimeoutOrDefault ( socketTimeout ) , operationContext . CancellationToken ) . ConfigureAwait ( false ) ;
187
183
if ( bytesRead == 0 )
188
184
{
189
185
throw new EndOfStreamException ( ) ;
@@ -279,8 +275,7 @@ public static void WriteBytes(this Stream stream, OperationContext operationCont
279
275
{
280
276
var backingBytes = buffer . AccessBackingBytes ( offset ) ;
281
277
var bytesToWrite = Math . Min ( count , backingBytes . Count ) ;
282
- var timeout = operationContext . Timeout == null ? socketTimeout : operationContext . RemainingTimeout ;
283
- stream . Write ( backingBytes . Array , backingBytes . Offset , bytesToWrite , timeout , operationContext . CancellationToken ) ;
278
+ stream . Write ( backingBytes . Array , backingBytes . Offset , bytesToWrite , operationContext . RemainingTimeoutOrDefault ( socketTimeout ) , operationContext . CancellationToken ) ;
284
279
offset += bytesToWrite ;
285
280
count -= bytesToWrite ;
286
281
}
@@ -297,8 +292,7 @@ public static async Task WriteBytesAsync(this Stream stream, OperationContext op
297
292
{
298
293
var backingBytes = buffer . AccessBackingBytes ( offset ) ;
299
294
var bytesToWrite = Math . Min ( count , backingBytes . Count ) ;
300
- var timeout = operationContext . Timeout == null ? socketTimeout : operationContext . RemainingTimeout ;
301
- await stream . WriteAsync ( backingBytes . Array , backingBytes . Offset , bytesToWrite , timeout , operationContext . CancellationToken ) . ConfigureAwait ( false ) ;
295
+ await stream . WriteAsync ( backingBytes . Array , backingBytes . Offset , bytesToWrite , operationContext . RemainingTimeoutOrDefault ( socketTimeout ) , operationContext . CancellationToken ) . ConfigureAwait ( false ) ;
302
296
offset += bytesToWrite ;
303
297
count -= bytesToWrite ;
304
298
}
0 commit comments