From 6880e27ce90f938941593d0dcc15fb9e6c7b08f6 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 4 Mar 2015 20:02:37 +0100 Subject: [PATCH] [#3463] EpollSocketChannel.localAddress() returns always null if Native.connect() was not able to connect directly Motivation: Due a a regression that was introduced by b898bdd we failed to set the localAddress if the connect did not success directly. Modifications: Correct set localAddress in doConnect(...) Result: Be able to get the localAddress in all cases. --- .../io/netty/channel/epoll/EpollSocketChannel.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java index 9177e4db26..39bb0e0577 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java @@ -181,13 +181,17 @@ public final class EpollSocketChannel extends AbstractEpollStreamChannel impleme checkResolvable((InetSocketAddress) localAddress); } checkResolvable((InetSocketAddress) remoteAddress); - if (super.doConnect(remoteAddress, localAddress)) { - int fd = fd().intValue(); - local = Native.localAddress(fd); + int fd = fd().intValue(); + boolean connected = super.doConnect(remoteAddress, localAddress); + if (connected) { remote = (InetSocketAddress) remoteAddress; return true; } - return false; + // We always need to set the localAddress even if not connected yet + // + // See https://github.com/netty/netty/issues/3463 + local = Native.localAddress(fd); + return connected; } private final class EpollSocketChannelUnsafe extends EpollStreamUnsafe {