Use InetSocketAddress(0) if no localAddress is specified for connect() operation in UDT

This commit is contained in:
Trustin Lee 2013-01-31 10:22:03 +09:00
parent eeab6767db
commit 604b359d9e
4 changed files with 20 additions and 20 deletions

View File

@ -25,13 +25,12 @@ import io.netty.example.udt.util.UtilConsoleReporter;
import io.netty.example.udt.util.UtilThreadFactory; import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* UDT Byte Stream Client * UDT Byte Stream Client
* <p> * <p>
@ -63,7 +62,7 @@ public class ByteEchoClient {
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
connectFactory, NioUdtProvider.BYTE_PROVIDER); connectFactory, NioUdtProvider.BYTE_PROVIDER);
try { try {
boot.group(connectGroup).localAddress(0) boot.group(connectGroup)
.channelFactory(NioUdtProvider.BYTE_CONNECTOR) .channelFactory(NioUdtProvider.BYTE_CONNECTOR)
.handler(new ChannelInitializer<UdtChannel>() { .handler(new ChannelInitializer<UdtChannel>() {
@Override @Override

View File

@ -25,13 +25,12 @@ import io.netty.example.udt.util.UtilConsoleReporter;
import io.netty.example.udt.util.UtilThreadFactory; import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* UDT Message Flow client * UDT Message Flow client
* <p> * <p>
@ -63,7 +62,7 @@ public class MsgEchoClient {
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
connectFactory, NioUdtProvider.MESSAGE_PROVIDER); connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
try { try {
boot.group(connectGroup).localAddress(0) boot.group(connectGroup)
.channelFactory(NioUdtProvider.MESSAGE_CONNECTOR) .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR)
.handler(new ChannelInitializer<UdtChannel>() { .handler(new ChannelInitializer<UdtChannel>() {
@Override @Override

View File

@ -15,24 +15,25 @@
*/ */
package io.netty.channel.udt.nio; package io.netty.channel.udt.nio;
import static java.nio.channels.SelectionKey.*; import com.barchart.udt.TypeUDT;
import com.barchart.udt.nio.SocketChannelUDT;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.socket.nio.AbstractNioByteChannel; import io.netty.channel.socket.nio.AbstractNioByteChannel;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.channel.udt.DefaultUdtChannelConfig; import io.netty.channel.udt.DefaultUdtChannelConfig;
import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.UdtChannel;
import io.netty.channel.udt.UdtChannelConfig; import io.netty.channel.udt.UdtChannelConfig;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import com.barchart.udt.TypeUDT; import static java.nio.channels.SelectionKey.*;
import com.barchart.udt.nio.SocketChannelUDT;
/** /**
* Byte Channel Connector for UDT Streams. * Byte Channel Connector for UDT Streams.
@ -104,7 +105,7 @@ public class NioUdtByteConnectorChannel extends AbstractNioByteChannel
@Override @Override
protected boolean doConnect(final SocketAddress remoteAddress, protected boolean doConnect(final SocketAddress remoteAddress,
final SocketAddress localAddress) throws Exception { final SocketAddress localAddress) throws Exception {
doBind(localAddress); doBind(localAddress != null? localAddress : new InetSocketAddress(0));
boolean success = false; boolean success = false;
try { try {
final boolean connected = javaChannel().connect(remoteAddress); final boolean connected = javaChannel().connect(remoteAddress);

View File

@ -15,7 +15,8 @@
*/ */
package io.netty.channel.udt.nio; package io.netty.channel.udt.nio;
import static java.nio.channels.SelectionKey.*; import com.barchart.udt.TypeUDT;
import com.barchart.udt.nio.SocketChannelUDT;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
@ -23,18 +24,18 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.socket.nio.AbstractNioMessageChannel; import io.netty.channel.socket.nio.AbstractNioMessageChannel;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.channel.udt.DefaultUdtChannelConfig; import io.netty.channel.udt.DefaultUdtChannelConfig;
import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.UdtChannel;
import io.netty.channel.udt.UdtChannelConfig; import io.netty.channel.udt.UdtChannelConfig;
import io.netty.channel.udt.UdtMessage; import io.netty.channel.udt.UdtMessage;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import com.barchart.udt.TypeUDT; import static java.nio.channels.SelectionKey.*;
import com.barchart.udt.nio.SocketChannelUDT;
/** /**
* Message Connector for UDT Datagrams. * Message Connector for UDT Datagrams.
@ -108,7 +109,7 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel
@Override @Override
protected boolean doConnect(final SocketAddress remoteAddress, protected boolean doConnect(final SocketAddress remoteAddress,
final SocketAddress localAddress) throws Exception { final SocketAddress localAddress) throws Exception {
doBind(localAddress); doBind(localAddress != null? localAddress : new InetSocketAddress(0));
boolean success = false; boolean success = false;
try { try {
final boolean connected = javaChannel().connect(remoteAddress); final boolean connected = javaChannel().connect(remoteAddress);