< prev index next >

src/java.base/share/classes/sun/nio/ch/SelChImpl.java

Print this page

 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 
 42     FileDescriptor getFD();
 43 
 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

 54     boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski);
 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      */
 64     boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski);
 65 
 66     /**
 67      * Translates an interest operation set into a native event set
 68      */
 69     int translateInterestOps(int ops);
 70 
 71     void kill() throws IOException;
 72 
 73     /**
 74      * Disables the current thread for scheduling purposes until this
 75      * channel is ready for I/O, or asynchronously closed, for up to the
 76      * specified waiting time.
 77      *
 78      * <p> This method does <em>not</em> report which of these caused the
 79      * method to return. Callers should re-check the conditions which caused
 80      * the thread to park.
 81      *
 82      * @param event the event to poll
 83      * @param nanos the timeout to wait; {@code <= 0} to wait indefinitely
 84      */
 85     default void park(int event, long nanos) throws IOException {
 86         long millis;
 87         if (nanos <= 0) {
 88             millis = -1;










 89         } else {
 90             millis = NANOSECONDS.toMillis(nanos);






 91         }
 92         Net.poll(getFD(), event, millis);
 93     }
 94 
 95     /**
 96      * Disables the current thread for scheduling purposes until this
 97      * channel is ready for I/O, or asynchronously closed.
 98      *
 99      * <p> This method does <em>not</em> report which of these caused the
100      * method to return. Callers should re-check the conditions which caused
101      * the thread to park.
102      *
103      * @param event the event to poll
104      */
105     default void park(int event) throws IOException {
106         park(event, 0L);
107     }
108 
109 }

 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 import jdk.internal.misc.VirtualThreads;
 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 
 42     FileDescriptor getFD();
 43 
 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

 54     boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski);
 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      */
 64     boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski);
 65 
 66     /**
 67      * Translates an interest operation set into a native event set
 68      */
 69     int translateInterestOps(int ops);
 70 
 71     void kill() throws IOException;
 72 
 73     /**
 74      * Disables the current thread  for scheduling purposes until this
 75      * channel is ready for I/O, or asynchronously closed, for up to the
 76      * specified waiting time.
 77      *
 78      * <p> This method does <em>not</em> report which of these caused the
 79      * method to return. Callers should re-check the conditions which caused
 80      * the thread to park.
 81      *
 82      * @param event the event to poll
 83      * @param nanos the timeout to wait; {@code <= 0} to wait indefinitely
 84      */
 85     default void park(int event, long nanos) throws IOException {
 86         if (Thread.currentThread().isVirtual()) {
 87             Poller.register(getFDVal(), event);
 88             try {
 89                 if (isOpen()) {
 90                     if (nanos == 0) {
 91                         VirtualThreads.park();
 92                     } else {
 93                         VirtualThreads.park(nanos);
 94                     }
 95                 }
 96             } finally {
 97                 Poller.deregister(getFDVal(), event);
 98             }
 99         } else {
100             long millis;
101             if (nanos == 0) {
102                 millis = -1;
103             } else {
104                 millis = NANOSECONDS.toMillis(nanos);
105             }
106             Net.poll(getFD(), event, millis);
107         }

108     }
109 
110     /**
111      * Disables the current thread for scheduling purposes until this
112      * channel is ready for I/O, or asynchronously closed.
113      *
114      * <p> This method does <em>not</em> report which of these caused the
115      * method to return. Callers should re-check the conditions which caused
116      * the thread to park.
117      *
118      * @param event the event to poll
119      */
120     default void park(int event) throws IOException {
121         park(event, 0L);
122     }

123 }
< prev index next >