test/java/nio/channels/Selector/ConnectWrite.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 25,51 **** * @bug 4505829 * @summary Test ready for connect followed by ready for write * @library .. */ - import java.io.*; import java.net.*; - import java.nio.*; import java.nio.channels.*; - import java.util.*; import java.nio.channels.spi.SelectorProvider; public class ConnectWrite { public static void main(String[] args) throws Exception { ! test1(13); } ! public static void test1(int port) throws Exception { Selector selector = SelectorProvider.provider().openSelector(); ! InetAddress myAddress=InetAddress.getByName(TestUtil.HOST); ! InetSocketAddress isa = new InetSocketAddress(myAddress, port); SocketChannel sc = SocketChannel.open(); try { sc.configureBlocking(false); SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT); boolean result = sc.connect(isa); --- 25,53 ---- * @bug 4505829 * @summary Test ready for connect followed by ready for write * @library .. */ import java.net.*; import java.nio.channels.*; import java.nio.channels.spi.SelectorProvider; + import java.util.*; public class ConnectWrite { public static void main(String[] args) throws Exception { ! try (TestClass.DayTimeServer daytimeServer ! = TestClass.DayTimeServer.startNewServer(25)) { ! test1(daytimeServer); ! } } ! static void test1(TestClass.DayTimeServer daytimeServer) throws Exception { Selector selector = SelectorProvider.provider().openSelector(); ! InetAddress myAddress = daytimeServer.getAddress(); ! InetSocketAddress isa ! = new InetSocketAddress(myAddress, daytimeServer.getPort()); SocketChannel sc = SocketChannel.open(); try { sc.configureBlocking(false); SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT); boolean result = sc.connect(isa);