Skip to content

Commit

Permalink
Handle DatagramChannel in NettyContext.address
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg authored and smaldini committed Nov 7, 2017
1 parent bf09b52 commit f518f44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/main/java/reactor/ipc/netty/NettyContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel;
import reactor.core.Disposable;
Expand Down Expand Up @@ -185,6 +186,10 @@ default InetSocketAddress address(){
if (c instanceof ServerSocketChannel) {
return ((ServerSocketChannel) c).localAddress();
}
if (c instanceof DatagramChannel) {
InetSocketAddress a = ((DatagramChannel) c).remoteAddress();
return a != null ? a : ((DatagramChannel)c ).localAddress();
}
throw new IllegalStateException("Does not have an InetSocketAddress");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public InetSocketAddress address() {
return ((SocketChannel) c).remoteAddress();
}
if (c instanceof DatagramChannel) {
return ((DatagramChannel) c).localAddress();
InetSocketAddress a = ((DatagramChannel) c).remoteAddress();
return a != null ? a : ((DatagramChannel)c ).localAddress();
}
throw new IllegalStateException("Does not have an InetSocketAddress");
}
Expand Down Expand Up @@ -501,4 +502,4 @@ public interface OnNew<CHANNEL extends Channel> {
Subscription.class,
"outboundSubscription");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,7 @@ else if (log.isErrorEnabled()) {

@Override
public InetSocketAddress address() {
Channel c = f.channel();
if (c instanceof SocketChannel) {
return ((SocketChannel) c).remoteAddress();
}
if (c instanceof ServerSocketChannel) {
return ((ServerSocketChannel) c).localAddress();
}
if (c instanceof DatagramChannel) {
return ((DatagramChannel) c).localAddress();
}
throw new IllegalStateException("Does not have an InetSocketAddress");
return ((ServerSocketChannel) f.channel()).localAddress();
}

@Override
Expand Down

0 comments on commit f518f44

Please sign in to comment.