Less blocking in ChunkedStream (#11150)

Motivation:
We should avoid blocking in the event loop as much as possible.
The InputStream.read() is a blocking method, and we don't need to call it if available() returns a positive number.

Modification:
Bypass calling InputStream.read() if available() returns a positive number.

Result:
Fewer blocking calls in the event loop, in general, when ChunkedStream is used.
This commit is contained in:
Chris Vest 2021-04-12 13:40:14 +02:00 committed by GitHub
parent 6724786dcc
commit df53de5b68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -79,6 +79,9 @@ public class ChunkedStream implements ChunkedInput<ByteBuf> {
if (closed) {
return true;
}
if (in.available() > 0) {
return false;
}
int b = in.read();
if (b < 0) {

View File

@ -155,7 +155,7 @@ public class EpollSocketChannelConfigTest {
if (!(e.getCause() instanceof ClosedChannelException)) {
AssertionError error = new AssertionError(
"Expected the suppressed exception to be an instance of ClosedChannelException.");
error.addSuppressed(e.getCause());
error.addSuppressed(e);
throw error;
}
}