< 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 static java.util.concurrent.TimeUnit.NANOSECONDS;
 32 
 33 /**
 34  * An interface that allows translation (and more!).
 35  *
 36  * @since 1.4
 37  */
 38 
 39 public interface SelChImpl extends Channel {
 40 
 41     FileDescriptor getFD();
 42 
 43     int getFDVal();
 44 
 45     /**
 46      * Adds the specified ops if present in interestOps. The specified
 47      * ops are turned on without affecting the other ops.
 48      *
 49      * @return  true iff the new value of sk.readyOps() set by this method
 50      *          contains at least one bit that the previous value did not

 53     boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski);
 54 
 55     /**
 56      * Sets the specified ops if present in interestOps. The specified
 57      * 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 method
 60      *          contains at least one bit that the previous value did not
 61      *          contain
 62      */
 63     boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski);
 64 
 65     /**
 66      * Translates an interest operation set into a native event set
 67      */
 68     int translateInterestOps(int ops);
 69 
 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      */
 84     default void park(int event, long nanos) throws IOException {
 85         if (Thread.currentThread().isVirtual()) {
 86             Poller.poll(getFDVal(), event, nanos, this::isOpen);

 87         } else {
 88             long millis;
 89             if (nanos == 0) {
 90                 millis = -1;
 91             } else {
 92                 millis = NANOSECONDS.toMillis(nanos);
 93             }
 94             Net.poll(getFD(), event, millis);
 95         }

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

111 }
< prev index next >