Added Multi-Homing in SctpOioChannel
This commit is contained in:
parent
db4a3a4789
commit
bf22173ed1
@ -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>() {
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user