unwrap() — netty Function Reference
Architecture documentation for the unwrap() function in SslHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7["unwrap()"] d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1["SslHandler"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|defined in| d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 eb5ae59b_9b70_8065_9fe5_48f1bb487718["decodeJdkCompatible()"] eb5ae59b_9b70_8065_9fe5_48f1bb487718 -->|calls| 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 fd6e1cff_0a80_5613_9d64_f2430d162a6b["decodeNonJdkCompatible()"] fd6e1cff_0a80_5613_9d64_f2430d162a6b -->|calls| 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 1e626fd1_be04_3828_22be_f23dbb77f38a["unwrapNonAppData()"] 1e626fd1_be04_3828_22be_f23dbb77f38a -->|calls| 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 8cae5f97_939d_55fc_31c2_c6131add51c2["taskError()"] 8cae5f97_939d_55fc_31c2_c6131add51c2 -->|calls| 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 6a6c9f71_8d6b_1ed2_787c_12fbd8c1c17c["Throwable()"] 6a6c9f71_8d6b_1ed2_787c_12fbd8c1c17c -->|calls| 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 3767fed6_8ef0_e61c_ca65_bd1e0902b8bb["resumeOnEventExecutor()"] 3767fed6_8ef0_e61c_ca65_bd1e0902b8bb -->|calls| 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 83a0158f_b432_6f94_08e9_4ba1d7ed442a["read()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| 83a0158f_b432_6f94_08e9_4ba1d7ed442a f6d3b03c_60c8_2cd1_d1f9_9e50bc567c49["setHandshakeSuccessUnwrapMarkReentry()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| f6d3b03c_60c8_2cd1_d1f9_9e50bc567c49 412a41a8_6a03_f301_fa41_1d7e9d8ad668["setHandshakeSuccess()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| 412a41a8_6a03_f301_fa41_1d7e9d8ad668 586d9480_c5dd_d8c2_fcc9_bd16fdeca640["setState()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| 586d9480_c5dd_d8c2_fcc9_bd16fdeca640 52f75d24_7c2b_f055_d7e7_b2cfcc304a7f["isStateSet()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| 52f75d24_7c2b_f055_d7e7_b2cfcc304a7f 4634ec83_284d_77d8_4bd9_1ed111246bb9["executeChannelRead()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| 4634ec83_284d_77d8_4bd9_1ed111246bb9 985b3057_a9f6_8ddd_4409_70c4485507c5["runDelegatedTasks()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| 985b3057_a9f6_8ddd_4409_70c4485507c5 style 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/SslHandler.java lines 1492–1618
private int unwrap(ChannelHandlerContext ctx, ByteBuf packet, int length) throws SSLException {
final int originalLength = length;
boolean wrapLater = false;
boolean notifyClosure = false;
boolean executedRead = false;
ByteBuf decodeOut = allocate(ctx, length);
try {
// Only continue to loop if the handler was not removed in the meantime.
// See https://github.com/netty/netty/issues/5860
do {
final SSLEngineResult result = engineType.unwrap(this, packet, length, decodeOut);
final Status status = result.getStatus();
final HandshakeStatus handshakeStatus = result.getHandshakeStatus();
final int produced = result.bytesProduced();
final int consumed = result.bytesConsumed();
// Skip bytes now in case unwrap is called in a re-entry scenario. For example LocalChannel.read()
// may entry this method in a re-entry fashion and if the peer is writing into a shared buffer we may
// unwrap the same data multiple times.
packet.skipBytes(consumed);
length -= consumed;
// The expected sequence of events is:
// 1. Notify of handshake success
// 2. fireChannelRead for unwrapped data
if (handshakeStatus == HandshakeStatus.FINISHED || handshakeStatus == HandshakeStatus.NOT_HANDSHAKING) {
wrapLater |= (decodeOut.isReadable() ?
setHandshakeSuccessUnwrapMarkReentry() : setHandshakeSuccess()) ||
handshakeStatus == HandshakeStatus.FINISHED ||
// We need to check if pendingUnecryptedWrites is null as the SslHandler
// might have been removed in the meantime.
(pendingUnencryptedWrites != null && !pendingUnencryptedWrites.isEmpty());
}
// Dispatch decoded data after we have notified of handshake success. If this method has been invoked
// in a re-entry fashion we execute a task on the executor queue to process after the stack unwinds
// to preserve order of events.
if (decodeOut.isReadable()) {
setState(STATE_FIRE_CHANNEL_READ);
if (isStateSet(STATE_UNWRAP_REENTRY)) {
executedRead = true;
executeChannelRead(ctx, decodeOut);
} else {
ctx.fireChannelRead(decodeOut);
}
decodeOut = null;
}
if (status == Status.CLOSED) {
notifyClosure = true; // notify about the CLOSED state of the SSLEngine. See #137
} else if (status == Status.BUFFER_OVERFLOW) {
if (decodeOut != null) {
decodeOut.release();
}
final int applicationBufferSize = engine.getSession().getApplicationBufferSize();
// Allocate a new buffer which can hold all the rest data and loop again.
// It may happen that applicationBufferSize < produced while there is still more to unwrap, in this
// case we will just allocate a new buffer with the capacity of applicationBufferSize and call
// unwrap again.
decodeOut = allocate(ctx, engineType.calculatePendingData(this, applicationBufferSize < produced ?
applicationBufferSize : applicationBufferSize - produced));
continue;
}
if (handshakeStatus == HandshakeStatus.NEED_TASK) {
boolean pending = runDelegatedTasks(true);
if (!pending) {
// We scheduled a task on the delegatingTaskExecutor, so stop processing as we will
// resume once the task completes.
//
// We break out of the loop only and do NOT return here as we still may need to notify
// about the closure of the SSLEngine.
wrapLater = false;
break;
}
} else if (handshakeStatus == HandshakeStatus.NEED_WRAP) {
// If the wrap operation transitions the status to NOT_HANDSHAKING and there is no more data to
// unwrap then the next call to unwrap will not produce any data. We can avoid the potentially
// costly unwrap operation and break out of the loop.
if (wrapNonAppData(ctx, true) && length == 0) {
break;
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does unwrap() do?
unwrap() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java.
Where is unwrap() defined?
unwrap() is defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java at line 1492.
What does unwrap() call?
unwrap() calls 13 function(s): clearState, executeChannelRead, executeNotifyClosePromise, isStateSet, notifyClosePromise, read, readIfNeeded, runDelegatedTasks, and 5 more.
What calls unwrap()?
unwrap() is called by 6 function(s): Throwable, decodeJdkCompatible, decodeNonJdkCompatible, resumeOnEventExecutor, taskError, unwrapNonAppData.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free