wrap() — netty Function Reference
Architecture documentation for the wrap() function in SslHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD ca3c58ac_45a7_24e9_d74b_140cea69627e["wrap()"] d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1["SslHandler"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|defined in| d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 1b465b2e_ec05_393c_4b3a_f882c72d8cc3["wrapAndFlush()"] 1b465b2e_ec05_393c_4b3a_f882c72d8cc3 -->|calls| ca3c58ac_45a7_24e9_d74b_140cea69627e 5759ad29_b25e_dc08_15d9_5d7a84356f31["wrapNonAppData()"] 5759ad29_b25e_dc08_15d9_5d7a84356f31 -->|calls| ca3c58ac_45a7_24e9_d74b_140cea69627e 69569884_b53f_4a6d_2905_0f9db5cafbed["SSLEngineResult()"] 69569884_b53f_4a6d_2905_0f9db5cafbed -->|calls| ca3c58ac_45a7_24e9_d74b_140cea69627e 1807eec1_6f0b_edf4_8d02_a6d15d3c18c1["handleUnwrapThrowable()"] 1807eec1_6f0b_edf4_8d02_a6d15d3c18c1 -->|calls| ca3c58ac_45a7_24e9_d74b_140cea69627e 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7["unwrap()"] 51b61e7d_0f6d_53c7_ed6a_56a55b2ed5a7 -->|calls| ca3c58ac_45a7_24e9_d74b_140cea69627e 3767fed6_8ef0_e61c_ca65_bd1e0902b8bb["resumeOnEventExecutor()"] 3767fed6_8ef0_e61c_ca65_bd1e0902b8bb -->|calls| ca3c58ac_45a7_24e9_d74b_140cea69627e 3c66160e_1a9c_d310_8bcb_1a5c64f633f9["write()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| 3c66160e_1a9c_d310_8bcb_1a5c64f633f9 16c70aef_a8d5_6d7e_02d1_6d8d8dfe1d58["releaseAndFailAll()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| 16c70aef_a8d5_6d7e_02d1_6d8d8dfe1d58 985b3057_a9f6_8ddd_4409_70c4485507c5["runDelegatedTasks()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| 985b3057_a9f6_8ddd_4409_70c4485507c5 412a41a8_6a03_f301_fa41_1d7e9d8ad668["setHandshakeSuccess()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| 412a41a8_6a03_f301_fa41_1d7e9d8ad668 37fdca52_5a27_1da0_971b_e56a22cd3521["readIfNeeded()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| 37fdca52_5a27_1da0_971b_e56a22cd3521 cc9a73ea_cfe9_c66d_c539_4a6802139e47["IllegalStateException()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| cc9a73ea_cfe9_c66d_c539_4a6802139e47 586d9480_c5dd_d8c2_fcc9_bd16fdeca640["setState()"] ca3c58ac_45a7_24e9_d74b_140cea69627e -->|calls| 586d9480_c5dd_d8c2_fcc9_bd16fdeca640 style ca3c58ac_45a7_24e9_d74b_140cea69627e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/SslHandler.java lines 851–986
private void wrap(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLException {
ByteBuf out = null;
ByteBufAllocator alloc = ctx.alloc();
try {
final int wrapDataSize = this.wrapDataSize;
// Only continue to loop if the handler was not removed in the meantime.
// See https://github.com/netty/netty/issues/5860
outer: while (!ctx.isRemoved()) {
ChannelPromise promise = ctx.newPromise();
ByteBuf buf = wrapDataSize > 0 ?
pendingUnencryptedWrites.remove(alloc, wrapDataSize, promise) :
pendingUnencryptedWrites.removeFirst(promise);
if (buf == null) {
break;
}
SSLEngineResult result;
try {
if (buf.readableBytes() > MAX_PLAINTEXT_LENGTH) {
// If we pulled a buffer larger than the supported packet size, we can slice it up and
// iteratively, encrypting multiple packets into a single larger buffer. This substantially
// saves on allocations for large responses. Here we estimate how large of a buffer we need.
// If we overestimate a bit, that's fine. If we underestimate, we'll simply re-enqueue the
// remaining buffer and get it on the next outer loop.
int readableBytes = buf.readableBytes();
int numPackets = readableBytes / MAX_PLAINTEXT_LENGTH;
if (readableBytes % MAX_PLAINTEXT_LENGTH != 0) {
numPackets += 1;
}
if (out == null) {
out = allocateOutNetBuf(ctx, readableBytes, buf.nioBufferCount() + numPackets);
}
result = wrapMultiple(alloc, engine, buf, out);
} else {
if (out == null) {
out = allocateOutNetBuf(ctx, buf.readableBytes(), buf.nioBufferCount());
}
result = wrap(alloc, engine, buf, out);
}
} catch (SSLException e) {
// Either wrapMultiple(...) or wrap(...) did throw. In this case we need to release the buffer
// that we removed from pendingUnencryptedWrites before failing the promise and rethrowing it.
// Failing to do so would result in a buffer leak.
// See https://github.com/netty/netty/issues/14644
//
// We don't need to release out here as this is done in a finally block already.
buf.release();
promise.setFailure(e);
throw e;
}
if (buf.isReadable()) {
pendingUnencryptedWrites.addFirst(buf, promise);
// When we add the buffer/promise pair back we need to be sure we don't complete the promise
// later. We only complete the promise if the buffer is completely consumed.
promise = null;
} else {
buf.release();
}
// We need to write any data before we invoke any methods which may trigger re-entry, otherwise
// writes may occur out of order and TLS sequencing may be off (e.g. SSLV3_ALERT_BAD_RECORD_MAC).
if (out.isReadable()) {
final ByteBuf b = out;
out = null;
if (promise != null) {
ctx.write(b, promise);
} else {
ctx.write(b);
}
} else if (promise != null) {
ctx.write(Unpooled.EMPTY_BUFFER, promise);
}
// else out is not readable we can re-use it and so save an extra allocation
if (result.getStatus() == Status.CLOSED) {
// First check if there is any write left that needs to be failed, if there is none we don't need
// to create a new exception or obtain an existing one.
if (!pendingUnencryptedWrites.isEmpty()) {
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does wrap() do?
wrap() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java.
Where is wrap() defined?
wrap() is defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java at line 851.
What does wrap() call?
wrap() calls 7 function(s): IllegalStateException, readIfNeeded, releaseAndFailAll, runDelegatedTasks, setHandshakeSuccess, setState, write.
What calls wrap()?
wrap() is called by 6 function(s): SSLEngineResult, handleUnwrapThrowable, resumeOnEventExecutor, unwrap, wrapAndFlush, wrapNonAppData.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free