< prev index next > src/java.base/share/classes/sun/nio/ch/NativeDispatcher.java
Print this page
package sun.nio.ch;
import java.io.FileDescriptor;
import java.io.IOException;
- import jdk.internal.access.JavaIOFileDescriptorAccess;
- import jdk.internal.access.SharedSecrets;
/**
* Allows different platforms to call different native methods
* for read and write operations.
*/
abstract class NativeDispatcher {
- private static final JavaIOFileDescriptorAccess JIOFDA = SharedSecrets.getJavaIOFileDescriptorAccess();
abstract int read(FileDescriptor fd, long address, int len)
throws IOException;
/**
* Prepare the given file descriptor for closing. If a virtual thread is blocked
* on the file descriptor then it is unparked so that it stops polling. On Unix systems,
* if a platform thread is blocked on the file descriptor then the file descriptor is
* dup'ed to a special fd and the thread signalled so that the syscall fails with EINTR.
*/
! final void preClose(FileDescriptor fd, long reader, long writer) throws IOException {
! if (NativeThread.isVirtualThread(reader) || NativeThread.isVirtualThread(writer)) {
! int fdVal = JIOFDA.get(fd);
! Poller.stopPoll(fdVal);
}
if (NativeThread.isNativeThread(reader) || NativeThread.isNativeThread(writer)) {
implPreClose(fd, reader, writer);
}
}
/**
* This method does nothing by default. On Unix systems the file descriptor is dup'ed
* to a special fd and native threads signalled.
*/
!
- void implPreClose(FileDescriptor fd, long reader, long writer) throws IOException {
// Do nothing by default; this is only needed on Unix
}
/**
* Duplicates a file descriptor.
* Prepare the given file descriptor for closing. If a virtual thread is blocked
* on the file descriptor then it is unparked so that it stops polling. On Unix systems,
* if a platform thread is blocked on the file descriptor then the file descriptor is
* dup'ed to a special fd and the thread signalled so that the syscall fails with EINTR.
*/
! final void preClose(FileDescriptor fd, NativeThread reader, NativeThread writer) throws IOException {
! if (NativeThread.isVirtualThread(reader)) {
! Poller.stopPoll(reader.thread());
! }
+ if (NativeThread.isVirtualThread(writer)) {
+ Poller.stopPoll(writer.thread());
}
if (NativeThread.isNativeThread(reader) || NativeThread.isNativeThread(writer)) {
implPreClose(fd, reader, writer);
}
}
/**
* This method does nothing by default. On Unix systems the file descriptor is dup'ed
* to a special fd and native threads signalled.
*/
! void implPreClose(FileDescriptor fd, NativeThread reader, NativeThread writer) throws IOException {
// Do nothing by default; this is only needed on Unix
}
/**
* Duplicates a file descriptor.
< prev index next >