8199791: (se) More Selector cleanup

Reviewed-by: redestad, bpb
This commit is contained in:
Alan Bateman 2018-03-23 14:18:18 +00:00
parent de23920e05
commit 3bb85f5fc5
33 changed files with 754 additions and 1516 deletions

View file

@ -397,7 +397,9 @@ public class IOUtil {
* The read end of the pipe is returned in the high 32 bits,
* while the write end is returned in the low 32 bits.
*/
static native long makePipe(boolean blocking);
static native long makePipe(boolean blocking) throws IOException;
static native int write1(int fd, byte b) throws IOException;
static native boolean drain(int fd) throws IOException;

View file

@ -33,10 +33,10 @@ import java.nio.channels.spi.AbstractSelectionKey;
/**
* An implementation of SelectionKey for Solaris.
* An implementation of SelectionKey.
*/
public class SelectionKeyImpl
public final class SelectionKeyImpl
extends AbstractSelectionKey
{
@ -54,12 +54,14 @@ public class SelectionKeyImpl
selector = sel;
}
@Override
public SelectableChannel channel() {
return (SelectableChannel)channel;
}
@Override
public Selector selector() {
return selector;
return (Selector)selector;
}
int getIndex() { // package-private
@ -75,16 +77,19 @@ public class SelectionKeyImpl
throw new CancelledKeyException();
}
@Override
public int interestOps() {
ensureValid();
return interestOps;
}
@Override
public SelectionKey interestOps(int ops) {
ensureValid();
return nioInterestOps(ops);
}
@Override
public int readyOps() {
ensureValid();
return readyOps;
@ -131,4 +136,6 @@ public class SelectionKeyImpl
return sb.toString();
}
// used by Selector implementations to record when the key was selected
int lastPolled;
}

View file

@ -78,6 +78,16 @@ public abstract class SelectorImpl
return publicSelectedKeys;
}
/**
* Returns the public view of the key sets
*/
protected final Set<SelectionKey> nioKeys() {
return publicKeys;
}
protected final Set<SelectionKey> nioSelectedKeys() {
return publicSelectedKeys;
}
protected abstract int doSelect(long timeout) throws IOException;
private int lockAndDoSelect(long timeout) throws IOException {
@ -125,8 +135,6 @@ public abstract class SelectorImpl
protected abstract void implClose() throws IOException;
public abstract void putEventOps(SelectionKeyImpl sk, int ops);
@Override
protected final SelectionKey register(AbstractSelectableChannel ch,
int ops,
@ -166,4 +174,9 @@ public abstract class SelectorImpl
}
}
}
/**
* Invoked to change the key's interest set
*/
public abstract void putEventOps(SelectionKeyImpl ski, int ops);
}

View file

@ -210,25 +210,20 @@ class ServerSocketChannelImpl
@Override
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
acceptLock.lock();
try {
synchronized (stateLock) {
ensureOpen();
if (localAddress != null)
throw new AlreadyBoundException();
InetSocketAddress isa = (local == null)
? new InetSocketAddress(0)
: Net.checkAddress(local);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());
Net.listen(fd, backlog < 1 ? 50 : backlog);
localAddress = Net.localAddress(fd);
}
} finally {
acceptLock.unlock();
synchronized (stateLock) {
ensureOpen();
if (localAddress != null)
throw new AlreadyBoundException();
InetSocketAddress isa = (local == null)
? new InetSocketAddress(0)
: Net.checkAddress(local);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());
Net.listen(fd, backlog < 1 ? 50 : backlog);
localAddress = Net.localAddress(fd);
}
return this;
}