Skip to content

Commit

Permalink
1)refactored sctp server channel config 2)removed unsupported sctp so…
Browse files Browse the repository at this point in the history
…cket options
  • Loading branch information
jestan committed Oct 13, 2011
1 parent a20a2c1 commit b22c7e4
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@
*/
package org.jboss.netty.channel.socket.sctp;

import java.io.IOException;
import java.net.SocketAddress;
import java.util.Map;

import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpStandardSocketOption;

import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.DefaultChannelConfig;
import org.jboss.netty.channel.socket.nio.NioSocketChannelConfig;
import org.jboss.netty.util.internal.ConversionUtil;

import java.io.IOException;

/**
* The default {@link NioSocketChannelConfig} implementation for SCTP.
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
* @author <a href="http://github.com/jestan">Jestan Nirojan</a>
*
* @version $Rev$, $Date$
*/
class DefaultSctpChannelConfig extends DefaultChannelConfig implements SctpChannelConfig {
Expand All @@ -59,10 +56,6 @@ public boolean setOption(String key, Object value) {
setSendBufferSize(ConversionUtil.toInt(value));
} else if (key.equals("sctpNoDelay")) {
setSctpNoDelay(ConversionUtil.toBoolean(value));
} else if (key.equals("sctpPrimaryAddress")) {
setPrimaryAddress(ConversionUtil.toSocketAddress(value));
} else if (key.equals("sctpPeerPrimaryAddress")) {
setPeerPrimaryAddress(ConversionUtil.toSocketAddress(value));
} else if (key.equals("soLinger")) {
setSoLinger(ConversionUtil.toInt(value));
} else if (key.equals("sctpInitMaxStreams")) {
Expand Down Expand Up @@ -145,42 +138,6 @@ public void setReceiveBufferSize(int receiveBufferSize) {
}
}

@Override
public SocketAddress getPrimaryAddress() {
try {
return channel.getOption(SctpStandardSocketOption.SCTP_PRIMARY_ADDR);
} catch (IOException e) {
throw new ChannelException(e);
}
}

@Override
public void setPrimaryAddress(SocketAddress primaryAddress) {
try {
channel.setOption(SctpStandardSocketOption.SCTP_PRIMARY_ADDR, primaryAddress);
} catch (IOException e) {
throw new ChannelException(e);
}
}

@Override
public SocketAddress getPeerPrimaryAddress() {
try {
return channel.getOption(SctpStandardSocketOption.SCTP_SET_PEER_PRIMARY_ADDR);
} catch (IOException e) {
throw new ChannelException(e);
}
}

@Override
public void setPeerPrimaryAddress(SocketAddress peerPrimaryAddress) {
try {
channel.setOption(SctpStandardSocketOption.SCTP_SET_PEER_PRIMARY_ADDR, peerPrimaryAddress);
} catch (IOException e) {
throw new ChannelException(e);
}
}

@Override
public SctpStandardSocketOption.InitMaxStreams getInitMaxStreams() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
* </tr><tr>
* <td>{@code "sendBufferSize"}</td><td>{@link #setSendBufferSize(int)}</td>
* </tr><tr>
* <td>{@code "sctpPrimaryAddress"}</td><td>{@link #setPrimaryAddress(SocketAddress)}}</td>
* </tr><tr>
* <td>{@code "sctpPeerPrimaryAddress"}</td><td>{@link #setPeerPrimaryAddress(SocketAddress)}}</td>
* </tr><tr>
* <td>{@code "sctpInitMaxStreams"}</td><td>{@link #setInitMaxStreams(com.sun.nio.sctp.SctpStandardSocketOption.InitMaxStreams)} (int)}}</td>
* </tr>
* </table>
Expand Down Expand Up @@ -95,26 +91,6 @@ public interface SctpChannelConfig extends ChannelConfig {
*/
void setReceiveBufferSize(int receiveBufferSize);

/**
* Gets the <a href="http://openjdk.java.net/projects/sctp/javadoc/com/sun/nio/sctp/SctpStandardSocketOption.html">{@code SCTP_PRIMARY_ADDR}</a> option.
*/
SocketAddress getPrimaryAddress();

/**
* Sets the <a href="http://openjdk.java.net/projects/sctp/javadoc/com/sun/nio/sctp/SctpStandardSocketOption.html">{@code SCTP_PRIMARY_ADDR}</a> option.
*/
void setPrimaryAddress(SocketAddress primaryAddress);

/**
* Gets the <a href="http://openjdk.java.net/projects/sctp/javadoc/com/sun/nio/sctp/SctpStandardSocketOption.html">{@code SCTP_SET_PEER_PRIMARY_ADDR}</a> option.
*/
SocketAddress getPeerPrimaryAddress();

/**
* Sets the <a href="http://openjdk.java.net/projects/sctp/javadoc/com/sun/nio/sctp/SctpStandardSocketOption.html">{@code SCTP_SET_PEER_PRIMARY_ADDR}</a> option.
*/
void setPeerPrimaryAddress(SocketAddress peerPrimaryAddress);

/**
* Gets the <a href="http://openjdk.java.net/projects/sctp/javadoc/com/sun/nio/sctp/SctpStandardSocketOption.html">{@code SCTP_INIT_MAXSTREAMS}</a> option.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.sun.nio.sctp.SctpChannel;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.socket.nio.NioSocketChannelConfig;
import org.jboss.netty.channel.socket.sctp.SctpSendBufferPool.SendBuffer;
import org.jboss.netty.util.internal.LinkedTransferQueue;
import org.jboss.netty.util.internal.ThreadLocalBoolean;
Expand Down Expand Up @@ -49,7 +48,7 @@ class SctpChannelImpl extends AbstractChannel
private static final int ST_CLOSED = -1;
volatile int state = ST_OPEN;

final SctpChannel socket;
final SctpChannel channel;
final SctpWorker worker;
private final NioSctpChannelConfig config;
private volatile InetSocketAddress localAddress;
Expand All @@ -73,12 +72,12 @@ class SctpChannelImpl extends AbstractChannel
public SctpChannelImpl(
Channel parent, ChannelFactory factory,
ChannelPipeline pipeline, ChannelSink sink,
SctpChannel socket, SctpWorker worker) {
SctpChannel channel, SctpWorker worker) {
super(parent, factory, pipeline, sink);

this.socket = socket;
this.channel = channel;
this.worker = worker;
config = new DefaultNioSctpChannelConfig(socket);
config = new DefaultNioSctpChannelConfig(channel);

getCloseFuture().addListener(new ChannelFutureListener() {
@Override
Expand All @@ -98,7 +97,7 @@ public InetSocketAddress getLocalAddress() {
InetSocketAddress localAddress = this.localAddress;
if (localAddress == null) {
try {
final Iterator<SocketAddress> iterator = socket.getAllLocalAddresses().iterator();
final Iterator<SocketAddress> iterator = channel.getAllLocalAddresses().iterator();
if (iterator.hasNext()) {
this.localAddress = localAddress = (InetSocketAddress) iterator.next();
}
Expand All @@ -112,7 +111,7 @@ public InetSocketAddress getLocalAddress() {
@Override
public Set<InetSocketAddress> getAllLocalAddresses() {
try {
final Set<SocketAddress> allLocalAddresses = socket.getAllLocalAddresses();
final Set<SocketAddress> allLocalAddresses = channel.getAllLocalAddresses();
final Set<InetSocketAddress> addresses = new HashSet<InetSocketAddress>(allLocalAddresses.size());
for(SocketAddress socketAddress: allLocalAddresses) {
addresses.add((InetSocketAddress) socketAddress);
Expand All @@ -128,7 +127,7 @@ public InetSocketAddress getRemoteAddress() {
InetSocketAddress remoteAddress = this.remoteAddress;
if (remoteAddress == null) {
try {
final Iterator<SocketAddress> iterator = socket.getRemoteAddresses().iterator();
final Iterator<SocketAddress> iterator = channel.getRemoteAddresses().iterator();
if (iterator.hasNext()) {
this.remoteAddress = remoteAddress = (InetSocketAddress) iterator.next();
}
Expand All @@ -142,7 +141,7 @@ public InetSocketAddress getRemoteAddress() {
@Override
public Set<InetSocketAddress> getRemoteAddresses() {
try {
final Set<SocketAddress> allLocalAddresses = socket.getRemoteAddresses();
final Set<SocketAddress> allLocalAddresses = channel.getRemoteAddresses();
final Set<InetSocketAddress> addresses = new HashSet<InetSocketAddress>(allLocalAddresses.size());
for(SocketAddress socketAddress: allLocalAddresses) {
addresses.add((InetSocketAddress) socketAddress);
Expand All @@ -156,7 +155,7 @@ public Set<InetSocketAddress> getRemoteAddresses() {
@Override
public Association association() {
try {
return socket.association();
return channel.association();
} catch (Throwable e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void bind(
SctpClientChannel channel, ChannelFuture future,
SocketAddress localAddress) {
try {
channel.socket.bind(localAddress);
channel.channel.bind(localAddress);
channel.boundManually = true;
channel.setBound();
future.setSuccess();
Expand All @@ -128,7 +128,7 @@ private void connect(
final SctpClientChannel channel, final ChannelFuture cf,
SocketAddress remoteAddress) {
try {
if (channel.socket.connect(remoteAddress)) {
if (channel.channel.connect(remoteAddress)) {
channel.worker.register(channel, cf);
} else {
channel.getCloseFuture().addListener(new ChannelFutureListener() {
Expand Down Expand Up @@ -371,7 +371,7 @@ private void processConnectTimeout(Set<SelectionKey> keys, long currentTimeNanos
private void connect(SelectionKey k) {
SctpClientChannel ch = (SctpClientChannel) k.attachment();
try {
if (ch.socket.finishConnect()) {
if (ch.channel.finishConnect()) {
k.cancel();
ch.worker.register(ch, ch.connectFuture);
}
Expand Down Expand Up @@ -401,7 +401,7 @@ private static final class RegisterTask implements Runnable {
@Override
public void run() {
try {
channel.socket.register(
channel.channel.register(
boss.selector, SelectionKey.OP_CONNECT, channel);
} catch (ClosedChannelException e) {
channel.worker.close(channel, succeededFuture(channel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@
package org.jboss.netty.channel.socket.sctp;

import org.jboss.netty.channel.ServerChannel;
import org.jboss.netty.channel.socket.ServerSocketChannelConfig;

import java.net.InetSocketAddress;
import java.util.Set;

/**
* A TCP/IP {@link org.jboss.netty.channel.ServerChannel} which accepts incoming TCP/IP connections.
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
* @author <a href="http://github.com/jestan">Jestan Nirojan</a>
*
* @version $Rev$, $Date$
*
*/
public interface SctpServerChannel extends ServerChannel {
@Override
ServerSocketChannelConfig getConfig();
ServerSctpChannelConfig getConfig();
@Override
InetSocketAddress getLocalAddress();

Set<InetSocketAddress> getAllLocalAddresses();
@Override
InetSocketAddress getRemoteAddress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
import com.sun.nio.sctp.SctpStandardSocketOption;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.DefaultServerChannelConfig;
import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
import org.jboss.netty.util.internal.ConversionUtil;

import java.io.IOException;
import java.net.SocketAddress;

/**
* The default {@link org.jboss.netty.channel.socket.ServerSocketChannelConfig} implementation.
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
* @author <a href="http://github.com/jestan">Jestan Nirojan</a>
*
* @version $Rev$, $Date$
*/
public class SctpServerChannelConfig extends DefaultServerChannelConfig
implements ServerSocketChannelConfig {
implements ServerSctpChannelConfig {

private final com.sun.nio.sctp.SctpServerChannel serverChannel;
private volatile int backlog;
Expand All @@ -54,10 +54,8 @@ public boolean setOption(String key, Object value) {
return true;
}

if (key.equals("receiveBufferSize")) {
setReceiveBufferSize(ConversionUtil.toInt(value));
} else if (key.equals("reuseAddress")) {
setReuseAddress(ConversionUtil.toBoolean(value));
if (key.equals("sctpInitMaxStreams")) {
setInitMaxStreams((SctpStandardSocketOption.InitMaxStreams) value);
} else if (key.equals("backlog")) {
setBacklog(ConversionUtil.toInt(value));
} else {
Expand All @@ -67,38 +65,23 @@ public boolean setOption(String key, Object value) {
}

@Override
public boolean isReuseAddress() {
return false;
}

@Override
public void setReuseAddress(boolean reuseAddress) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public int getReceiveBufferSize() {
public SctpStandardSocketOption.InitMaxStreams getInitMaxStreams() {
try {
return serverChannel.getOption(SctpStandardSocketOption.SO_RCVBUF);
return serverChannel.getOption(SctpStandardSocketOption.SCTP_INIT_MAXSTREAMS);
} catch (IOException e) {
throw new ChannelException(e);
}
}

@Override
public void setReceiveBufferSize(int receiveBufferSize) {
public void setInitMaxStreams(SctpStandardSocketOption.InitMaxStreams initMaxStreams) {
try {
serverChannel.setOption(SctpStandardSocketOption.SO_RCVBUF, receiveBufferSize);
serverChannel.setOption(SctpStandardSocketOption.SCTP_INIT_MAXSTREAMS, initMaxStreams);
} catch (IOException e) {
throw new ChannelException(e);
}
}

@Override
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public int getBacklog() {
return backlog;
Expand Down
Loading

0 comments on commit b22c7e4

Please sign in to comment.