[#4204] Broken support of SCTP_INIT_MAXSTREAMS in *SctpServerChannel

Motivation:

The SCTP_INIT_MAXSTREAMS property is ignored on NioSctpServerChannel / OioSctpServerChannel.

Modifications:

- Correctly use the netty ChannelOption
- Ensure getOption(...) works
- Add testcase.

Result:

SCTP_INIT_MAXSTREAMS works.

Conflicts:
	transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpServerChannelConfig.java
This commit is contained in:
Norman Maurer 2016-08-02 22:02:20 +02:00
parent d44017189e
commit 30a293c74b
5 changed files with 155 additions and 4 deletions

View File

@ -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);
}

View File

@ -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) {

View File

@ -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<? extends SctpChannel> clientClass();
protected abstract Class<? extends SctpServerChannel> serverClass();
}

View File

@ -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<? extends SctpChannel> clientClass() {
return NioSctpChannel.class;
}
@Override
protected Class<? extends SctpServerChannel> serverClass() {
return NioSctpServerChannel.class;
}
}

View File

@ -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<? extends SctpChannel> clientClass() {
return OioSctpChannel.class;
}
@Override
protected Class<? extends SctpServerChannel> serverClass() {
return OioSctpServerChannel.class;
}
}