From 2c13671808d8908ec82a598b78be5007c6cb4a23 Mon Sep 17 00:00:00 2001 From: Kurchi Subhra Hazra Date: Wed, 9 May 2012 16:55:55 -0700 Subject: [PATCH] 7096436: (sc) SocketChannel.connect fails on Windows 8 when channel configured non-blocking Set localAddress only when connection is established Reviewed-by: alanb --- .../classes/sun/nio/ch/SocketChannelImpl.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java index fe2c5fe33ac..f0f72551614 100644 --- a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -629,17 +629,6 @@ class SocketChannelImpl break; } - synchronized (stateLock) { - if (isOpen() && (localAddress == null) || - ((InetSocketAddress)localAddress) - .getAddress().isAnyLocalAddress()) - { - // Socket was not bound before connecting or - // Socket was bound with an "anyLocalAddress" - localAddress = Net.localAddress(fd); - } - } - } finally { readerCleanup(); end((n > 0) || (n == IOStatus.UNAVAILABLE)); @@ -659,6 +648,8 @@ class SocketChannelImpl // Connection succeeded; disallow further // invocation state = ST_CONNECTED; + if (isOpen()) + localAddress = Net.localAddress(fd); return true; } // If nonblocking and no exception then connection @@ -747,6 +738,8 @@ class SocketChannelImpl if (n > 0) { synchronized (stateLock) { state = ST_CONNECTED; + if (isOpen()) + localAddress = Net.localAddress(fd); } return true; }