onDataRead() — netty Function Reference
Architecture documentation for the onDataRead() function in DefaultHttp2ConnectionDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 8d250926_1eab_67b5_7ae5_94ae1e073f54["onDataRead()"] 0189a990_8f54_63f5_92fb_f168c031db1e["FrameReadListener"] 8d250926_1eab_67b5_7ae5_94ae1e073f54 -->|defined in| 0189a990_8f54_63f5_92fb_f168c031db1e a9a6e3dd_b339_3553_1e73_f0026b13c4ae["onDataRead()"] a9a6e3dd_b339_3553_1e73_f0026b13c4ae -->|calls| 8d250926_1eab_67b5_7ae5_94ae1e073f54 a9a6e3dd_b339_3553_1e73_f0026b13c4ae["onDataRead()"] 8d250926_1eab_67b5_7ae5_94ae1e073f54 -->|calls| a9a6e3dd_b339_3553_1e73_f0026b13c4ae ced1d4e9_b458_5358_c892_efa8534c4694["shouldIgnoreHeadersOrDataFrame()"] 8d250926_1eab_67b5_7ae5_94ae1e073f54 -->|calls| ced1d4e9_b458_5358_c892_efa8534c4694 a2d8c4e1_92a0_ea7d_3a12_abc7419c584a["verifyStreamMayHaveExisted()"] 8d250926_1eab_67b5_7ae5_94ae1e073f54 -->|calls| a2d8c4e1_92a0_ea7d_3a12_abc7419c584a 5099d76e_2045_154d_ff39_253bfca400b1["unconsumedBytes()"] 8d250926_1eab_67b5_7ae5_94ae1e073f54 -->|calls| 5099d76e_2045_154d_ff39_253bfca400b1 472f71a8_ad4a_5ddf_ef48_0ce742954e37["verifyContentLength()"] 8d250926_1eab_67b5_7ae5_94ae1e073f54 -->|calls| 472f71a8_ad4a_5ddf_ef48_0ce742954e37 style 8d250926_1eab_67b5_7ae5_94ae1e073f54 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java lines 251–333
@Override
public int onDataRead(final ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
boolean endOfStream) throws Http2Exception {
Http2Stream stream = connection.stream(streamId);
Http2LocalFlowController flowController = flowController();
int readable = data.readableBytes();
int bytesToReturn = readable + padding;
final boolean shouldIgnore;
try {
shouldIgnore = shouldIgnoreHeadersOrDataFrame(ctx, streamId, stream, endOfStream, "DATA");
} catch (Http2Exception e) {
// Ignoring this frame. We still need to count the frame towards the connection flow control
// window, but we immediately mark all bytes as consumed.
flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
flowController.consumeBytes(stream, bytesToReturn);
throw e;
} catch (Throwable t) {
throw connectionError(INTERNAL_ERROR, t, "Unhandled error on data stream id %d", streamId);
}
if (shouldIgnore) {
// Ignoring this frame. We still need to count the frame towards the connection flow control
// window, but we immediately mark all bytes as consumed.
flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
flowController.consumeBytes(stream, bytesToReturn);
// Verify that the stream may have existed after we apply flow control.
verifyStreamMayHaveExisted(streamId, endOfStream, "DATA");
// All bytes have been consumed.
return bytesToReturn;
}
Http2Exception error = null;
switch (stream.state()) {
case OPEN:
case HALF_CLOSED_LOCAL:
break;
case HALF_CLOSED_REMOTE:
case CLOSED:
error = streamError(stream.id(), STREAM_CLOSED, "Stream %d in unexpected state: %s",
stream.id(), stream.state());
break;
default:
error = streamError(stream.id(), PROTOCOL_ERROR,
"Stream %d in unexpected state: %s", stream.id(), stream.state());
break;
}
int unconsumedBytes = unconsumedBytes(stream);
try {
flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
// Update the unconsumed bytes after flow control is applied.
unconsumedBytes = unconsumedBytes(stream);
// If the stream is in an invalid state to receive the frame, throw the error.
if (error != null) {
throw error;
}
verifyContentLength(stream, readable, endOfStream);
// Call back the application and retrieve the number of bytes that have been
// immediately processed.
bytesToReturn = listener.onDataRead(ctx, streamId, data, padding, endOfStream);
if (endOfStream) {
lifecycleManager.closeStreamRemote(stream, ctx.newSucceededFuture());
}
return bytesToReturn;
} catch (Http2Exception | RuntimeException e) {
// If an exception happened during delivery, the listener may have returned part
// of the bytes before the error occurred. If that's the case, subtract that from
// the total processed bytes so that we don't return too many bytes.
int delta = unconsumedBytes - unconsumedBytes(stream);
bytesToReturn -= delta;
throw e;
} finally {
// If appropriate, return the processed bytes to the flow controller.
flowController.consumeBytes(stream, bytesToReturn);
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does onDataRead() do?
onDataRead() is a function in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java.
Where is onDataRead() defined?
onDataRead() is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java at line 251.
What does onDataRead() call?
onDataRead() calls 5 function(s): onDataRead, shouldIgnoreHeadersOrDataFrame, unconsumedBytes, verifyContentLength, verifyStreamMayHaveExisted.
What calls onDataRead()?
onDataRead() is called by 1 function(s): onDataRead.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free