Path: blob/master/src/java.base/share/classes/sun/nio/ch/SelChImpl.java
41159 views
/*1* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.ch;2627import java.nio.channels.Channel;28import java.io.FileDescriptor;29import java.io.IOException;3031import static java.util.concurrent.TimeUnit.NANOSECONDS;3233/**34* An interface that allows translation (and more!).35*36* @since 1.437*/3839public interface SelChImpl extends Channel {4041FileDescriptor getFD();4243int getFDVal();4445/**46* Adds the specified ops if present in interestOps. The specified47* ops are turned on without affecting the other ops.48*49* @return true iff the new value of sk.readyOps() set by this method50* contains at least one bit that the previous value did not51* contain52*/53boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski);5455/**56* Sets the specified ops if present in interestOps. The specified57* ops are turned on, and all other ops are turned off.58*59* @return true iff the new value of sk.readyOps() set by this method60* contains at least one bit that the previous value did not61* contain62*/63boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski);6465/**66* Translates an interest operation set into a native event set67*/68int translateInterestOps(int ops);6970void kill() throws IOException;7172/**73* Disables the current thread for scheduling purposes until this74* channel is ready for I/O, or asynchronously closed, for up to the75* specified waiting time.76*77* <p> This method does <em>not</em> report which of these caused the78* method to return. Callers should re-check the conditions which caused79* the thread to park.80*81* @param event the event to poll82* @param nanos the timeout to wait; {@code <= 0} to wait indefinitely83*/84default void park(int event, long nanos) throws IOException {85long millis;86if (nanos <= 0) {87millis = -1;88} else {89millis = NANOSECONDS.toMillis(nanos);90}91Net.poll(getFD(), event, millis);92}9394/**95* Disables the current thread for scheduling purposes until this96* channel is ready for I/O, or asynchronously closed.97*98* <p> This method does <em>not</em> report which of these caused the99* method to return. Callers should re-check the conditions which caused100* the thread to park.101*102* @param event the event to poll103*/104default void park(int event) throws IOException {105park(event, 0L);106}107108}109110111