Only cache the localAddress if its a non wildcard address, so its possible to retrieve the 'real' adress later once the channel is fully bound/connected. See #524

This commit is contained in:
norman 2012-08-16 07:38:38 +02:00
parent b6264c02d9
commit 24f1b54c86

View File

@ -128,7 +128,13 @@ abstract class AbstractNioChannel<C extends SelectableChannel & WritableByteChan
InetSocketAddress localAddress = this.localAddress;
if (localAddress == null) {
try {
this.localAddress = localAddress = getLocalSocketAddress();
localAddress = getLocalSocketAddress();
if (localAddress.getAddress().isAnyLocalAddress()) {
// Don't cache on a wildcard address so the correct one
// will be cached once the channel is connected/bound
return localAddress;
}
this.localAddress = localAddress;
} catch (Throwable t) {
// Sometimes fails on a closed socket in Windows.
return null;