Complete the connection.
This method is used when the channel is connectable to finish the connection, and the connectable status of a channel means the channel is after initiating in non-blocking mode and calling its connect method. It will throw related IOException if the connection failed.
This method will return true if the connection is finished already, and return false if the channel is non-blocking and the connection is not finished yet.
If the channel is in blocking mode, this method will suspend, and return true for connection finished or throw some exception otherwise. The channel will be closed if the connection failed and this method thrown some exception.
This method can be called at any moment, and can block other read and write operations while connecting.
@return
true if the connection is successfully finished,
false otherwise.
@throws NoConnectionPendingException If the channel is not connected and the connection is not initiated.
@throws ClosedChannelException If the channel is already closed.
@throws AsynchronousCloseException If the channel is closed by another thread while this method is in operation.
@throws ClosedByInterruptException If another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set, and the channel will be closed.
@throws IOException Some other IO error occurred.