use of io.netty.handler.codec.sctp.SctpInboundByteStreamHandler in project netty by netty.
the class SctpEchoTest method testSimpleEcho0.
private static void testSimpleEcho0(ServerBootstrap sb, Bootstrap cb, final boolean unordered) throws Throwable {
final EchoHandler sh = new EchoHandler();
final EchoHandler ch = new EchoHandler();
sb.childHandler(new ChannelInitializer<SctpChannel>() {
@Override
public void initChannel(SctpChannel c) throws Exception {
c.pipeline().addLast(new SctpMessageCompletionHandler(), new SctpInboundByteStreamHandler(0, 0), new SctpOutboundByteStreamHandler(0, 0, unordered), sh);
}
});
cb.handler(new ChannelInitializer<SctpChannel>() {
@Override
public void initChannel(SctpChannel c) throws Exception {
c.pipeline().addLast(new SctpMessageCompletionHandler(), new SctpInboundByteStreamHandler(0, 0), new SctpOutboundByteStreamHandler(0, 0, unordered), ch);
}
});
Channel sc = sb.bind().sync().channel();
Channel cc = cb.connect().sync().channel();
for (int i = 0; i < data.length; ) {
int length = Math.min(random.nextInt(1024 * 64), data.length - i);
cc.writeAndFlush(Unpooled.wrappedBuffer(data, i, length));
i += length;
}
while (ch.counter < data.length) {
if (sh.exception.get() != null) {
break;
}
if (ch.exception.get() != null) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// Ignore.
}
}
while (sh.counter < data.length) {
if (sh.exception.get() != null) {
break;
}
if (ch.exception.get() != null) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// Ignore.
}
}
sh.channel.close().sync();
ch.channel.close().sync();
sc.close().sync();
if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
throw sh.exception.get();
}
if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
throw ch.exception.get();
}
if (sh.exception.get() != null) {
throw sh.exception.get();
}
if (ch.exception.get() != null) {
throw ch.exception.get();
}
}
Aggregations