spliceToSocket() — netty Function Reference
Architecture documentation for the spliceToSocket() function in EpollSpliceTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 19bf818f_6e1f_4064_2eef_bfb7993c1368["spliceToSocket()"] 5f8d22b4_e4e5_93ca_78b8_9defb1460f42["EpollSpliceTest"] 19bf818f_6e1f_4064_2eef_bfb7993c1368 -->|defined in| 5f8d22b4_e4e5_93ca_78b8_9defb1460f42 c39ca91e_0b7d_217e_568b_15358192efc4["channelActive()"] 19bf818f_6e1f_4064_2eef_bfb7993c1368 -->|calls| c39ca91e_0b7d_217e_568b_15358192efc4 style 19bf818f_6e1f_4064_2eef_bfb7993c1368 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java lines 56–186
@Test
public void spliceToSocket() throws Throwable {
final EchoHandler sh = new EchoHandler();
final EchoHandler ch = new EchoHandler();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, EpollIoHandler.newFactory());
ServerBootstrap bs = new ServerBootstrap();
bs.channel(EpollServerSocketChannel.class);
bs.group(group).childHandler(sh);
final Channel sc = bs.bind(NetUtil.LOCALHOST, 0).syncUninterruptibly().channel();
ServerBootstrap bs2 = new ServerBootstrap();
bs2.channel(EpollServerSocketChannel.class);
bs2.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
bs2.group(group).childHandler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
ctx.channel().config().setAutoRead(false);
Bootstrap bs = new Bootstrap();
bs.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
bs.channel(EpollSocketChannel.class);
bs.group(ctx.channel().eventLoop()).handler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext context) throws Exception {
final EpollSocketChannel ch = (EpollSocketChannel) ctx.channel();
final EpollSocketChannel ch2 = (EpollSocketChannel) context.channel();
// We are splicing two channels together, at this point we have a tcp proxy which handles all
// the data transfer only in kernel space!
// Integer.MAX_VALUE will splice infinitely.
ch.spliceTo(ch2, Integer.MAX_VALUE).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
future.channel().close();
}
}
});
// Trigger multiple splices to see if partial splicing works as well.
ch2.spliceTo(ch, SPLICE_LEN).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
future.channel().close();
} else {
ch2.spliceTo(ch, SPLICE_LEN).addListener(this);
}
}
});
ctx.channel().config().setAutoRead(true);
}
@Override
public void channelInactive(ChannelHandlerContext context) throws Exception {
context.close();
}
});
bs.connect(sc.localAddress()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
ctx.close();
} else {
future.channel().closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
ctx.close();
}
});
}
}
});
}
});
Channel pc = bs2.bind(NetUtil.LOCALHOST, 0).syncUninterruptibly().channel();
Bootstrap cb = new Bootstrap();
cb.group(group);
cb.channel(EpollSocketChannel.class);
cb.handler(ch);
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does spliceToSocket() do?
spliceToSocket() is a function in the netty codebase, defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java.
Where is spliceToSocket() defined?
spliceToSocket() is defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java at line 56.
What does spliceToSocket() call?
spliceToSocket() calls 1 function(s): channelActive.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free