test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/EchoService.java
changeset 51117 c96c7d08ae49
parent 47216 71c04702a3d5
equal deleted inserted replaced
51116:7e34f3da2293 51117:c96c7d08ae49
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2018, 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.
    63 import java.nio.channels.SelectionKey;
    63 import java.nio.channels.SelectionKey;
    64 import java.nio.channels.Selector;
    64 import java.nio.channels.Selector;
    65 import java.nio.channels.ServerSocketChannel;
    65 import java.nio.channels.ServerSocketChannel;
    66 import java.nio.channels.SocketChannel;
    66 import java.nio.channels.SocketChannel;
    67 
    67 
       
    68 import jdk.test.lib.Utils;
       
    69 
    68 public class EchoService {
    70 public class EchoService {
    69 
    71 
    70     private static void doIt(SocketChannel sc, int closeAfter, int delay) throws IOException {
    72     private static void doIt(SocketChannel sc, int closeAfter, int delay) throws IOException {
    71         ByteBuffer bb = ByteBuffer.allocate(1024);
    73         ByteBuffer bb = ByteBuffer.allocate(1024);
    72         int total = 0;
    74         int total = 0;
   171             Selector sel = ssc.provider().openSelector();
   173             Selector sel = ssc.provider().openSelector();
   172             SelectionKey sk = ssc.register(sel, SelectionKey.OP_ACCEPT);
   174             SelectionKey sk = ssc.register(sel, SelectionKey.OP_ACCEPT);
   173             SocketChannel sc;
   175             SocketChannel sc;
   174             int count = 0;
   176             int count = 0;
   175             for (;;) {
   177             for (;;) {
   176                  sel.select(5000);
   178                  sel.select((int)Utils.adjustTimeout(5000));
   177                  if (sk.isAcceptable() && ((sc = ssc.accept()) != null)) {
   179                  if (sk.isAcceptable() && ((sc = ssc.accept()) != null)) {
   178                     Worker w = new Worker(sc);
   180                     Worker w = new Worker(sc);
   179                     (new Thread(w)).start();
   181                     (new Thread(w)).start();
   180                  } else {
   182                  } else {
   181                      // if all clients have disconnected then we die as well.
   183                      // if all clients have disconnected then we die as well.