1 /* |
1 /* |
2 * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 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 4513011 |
25 * @bug 4513011 |
26 * @summary Registering and cancelling same fd many times |
26 * @summary Registering and cancelling same fd many times |
27 * @library .. |
27 * @library .. |
28 */ |
28 */ |
29 |
29 |
30 import java.io.*; |
|
31 import java.net.*; |
30 import java.net.*; |
32 import java.nio.*; |
31 import java.nio.*; |
33 import java.nio.channels.*; |
32 import java.nio.channels.*; |
|
33 import java.nio.channels.spi.SelectorProvider; |
34 import java.util.*; |
34 import java.util.*; |
35 import java.nio.channels.spi.SelectorProvider; |
|
36 |
35 |
37 public class Alias { |
36 public class Alias { |
38 |
37 |
39 static int success = 0; |
38 static int success = 0; |
40 static int LIMIT = 20; // Hangs after just 1 if problem is present |
39 static int LIMIT = 20; // Hangs after just 1 if problem is present |
41 |
40 |
42 public static void main(String[] args) throws Exception { |
41 public static void main(String[] args) throws Exception { |
43 test1(); |
42 try (TestServers.DayTimeServer daytimeServer |
|
43 = TestServers.DayTimeServer.startNewServer(100)) { |
|
44 test1(daytimeServer); |
|
45 } |
44 } |
46 } |
45 |
47 |
46 public static void test1() throws Exception { |
48 static void test1(TestServers.DayTimeServer daytimeServer) throws Exception { |
47 Selector selector = SelectorProvider.provider().openSelector(); |
49 Selector selector = SelectorProvider.provider().openSelector(); |
48 InetAddress myAddress=InetAddress.getByName(TestUtil.HOST); |
50 InetAddress myAddress = daytimeServer.getAddress(); |
49 InetSocketAddress isa = new InetSocketAddress(myAddress,13); |
51 InetSocketAddress isa |
|
52 = new InetSocketAddress(myAddress, |
|
53 daytimeServer.getPort()); |
50 |
54 |
51 for (int j=0; j<LIMIT; j++) { |
55 for (int j=0; j<LIMIT; j++) { |
52 SocketChannel sc = SocketChannel.open(); |
56 SocketChannel sc = SocketChannel.open(); |
53 sc.configureBlocking(false); |
57 sc.configureBlocking(false); |
54 boolean result = sc.connect(isa); |
58 boolean result = sc.connect(isa); |
|
59 |
|
60 // On some platforms - given that we're using a local server, |
|
61 // we may not enter into the if () { } statement below... |
55 if (!result) { |
62 if (!result) { |
56 SelectionKey key = sc.register(selector, |
63 SelectionKey key = sc.register(selector, |
57 SelectionKey.OP_CONNECT); |
64 SelectionKey.OP_CONNECT); |
58 while (!result) { |
65 while (!result) { |
59 int keysAdded = selector.select(100); |
66 int keysAdded = selector.select(100); |