jdk/test/java/nio/channels/Selector/ConnectWrite.java
changeset 14415 7a31b0e0cfaf
parent 7668 d4a77089c587
equal deleted inserted replaced
14414:f338be3ef659 14415:7a31b0e0cfaf
     1 /*
     1 /*
     2  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @bug 4505829
    25  * @bug 4505829
    26  * @summary Test ready for connect followed by ready for write
    26  * @summary Test ready for connect followed by ready for write
    27  * @library ..
    27  * @library ..
    28  */
    28  */
    29 
    29 
    30 import java.io.*;
       
    31 import java.net.*;
    30 import java.net.*;
    32 import java.nio.*;
       
    33 import java.nio.channels.*;
    31 import java.nio.channels.*;
       
    32 import java.nio.channels.spi.SelectorProvider;
    34 import java.util.*;
    33 import java.util.*;
    35 import java.nio.channels.spi.SelectorProvider;
       
    36 
    34 
    37 public class ConnectWrite {
    35 public class ConnectWrite {
    38 
    36 
    39     public static void main(String[] args) throws Exception {
    37     public static void main(String[] args) throws Exception {
    40         test1(13);
    38         try (TestServers.DayTimeServer daytimeServer
       
    39                 = TestServers.DayTimeServer.startNewServer(25)) {
       
    40             test1(daytimeServer);
       
    41         }
    41     }
    42     }
    42 
    43 
    43     public static void test1(int port) throws Exception {
    44     static void test1(TestServers.DayTimeServer daytimeServer) throws Exception {
    44         Selector selector = SelectorProvider.provider().openSelector();
    45         Selector selector = SelectorProvider.provider().openSelector();
    45         InetAddress myAddress=InetAddress.getByName(TestUtil.HOST);
    46         InetAddress myAddress = daytimeServer.getAddress();
    46         InetSocketAddress isa = new InetSocketAddress(myAddress, port);
    47         InetSocketAddress isa
       
    48             = new InetSocketAddress(myAddress, daytimeServer.getPort());
    47         SocketChannel sc = SocketChannel.open();
    49         SocketChannel sc = SocketChannel.open();
    48         try {
    50         try {
    49             sc.configureBlocking(false);
    51             sc.configureBlocking(false);
    50             SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
    52             SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
    51             boolean result = sc.connect(isa);
    53             boolean result = sc.connect(isa);