Code Review Request: 7096436: (sc) SocketChannel.connect fails on Windows 8 when channel configured non-blocking

Alan Bateman Alan.Bateman at oracle.com
Sat May 5 04:42:39 PDT 2012


On 04/05/2012 19:46, Kurchi Hazra wrote:
> Hi,
>
>  We were seting localAddress when establishing the connection but for 
> the non-blocking case, it is possible that the socket is not yet bound.
> We therefore change this behavior and retrieve the localAddress in 
> SocketChannelImpl.getLocalAddress() when the socket is bound and 
> localAddress is null or isAnyLocalAddress.
>
> However, I also had to introduce an additional boolean field to keep 
> track of when the socket is bound. This is to circumvent the  problem 
> that we
> don't get an error (similar to WSAEINVAL on windows) on 
> solaris/linux/mac when calling getsockopt on an unbound socket. 
> Consequently, localAddress
> and localPort are being set to 0.0.0.0 and 0 on these platforms, 
> instead of the required null and -1.
>
> Bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7096436
> Webrev: http://cr.openjdk.java.net/~khazra/7096436/webrev.00/
Thanks for taking this one, the assumption has always been that the 
connect would cause the socket to be bound immediately, if not already 
bound.

I agree with removing the code at L632-640 as that's where the 
assumption is that the socket is implicitly bound. However if we assign 
localAddress in the two places where we set the state to ST_CONNECTED 
(connect and finishConnect) then it should solve the issue. So unless 
I'm missing something (could very well b) then the "bound" field 
shouldn't be needed. I also have concern about adding this field because 
"state" and "localAddress" should already cover all states. An 
alternative to not setting the localAddress after the connection is 
establish is to change getLocalAddress to:

if (localAddress == null && (state == ST_CONNECTED))
localAddress = Net.localAddress(fd);

The downside to that is that on some platforms this can fail for the 
case that the peer has closed the connection.

-Alan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20120505/0774ad91/attachment.html 


More information about the nio-dev mailing list