IsConnectable.java revision 0
1292N/A/*
2362N/A * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
1292N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1292N/A *
1292N/A * This code is free software; you can redistribute it and/or modify it
1292N/A * under the terms of the GNU General Public License version 2 only, as
1292N/A * published by the Free Software Foundation.
1292N/A *
1292N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1292N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1292N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1292N/A * version 2 for more details (a copy is included in the LICENSE file that
1292N/A * accompanied this code).
1292N/A *
1292N/A * You should have received a copy of the GNU General Public License version
1292N/A * 2 along with this work; if not, write to the Free Software Foundation,
1292N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1292N/A *
2362N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2362N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any questions.
1292N/A */
1292N/A
1292N/A/* @test
1292N/A * @bug 4737146 4750573
1292N/A * @summary Test if isConnectable returns true after connected
1292N/A * @library ..
1292N/A */
1292N/A
1292N/Aimport java.net.*;
1292N/Aimport java.io.*;
1292N/Aimport java.nio.*;
1292N/Aimport java.nio.channels.*;
1292N/Aimport java.nio.channels.spi.SelectorProvider;
1292N/Aimport java.util.*;
1292N/A
1292N/Apublic class IsConnectable {
1292N/A
1292N/A static final int DAYTIME_PORT = 13;
1292N/A static final String DAYTIME_HOST = TestUtil.HOST;
1292N/A
1292N/A static void test() throws Exception {
1292N/A InetSocketAddress isa
1292N/A = new InetSocketAddress(InetAddress.getByName(DAYTIME_HOST),
1292N/A DAYTIME_PORT);
1292N/A SocketChannel sc = SocketChannel.open();
1292N/A sc.configureBlocking(false);
1292N/A sc.connect(isa);
1292N/A
1292N/A Selector selector = SelectorProvider.provider().openSelector();
1292N/A SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
1292N/A int keysAdded = selector.select();
1292N/A if (keysAdded > 0) {
1292N/A boolean result = sc.finishConnect();
1292N/A if (result) {
1292N/A keysAdded = selector.select(5000);
1292N/A // 4750573: keysAdded should not be incremented when op is dropped
1292N/A // from a key already in the selected key set
1292N/A if (keysAdded > 0)
1292N/A throw new Exception("Test failed: 4750573 detected");
1292N/A Set sel = selector.selectedKeys();
1292N/A Iterator i = sel.iterator();
1292N/A SelectionKey sk = (SelectionKey)i.next();
1292N/A // 4737146: isConnectable should be false while connected
1292N/A if (sk.isConnectable())
1292N/A throw new Exception("Test failed: 4737146 detected");
1292N/A }
1292N/A } else {
1292N/A throw new Exception("Select failed");
1292N/A }
1292N/A sc.close();
1292N/A }
1292N/A
1292N/A public static void main(String[] args) throws Exception {
1292N/A test();
1292N/A }
1292N/A
1292N/A}
1292N/A