mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8336339: (se) SelectionKey.interestOps(int) should not throw ClosedSelectorException
Reviewed-by: jpai, bpb
This commit is contained in:
parent
22914e0774
commit
9f03f68755
8 changed files with 136 additions and 34 deletions
|
@ -26,7 +26,6 @@
|
|||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
@ -92,11 +91,6 @@ class EPollSelectorImpl extends SelectorImpl {
|
|||
EPoll.ctl(epfd, EPOLL_CTL_ADD, eventfd.efd(), EPOLLIN);
|
||||
}
|
||||
|
||||
private void ensureOpen() {
|
||||
if (!isOpen())
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doSelect(Consumer<SelectionKey> action, long timeout)
|
||||
throws IOException
|
||||
|
@ -243,7 +237,6 @@ class EPollSelectorImpl extends SelectorImpl {
|
|||
|
||||
@Override
|
||||
public void setEventOps(SelectionKeyImpl ski) {
|
||||
ensureOpen();
|
||||
synchronized (updateLock) {
|
||||
updateKeys.addLast(ski);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
@ -97,11 +96,6 @@ class KQueueSelectorImpl extends SelectorImpl {
|
|||
KQueue.register(kqfd, fd0, EVFILT_READ, EV_ADD);
|
||||
}
|
||||
|
||||
private void ensureOpen() {
|
||||
if (!isOpen())
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doSelect(Consumer<SelectionKey> action, long timeout)
|
||||
throws IOException
|
||||
|
@ -285,7 +279,6 @@ class KQueueSelectorImpl extends SelectorImpl {
|
|||
|
||||
@Override
|
||||
public void setEventOps(SelectionKeyImpl ski) {
|
||||
ensureOpen();
|
||||
synchronized (updateLock) {
|
||||
updateKeys.addLast(ski);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -137,6 +137,8 @@ public abstract class AbstractSelectableChannel
|
|||
|
||||
void removeKey(SelectionKey k) { // package-private
|
||||
synchronized (keyLock) {
|
||||
if (keys == null)
|
||||
return;
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
if (keys[i] == k) {
|
||||
keys[i] = null;
|
||||
|
@ -233,7 +235,7 @@ public abstract class AbstractSelectableChannel
|
|||
k.interestOps(ops);
|
||||
} else {
|
||||
// New registration
|
||||
k = ((AbstractSelector)sel).register(this, ops, att);
|
||||
k = ((AbstractSelector) sel).register(this, ops, att);
|
||||
addKey(k);
|
||||
}
|
||||
return k;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -188,11 +188,11 @@ public abstract class SelectorImpl
|
|||
// Deregister channels
|
||||
Iterator<SelectionKey> i = keys.iterator();
|
||||
while (i.hasNext()) {
|
||||
SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
|
||||
SelectionKeyImpl ski = (SelectionKeyImpl) i.next();
|
||||
deregister(ski);
|
||||
SelectableChannel selch = ski.channel();
|
||||
if (!selch.isOpen() && !selch.isRegistered())
|
||||
((SelChImpl)selch).kill();
|
||||
((SelChImpl) selch).kill();
|
||||
selectedKeys.remove(ski);
|
||||
i.remove();
|
||||
}
|
||||
|
@ -221,13 +221,14 @@ public abstract class SelectorImpl
|
|||
keys.add(k);
|
||||
try {
|
||||
k.interestOps(ops);
|
||||
} catch (ClosedSelectorException e) {
|
||||
} catch (CancelledKeyException e) {
|
||||
// key observed and cancelled. Okay to return a cancelled key.
|
||||
}
|
||||
if (!isOpen()) {
|
||||
assert ch.keyFor(this) == null;
|
||||
keys.remove(k);
|
||||
k.cancel();
|
||||
throw e;
|
||||
} catch (CancelledKeyException e) {
|
||||
// key observed and cancelled. Okay to return a cancelled key.
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
@ -277,7 +278,7 @@ public abstract class SelectorImpl
|
|||
|
||||
SelectableChannel ch = ski.channel();
|
||||
if (!ch.isOpen() && !ch.isRegistered())
|
||||
((SelChImpl)ch).kill();
|
||||
((SelChImpl) ch).kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -231,7 +231,6 @@ class PollSelectorImpl extends SelectorImpl {
|
|||
|
||||
@Override
|
||||
public void setEventOps(SelectionKeyImpl ski) {
|
||||
ensureOpen();
|
||||
synchronized (updateLock) {
|
||||
updateKeys.addLast(ski);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ package sun.nio.ch;
|
|||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.Pipe;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
|
@ -89,11 +88,6 @@ class WEPollSelectorImpl extends SelectorImpl {
|
|||
WEPoll.ctl(eph, EPOLL_CTL_ADD, fd0Val, WEPoll.EPOLLIN);
|
||||
}
|
||||
|
||||
private void ensureOpen() {
|
||||
if (!isOpen())
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doSelect(Consumer<SelectionKey> action, long timeout)
|
||||
throws IOException
|
||||
|
@ -228,7 +222,6 @@ class WEPollSelectorImpl extends SelectorImpl {
|
|||
|
||||
@Override
|
||||
public void setEventOps(SelectionKeyImpl ski) {
|
||||
ensureOpen();
|
||||
synchronized (updateLock) {
|
||||
updateKeys.addLast(ski);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -606,7 +606,6 @@ class WindowsSelectorImpl extends SelectorImpl {
|
|||
|
||||
@Override
|
||||
public void setEventOps(SelectionKeyImpl ski) {
|
||||
ensureOpen();
|
||||
synchronized (updateLock) {
|
||||
updateKeys.addLast(ski);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue