@@ -263,28 +263,15 @@ public async Task RequestProcessingAsync()
263
263
{
264
264
try
265
265
{
266
- var terminated = false ;
267
- while ( ! terminated && ! _requestProcessingStopping )
266
+ while ( ! _requestProcessingStopping )
268
267
{
269
- while ( ! terminated && ! _requestProcessingStopping && ! TakeStartLine ( SocketInput ) )
268
+ if ( ! await ReadStartLineAsync ( ) ||
269
+ ! await ReadHeadersAsync ( ) )
270
270
{
271
- terminated = SocketInput . RemoteIntakeFin ;
272
- if ( ! terminated )
273
- {
274
- await SocketInput ;
275
- }
276
- }
277
-
278
- while ( ! terminated && ! _requestProcessingStopping && ! TakeMessageHeaders ( SocketInput , _requestHeaders ) )
279
- {
280
- terminated = SocketInput . RemoteIntakeFin ;
281
- if ( ! terminated )
282
- {
283
- await SocketInput ;
284
- }
271
+ break ;
285
272
}
286
273
287
- if ( ! terminated && ! _requestProcessingStopping )
274
+ if ( ! _requestProcessingStopping )
288
275
{
289
276
var messageBody = MessageBody . For ( HttpVersion , _requestHeaders , this ) ;
290
277
_keepAlive = messageBody . RequestKeepAlive ;
@@ -337,7 +324,10 @@ public async Task RequestProcessingAsync()
337
324
_responseBody . StopAcceptingWrites ( ) ;
338
325
}
339
326
340
- terminated = ! _keepAlive ;
327
+ if ( ! _keepAlive )
328
+ {
329
+ break ;
330
+ }
341
331
}
342
332
343
333
Reset ( ) ;
@@ -372,6 +362,62 @@ public async Task RequestProcessingAsync()
372
362
}
373
363
}
374
364
}
365
+ private Task < bool > ReadStartLineAsync ( )
366
+ {
367
+ if ( ! _requestProcessingStopping && ! TakeStartLine ( SocketInput ) )
368
+ {
369
+ if ( SocketInput . RemoteIntakeFin )
370
+ {
371
+ return TaskUtilities . CompletedFalseTask ;
372
+ } ;
373
+ return ReadStartLineAwaitAsync ( ) ;
374
+ }
375
+ return TaskUtilities . CompletedTrueTask ;
376
+ }
377
+
378
+ private async Task < bool > ReadStartLineAwaitAsync ( )
379
+ {
380
+ await SocketInput ;
381
+
382
+ while ( ! _requestProcessingStopping && ! TakeStartLine ( SocketInput ) )
383
+ {
384
+ if ( SocketInput . RemoteIntakeFin )
385
+ {
386
+ return false ;
387
+ } ;
388
+
389
+ await SocketInput ;
390
+ }
391
+ return true ;
392
+ }
393
+
394
+ private Task < bool > ReadHeadersAsync ( )
395
+ {
396
+ if ( ! _requestProcessingStopping && ! TakeMessageHeaders ( SocketInput , _requestHeaders ) )
397
+ {
398
+ if ( SocketInput . RemoteIntakeFin )
399
+ {
400
+ return TaskUtilities . CompletedFalseTask ;
401
+ } ;
402
+ return ReadHeadersAwaitAsync ( ) ;
403
+ }
404
+ return TaskUtilities . CompletedTrueTask ;
405
+ }
406
+
407
+ private async Task < bool > ReadHeadersAwaitAsync ( )
408
+ {
409
+ await SocketInput ;
410
+
411
+ while ( ! _requestProcessingStopping && ! TakeMessageHeaders ( SocketInput , _requestHeaders ) )
412
+ {
413
+ if ( SocketInput . RemoteIntakeFin )
414
+ {
415
+ return false ;
416
+ } ;
417
+ await SocketInput ;
418
+ }
419
+ return true ;
420
+ }
375
421
376
422
public void OnStarting ( Func < object , Task > callback , object state )
377
423
{
0 commit comments