doRead() — netty Function Reference
Architecture documentation for the doRead() function in AbstractOioByteChannel.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 24847cd2_e242_82c4_873e_ef44313f60e1["doRead()"] df30be00_eee6_bc00_48f3_cbf4f80b9065["AbstractOioByteChannel"] 24847cd2_e242_82c4_873e_ef44313f60e1 -->|defined in| df30be00_eee6_bc00_48f3_cbf4f80b9065 9f1b0882_de8a_d386_f00a_3c8170b1e5f6["isInputShutdown()"] 24847cd2_e242_82c4_873e_ef44313f60e1 -->|calls| 9f1b0882_de8a_d386_f00a_3c8170b1e5f6 3bfe11d6_f89b_cc98_cc9d_828f40a064a5["doReadBytes()"] 24847cd2_e242_82c4_873e_ef44313f60e1 -->|calls| 3bfe11d6_f89b_cc98_cc9d_828f40a064a5 c4cb8ae3_e77f_078e_ff82_bbcf09e40ae1["available()"] 24847cd2_e242_82c4_873e_ef44313f60e1 -->|calls| c4cb8ae3_e77f_078e_ff82_bbcf09e40ae1 e2921b96_0d95_d59d_1b95_b8061971e04f["closeOnRead()"] 24847cd2_e242_82c4_873e_ef44313f60e1 -->|calls| e2921b96_0d95_d59d_1b95_b8061971e04f 6731b7b6_ba29_84b6_72f2_5246e108dfb1["handleReadException()"] 24847cd2_e242_82c4_873e_ef44313f60e1 -->|calls| 6731b7b6_ba29_84b6_72f2_5246e108dfb1 style 24847cd2_e242_82c4_873e_ef44313f60e1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java lines 108–201
@Override
protected void doRead() {
final ChannelConfig config = config();
if (isInputShutdown() || !readPending) {
// We have to check readPending here because the Runnable to read could have been scheduled and later
// during the same read loop readPending was set to false.
return;
}
// In OIO we should set readPending to false even if the read was not successful so we can schedule
// another read on the event loop if no reads are done.
readPending = false;
final ChannelPipeline pipeline = pipeline();
final ByteBufAllocator allocator = config.getAllocator();
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
allocHandle.reset(config);
ByteBuf byteBuf = null;
boolean close = false;
boolean readData = false;
try {
byteBuf = allocHandle.allocate(allocator);
do {
allocHandle.lastBytesRead(doReadBytes(byteBuf));
if (allocHandle.lastBytesRead() <= 0) {
if (!byteBuf.isReadable()) { // nothing was read. release the buffer.
byteBuf.release();
byteBuf = null;
close = allocHandle.lastBytesRead() < 0;
if (close) {
// There is nothing left to read as we received an EOF.
readPending = false;
}
}
break;
} else {
readData = true;
}
final int available = available();
if (available <= 0) {
break;
}
// Oio collects consecutive read operations into 1 ByteBuf before propagating up the pipeline.
if (!byteBuf.isWritable()) {
final int capacity = byteBuf.capacity();
final int maxCapacity = byteBuf.maxCapacity();
if (capacity == maxCapacity) {
allocHandle.incMessagesRead(1);
readPending = false;
pipeline.fireChannelRead(byteBuf);
byteBuf = allocHandle.allocate(allocator);
} else {
final int writerIndex = byteBuf.writerIndex();
if (writerIndex + available > maxCapacity) {
byteBuf.capacity(maxCapacity);
} else {
byteBuf.ensureWritable(available);
}
}
}
} while (allocHandle.continueReading());
if (byteBuf != null) {
// It is possible we allocated a buffer because the previous one was not writable, but then didn't use
// it because allocHandle.continueReading() returned false.
if (byteBuf.isReadable()) {
readPending = false;
pipeline.fireChannelRead(byteBuf);
} else {
byteBuf.release();
}
byteBuf = null;
}
if (readData) {
allocHandle.readComplete();
pipeline.fireChannelReadComplete();
}
Domain
Subdomains
Source
Frequently Asked Questions
What does doRead() do?
doRead() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java.
Where is doRead() defined?
doRead() is defined in transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java at line 108.
What does doRead() call?
doRead() calls 5 function(s): available, closeOnRead, doReadBytes, handleReadException, isInputShutdown.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free