1 /* 2 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.nio.ch; 27 28 import java.nio.channels.Channel; 29 import java.io.FileDescriptor; 30 import java.io.IOException; 31 32 import static java.util.concurrent.TimeUnit.NANOSECONDS; 33 34 /** 35 * An interface that allows translation (and more!). 36 * 37 * @since 1.4 38 */ 39 40 public interface SelChImpl extends Channel { 41 getFD()42 FileDescriptor getFD(); 43 getFDVal()44 int getFDVal(); 45 46 /** 47 * Adds the specified ops if present in interestOps. The specified 48 * ops are turned on without affecting the other ops. 49 * 50 * @return true iff the new value of sk.readyOps() set by this method 51 * contains at least one bit that the previous value did not 52 * contain 53 */ translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk)54 public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk); 55 56 /** 57 * Sets the specified ops if present in interestOps. The specified 58 * ops are turned on, and all other ops are turned off. 59 * 60 * @return true iff the new value of sk.readyOps() set by this method 61 * contains at least one bit that the previous value did not 62 * contain 63 */ translateAndSetReadyOps(int ops, SelectionKeyImpl sk)64 public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk); 65 translateAndSetInterestOps(int ops, SelectionKeyImpl sk)66 void translateAndSetInterestOps(int ops, SelectionKeyImpl sk); 67 validOps()68 int validOps(); 69 kill()70 void kill() throws IOException; 71 72 /** 73 * Disables the current thread for scheduling purposes until this 74 * channel is ready for I/O, or asynchronously closed, for up to the 75 * specified waiting time. 76 * 77 * <p> This method does <em>not</em> report which of these caused the 78 * method to return. Callers should re-check the conditions which caused 79 * the thread to park. 80 * 81 * @param event the event to poll 82 * @param nanos the timeout to wait; {@code <= 0} to wait indefinitely 83 */ park(int event, long nanos)84 default void park(int event, long nanos) throws IOException { 85 long millis; 86 if (nanos <= 0) { 87 millis = -1; 88 } else { 89 millis = NANOSECONDS.toMillis(nanos); 90 } 91 Net.poll(getFD(), event, millis); 92 } 93 94 /** 95 * Disables the current thread for scheduling purposes until this 96 * channel is ready for I/O, or asynchronously closed. 97 * 98 * <p> This method does <em>not</em> report which of these caused the 99 * method to return. Callers should re-check the conditions which caused 100 * the thread to park. 101 * 102 * @param event the event to poll 103 */ park(int event)104 default void park(int event) throws IOException { 105 park(event, 0L); 106 } 107 108 } 109