jdk/test/java/nio/channels/Selector/LotsOfUpdates.java
author dfuchs
Wed, 07 Nov 2012 13:24:39 +0100
changeset 14415 7a31b0e0cfaf
parent 5506 202f599c92aa
child 45387 179605f4d367
permissions -rw-r--r--
6720349: (ch) Channels tests depending on hosts inside Sun Summary: This changeset make the nio tests start small TCP or UDP servers from within the tests, instead of relying on external services. Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2444
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2444
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2444
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     4
 *
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     8
 *
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    13
 * accompanied this code).
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    14
 *
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2444
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2444
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2444
diff changeset
    21
 * questions.
2444
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    22
 */
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    23
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    24
import java.nio.channels.*;
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    25
import java.io.IOException;
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    26
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    27
public class LotsOfUpdates {
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    28
    public static void main(String[] args) throws IOException {
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    29
        Selector sel = Selector.open();
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    30
        SocketChannel sc = SocketChannel.open();
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    31
        sc.configureBlocking(false);
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    32
        SelectionKey key = sc.register(sel, 0);
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    33
        for (int i=0; i<50000; i++) {
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    34
            key.interestOps(0);
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    35
        }
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    36
        sel.selectNow();
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    37
    }
282b8abf92eb 6824477: (se) Selector.select fails with IOException: "Invalid argument" if maximum file descriptors is low
alanb
parents:
diff changeset
    38
}