Added Multi-Homing in SctpOioChannel

This commit is contained in:
Jestan Nirojan 2012-09-21 12:16:06 +08:00
parent db4a3a4789
commit bf22173ed1
4 changed files with 56 additions and 4 deletions

View File

@ -52,7 +52,7 @@ public class OioSctpEchoClient {
Bootstrap b = new Bootstrap();
try {
b.group(new OioEventLoopGroup())
.channel(new OioSctpChannel())
.channel(OioSctpChannel.class)
.option(ChannelOption.SCTP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port))
.handler(new ChannelInitializer<SctpChannel>() {

View File

@ -43,7 +43,7 @@ public class OioSctpEchoServer {
ServerBootstrap b = new ServerBootstrap();
try {
b.group(new OioEventLoopGroup(), new OioEventLoopGroup())
.channel(new OioSctpServerChannel())
.channel(OioSctpServerChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.localAddress(new InetSocketAddress(port))
.childOption(ChannelOption.SCTP_NODELAY, true)

View File

@ -293,7 +293,6 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
try {
javaChannel().bindAddress(localAddress);
future.setSuccess();
// TODO: Do we want to fire an event ?
} catch (Throwable t) {
future.setFailure(t);
pipeline().fireExceptionCaught(t);
@ -320,7 +319,6 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
try {
javaChannel().unbindAddress(localAddress);
future.setSuccess();
// TODO: Do we want to fire an event ?
} catch (Throwable t) {
future.setFailure(t);
pipeline().fireExceptionCaught(t);

View File

@ -25,6 +25,7 @@ import io.netty.buffer.MessageBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.socket.DefaultSctpChannelConfig;
import io.netty.channel.socket.SctpChannelConfig;
@ -34,6 +35,7 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.util.Collections;
@ -248,4 +250,56 @@ public class OioSctpChannel extends AbstractOioMessageChannel
protected void doClose() throws Exception {
ch.close();
}
@Override
public ChannelFuture bindAddress(InetAddress localAddress) {
ChannelFuture future = newFuture();
doBindAddress(localAddress, future);
return future;
}
void doBindAddress(final InetAddress localAddress, final ChannelFuture future) {
if (eventLoop().inEventLoop()) {
try {
ch.bindAddress(localAddress);
future.setSuccess();
} catch (Throwable t) {
future.setFailure(t);
pipeline().fireExceptionCaught(t);
}
} else {
eventLoop().execute(new Runnable() {
@Override
public void run() {
doBindAddress(localAddress, future);
}
});
}
}
@Override
public ChannelFuture unbindAddress(InetAddress localAddress) {
ChannelFuture future = newFuture();
doUnbindAddress(localAddress, future);
return future;
}
void doUnbindAddress(final InetAddress localAddress, final ChannelFuture future) {
if (eventLoop().inEventLoop()) {
try {
ch.unbindAddress(localAddress);
future.setSuccess();
} catch (Throwable t) {
future.setFailure(t);
pipeline().fireExceptionCaught(t);
}
} else {
eventLoop().execute(new Runnable() {
@Override
public void run() {
doUnbindAddress(localAddress, future);
}
});
}
}
}