diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java index 609bac3e9f..4ff3055b67 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java @@ -77,6 +77,9 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc if (option == SCTP_NODELAY) { return (T) Boolean.valueOf(isSctpNoDelay()); } + if (option == SCTP_INIT_MAXSTREAMS) { + return (T) getInitMaxStreams(); + } return super.getOption(option); } diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java index 2141e23c33..257e016e4f 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java @@ -17,7 +17,6 @@ package io.netty.channel.sctp; import com.sun.nio.sctp.SctpServerChannel; import com.sun.nio.sctp.SctpStandardSocketOptions; -import com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams; import io.netty.buffer.ByteBufAllocator; import io.netty.channel.ChannelException; import io.netty.channel.ChannelOption; @@ -66,6 +65,9 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme if (option == ChannelOption.SO_SNDBUF) { return (T) Integer.valueOf(getSendBufferSize()); } + if (option == SctpChannelOption.SCTP_INIT_MAXSTREAMS) { + return (T) getInitMaxStreams(); + } return super.getOption(option); } @@ -78,7 +80,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme } else if (option == ChannelOption.SO_SNDBUF) { setSendBufferSize((Integer) value); } else if (option == SctpChannelOption.SCTP_INIT_MAXSTREAMS) { - setInitMaxStreams((InitMaxStreams) value); + setInitMaxStreams((SctpStandardSocketOptions.InitMaxStreams) value); } else { return super.setOption(option, value); } @@ -125,7 +127,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme } @Override - public InitMaxStreams getInitMaxStreams() { + public SctpStandardSocketOptions.InitMaxStreams getInitMaxStreams() { try { return javaChannel.getOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS); } catch (IOException e) { @@ -134,7 +136,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme } @Override - public SctpServerChannelConfig setInitMaxStreams(InitMaxStreams initMaxStreams) { + public SctpServerChannelConfig setInitMaxStreams(SctpStandardSocketOptions.InitMaxStreams initMaxStreams) { try { javaChannel.setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, initMaxStreams); } catch (IOException e) { diff --git a/transport-sctp/src/main/test/io/netty/channel/sctp/SctpLimitStreamsTest.java b/transport-sctp/src/main/test/io/netty/channel/sctp/SctpLimitStreamsTest.java new file mode 100644 index 0000000000..3d5abf4c34 --- /dev/null +++ b/transport-sctp/src/main/test/io/netty/channel/sctp/SctpLimitStreamsTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.sctp; + +import com.sun.nio.sctp.SctpStandardSocketOptions; +import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import org.junit.Test; +import java.net.InetSocketAddress; + +import static org.junit.Assert.*; + +public abstract class SctpLimitStreamsTest { + + @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(); + } + } + + protected abstract EventLoopGroup newEventLoopGroup(); + protected abstract Class clientClass(); + protected abstract Class serverClass(); +} diff --git a/transport-sctp/src/main/test/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java b/transport-sctp/src/main/test/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java new file mode 100644 index 0000000000..78365ab507 --- /dev/null +++ b/transport-sctp/src/main/test/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.sctp.nio; + +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.sctp.SctpChannel; +import io.netty.channel.sctp.SctpLimitStreamsTest; +import io.netty.channel.sctp.SctpServerChannel; + +public class NioSctpLimitStreamsTest extends SctpLimitStreamsTest { + @Override + protected EventLoopGroup newEventLoopGroup() { + return new NioEventLoopGroup(); + } + + @Override + protected Class clientClass() { + return NioSctpChannel.class; + } + + @Override + protected Class serverClass() { + return NioSctpServerChannel.class; + } +} diff --git a/transport-sctp/src/main/test/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java b/transport-sctp/src/main/test/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java new file mode 100644 index 0000000000..d30a97d0ba --- /dev/null +++ b/transport-sctp/src/main/test/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.sctp.oio; + +import io.netty.channel.EventLoopGroup; +import io.netty.channel.oio.OioEventLoopGroup; +import io.netty.channel.sctp.SctpChannel; +import io.netty.channel.sctp.SctpLimitStreamsTest; +import io.netty.channel.sctp.SctpServerChannel; + +public class OioSctpLimitStreamsTest extends SctpLimitStreamsTest { + @Override + protected EventLoopGroup newEventLoopGroup() { + return new OioEventLoopGroup(); + } + + @Override + protected Class clientClass() { + return OioSctpChannel.class; + } + + @Override + protected Class serverClass() { + return OioSctpServerChannel.class; + } +}