When I read the documentation for SocketChannel, it seems pretty clear that a blocking SocketChannel connect() call will only ever return true or throw an exception. In other words, it can only return false in non-blocking mode. Is that correct, or am I missing/misreading something?
Is it possible for channel.configureBlocking(true) to return and the channel not be in blocking mode? I would expect that if configureBlocking(true) were not able to successfully put the channel in blocking mode (before the return of the method call), an exception would be thrown. Is that correct?
Finally, is there any way for the following code to fail to connect and yet return TRUE? (The code only tests whether the connection succeeds or not, it doesn't do anything with the channel, hence the immediate close):
SocketChannel channel = null;
try {
channel = SocketChannel.open();
channel.configureBlocking(true);
channel.connect(new InetSocketAddress(addr, port));
return Boolean.TRUE;
}
catch (Exception e) {
return Boolean.FALSE;
}
finally {
if (channel != null) {
try { channel.close() } catch (Exception e) {}
}
}
Thanks!