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
parent ad7372b112
commit 6d35db57bd
2 changed files with 4 additions and 1 deletions

View File

@ -84,6 +84,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

@ -156,7 +156,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;
}
}