src/java.base/unix/classes/sun/nio/ch/PollSelectorImpl.java
Print this page
*** 26,37 ****
package sun.nio.ch;
import java.io.IOException;
import java.nio.channels.*;
import java.nio.channels.spi.*;
! import java.util.*;
! import sun.misc.*;
/**
* An implementation of Selector for Solaris.
*/
--- 26,36 ----
package sun.nio.ch;
import java.io.IOException;
import java.nio.channels.*;
import java.nio.channels.spi.*;
! import java.util.function.Consumer;
/**
* An implementation of Selector for Solaris.
*/
*** 60,94 ****
pollWrapper = new PollArrayWrapper(INIT_CAP);
pollWrapper.initInterrupt(fd0, fd1);
channelArray = new SelectionKeyImpl[INIT_CAP];
}
! protected int doSelect(long timeout)
! throws IOException
! {
if (channelArray == null)
throw new ClosedSelectorException();
processDeregisterQueue();
try {
begin();
pollWrapper.poll(totalChannels, 0, timeout);
} finally {
end();
}
processDeregisterQueue();
- int numKeysUpdated = updateSelectedKeys();
- if (pollWrapper.getReventOps(0) != 0) {
- // Clear the wakeup pipe
- pollWrapper.putReventOps(0, 0);
- synchronized (interruptLock) {
- IOUtil.drain(fd0);
- interruptTriggered = false;
- }
- }
- return numKeysUpdated;
}
protected void implCloseInterrupt() throws IOException {
// prevent further wakeup
synchronized (interruptLock) {
interruptTriggered = true;
}
--- 59,122 ----
pollWrapper = new PollArrayWrapper(INIT_CAP);
pollWrapper.initInterrupt(fd0, fd1);
channelArray = new SelectionKeyImpl[INIT_CAP];
}
! @Override
! protected int doSelect(long timeout) throws IOException {
! pollWrapper(timeout);
! int numKeysUpdated = updateSelectedKeys();
! clearWakeupPipeIfInterrupted();
! return numKeysUpdated;
! }
!
! @Override
! protected int doSelect(Consumer<SelectionKey> handler, long timeout) throws IOException {
! pollWrapper(timeout);
! int numKeysUpdated = 0;
! // Skip zeroth entry; it is for interrupts only
! for (int i=channelOffset; i<totalChannels; i++) {
! int rOps = pollWrapper.getReventOps(i);
! if (rOps != 0) {
! SelectionKeyImpl ski = channelArray[i];
! pollWrapper.putReventOps(i, 0);
! ski.channel.translateAndSetReadyOps(rOps, ski);
! if (ski.hasOps()) {
! handler.accept(ski);
! numKeysUpdated++;
! }
! }
! }
! clearWakeupPipeIfInterrupted();
! return numKeysUpdated;
! }
!
! private void clearWakeupPipeIfInterrupted() throws IOException {
! if (pollWrapper.getReventOps(0) != 0) {
! // Clear the wakeup pipe
! pollWrapper.putReventOps(0, 0);
! synchronized (interruptLock) {
! IOUtil.drain(fd0);
! interruptTriggered = false;
! }
! }
! }
!
! private void pollWrapper(long timeout) throws ClosedSelectorException, IOException {
if (channelArray == null)
throw new ClosedSelectorException();
processDeregisterQueue();
try {
begin();
pollWrapper.poll(totalChannels, 0, timeout);
} finally {
end();
}
processDeregisterQueue();
}
+ @Override
protected void implCloseInterrupt() throws IOException {
// prevent further wakeup
synchronized (interruptLock) {
interruptTriggered = true;
}