Search in sources :

Example 1 with SctpInboundByteStreamHandler

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();
    }
}
Also used : SctpChannel(io.netty.channel.sctp.SctpChannel) SctpMessageCompletionHandler(io.netty.handler.codec.sctp.SctpMessageCompletionHandler) SctpInboundByteStreamHandler(io.netty.handler.codec.sctp.SctpInboundByteStreamHandler) SctpChannel(io.netty.channel.sctp.SctpChannel) Channel(io.netty.channel.Channel) IOException(java.io.IOException) IOException(java.io.IOException) SctpOutboundByteStreamHandler(io.netty.handler.codec.sctp.SctpOutboundByteStreamHandler)

Aggregations

Channel (io.netty.channel.Channel)1 SctpChannel (io.netty.channel.sctp.SctpChannel)1 SctpInboundByteStreamHandler (io.netty.handler.codec.sctp.SctpInboundByteStreamHandler)1 SctpMessageCompletionHandler (io.netty.handler.codec.sctp.SctpMessageCompletionHandler)1 SctpOutboundByteStreamHandler (io.netty.handler.codec.sctp.SctpOutboundByteStreamHandler)1 IOException (java.io.IOException)1