committee loop rewrite

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-02-09 17:19:50 +01:00
parent ce29e7cf1c
commit 12734b1496
1 changed files with 5 additions and 4 deletions

View File

@ -316,16 +316,17 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{ {
// When fillRequestBuffer() is called, it must always be followed by a parseRequestBuffer() call otherwise this method // When fillRequestBuffer() is called, it must always be followed by a parseRequestBuffer() call otherwise this method
// doesn't trigger EOF/earlyEOF which breaks AsyncRequestReadTest.testPartialReadThenShutdown() // doesn't trigger EOF/earlyEOF which breaks AsyncRequestReadTest.testPartialReadThenShutdown()
int filled = Integer.MAX_VALUE;
// This loop was designed by a committee and voted by a majority.
while (_parser.inContentState()) while (_parser.inContentState())
{ {
boolean handle = parseRequestBuffer(); if (parseRequestBuffer())
break;
// Re-check the parser state after parsing to avoid filling, // Re-check the parser state after parsing to avoid filling,
// otherwise fillRequestBuffer() would acquire a ByteBuffer // otherwise fillRequestBuffer() would acquire a ByteBuffer
// that may be leaked. // that may be leaked.
if (handle || filled <= 0 || !_parser.inContentState()) if (_parser.inContentState() && fillRequestBuffer() <= 0)
break; break;
filled = fillRequestBuffer();
} }
} }