use of io.netty.channel.ChannelInboundHandlerAdapter in project netty by netty.
the class SctpLimitStreamsTest method testSctpInitMaxstreams.
@Test(timeout = 5000)
public void testSctpInitMaxstreams() throws Exception {
EventLoopGroup loop = newEventLoopGroup();
try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(loop).channel(serverClass()).option(ChannelOption.SO_REUSEADDR, true).option(SctpChannelOption.SCTP_INIT_MAXSTREAMS, SctpStandardSocketOptions.InitMaxStreams.create(1, 1)).localAddress(new InetSocketAddress(0)).childHandler(new ChannelInboundHandlerAdapter());
Bootstrap clientBootstrap = new Bootstrap().group(loop).channel(clientClass()).option(SctpChannelOption.SCTP_INIT_MAXSTREAMS, SctpStandardSocketOptions.InitMaxStreams.create(112, 112)).handler(new ChannelInboundHandlerAdapter());
Channel serverChannel = serverBootstrap.bind().syncUninterruptibly().channel();
SctpChannel clientChannel = (SctpChannel) clientBootstrap.connect(serverChannel.localAddress()).syncUninterruptibly().channel();
assertEquals(1, clientChannel.association().maxOutboundStreams());
assertEquals(1, clientChannel.association().maxInboundStreams());
serverChannel.close().syncUninterruptibly();
clientChannel.close().syncUninterruptibly();
} finally {
loop.shutdownGracefully();
}
}
use of io.netty.channel.ChannelInboundHandlerAdapter in project netty by netty.
the class EpollDomainSocketFdTest method testSendRecvFd.
public void testSendRecvFd(ServerBootstrap sb, Bootstrap cb) throws Throwable {
final BlockingQueue<Object> queue = new LinkedBlockingQueue<Object>(1);
sb.childHandler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
// Create new channel and obtain a file descriptor from it.
final EpollDomainSocketChannel ch = new EpollDomainSocketChannel();
ctx.writeAndFlush(ch.fd()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
Throwable cause = future.cause();
queue.offer(cause);
}
}
});
}
});
cb.handler(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
FileDescriptor fd = (FileDescriptor) msg;
queue.offer(fd);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
queue.add(cause);
ctx.close();
}
});
cb.option(EpollChannelOption.DOMAIN_SOCKET_READ_MODE, DomainSocketReadMode.FILE_DESCRIPTORS);
Channel sc = sb.bind().sync().channel();
Channel cc = cb.connect().sync().channel();
Object received = queue.take();
cc.close().sync();
sc.close().sync();
if (received instanceof FileDescriptor) {
FileDescriptor fd = (FileDescriptor) received;
Assert.assertTrue(fd.isOpen());
fd.close();
Assert.assertFalse(fd.isOpen());
Assert.assertNull(queue.poll());
} else {
throw (Throwable) received;
}
}
use of io.netty.channel.ChannelInboundHandlerAdapter in project netty by netty.
the class EpollServerSocketChannelConfigTest method before.
@BeforeClass
public static void before() {
group = new EpollEventLoopGroup(1);
ServerBootstrap bootstrap = new ServerBootstrap();
ch = (EpollServerSocketChannel) bootstrap.group(group).channel(EpollServerSocketChannel.class).childHandler(new ChannelInboundHandlerAdapter()).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
}
use of io.netty.channel.ChannelInboundHandlerAdapter in project netty by netty.
the class EpollSocketChannelConfigTest method before.
@BeforeClass
public static void before() {
rand = new Random();
group = new EpollEventLoopGroup(1);
Bootstrap bootstrap = new Bootstrap();
ch = (EpollSocketChannel) bootstrap.group(group).channel(EpollSocketChannel.class).handler(new ChannelInboundHandlerAdapter()).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
}
use of io.netty.channel.ChannelInboundHandlerAdapter in project netty by netty.
the class EpollSocketChannelTest method testTcpInfo.
@Test
public void testTcpInfo() throws Exception {
EventLoopGroup group = new EpollEventLoopGroup(1);
try {
Bootstrap bootstrap = new Bootstrap();
EpollSocketChannel ch = (EpollSocketChannel) bootstrap.group(group).channel(EpollSocketChannel.class).handler(new ChannelInboundHandlerAdapter()).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
EpollTcpInfo info = ch.tcpInfo();
assertTcpInfo0(info);
ch.close().syncUninterruptibly();
} finally {
group.shutdownGracefully();
}
}
Aggregations