title: Timeout on connect to socket using NIO SocketChannel
body: <p>We have a class that is talking to another HOST over a socket and it looks like this:</p>
  
  <pre><code>SocketChannel sc = SocketChannel.open(new InetSocketAddress(HOST, PORT));
  sc.configureBlocking(true);
  
  ...
  sc.write(...)
  sc.read(...)
  </code></pre>
  
  <p>This class works great except if the HOST is down then SocketChannel.open blocks forever. I've tried to make this timeout by doing the following:</p>
  
  <pre><code>SocketChannel  = SocketChannel.open();
  sc.configureBlocking(false);
  boolean result = socketChannel.connect(new InetSocketAddress(HOST, PORT));
  if (!result) {
      long startTime = System.currentTimeMillis();
      while (!socketChannel.finishConnect()) {
          if (System.currentTimeMillis() - startTime&lt; 1000) {
              // keep trying
              Thread.sleep(100);
          } else {
              // FAILED!
              enabled = false;
              return;
          }
      }
  }
  // SUCCESS!
  socketChannel.configureBlocking(true);
  enabled = true
  </code></pre>
  
  <p>Well for some reason finishConnect() is blocking forever when I would have expected it to not block at all. Any ideas?</p>