mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
avoid crashes due to calling select or wakeup on a closed Selector
This commit is contained in:
parent
807f2a8d51
commit
b45528203d
13
classpath/java/nio/channels/ClosedSelectorException.java
Normal file
13
classpath/java/nio/channels/ClosedSelectorException.java
Normal file
@ -0,0 +1,13 @@
|
||||
/* Copyright (c) 2012, Avian Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software
|
||||
for any purpose with or without fee is hereby granted, provided
|
||||
that the above copyright notice and this permission notice appear
|
||||
in all copies.
|
||||
|
||||
There is NO WARRANTY for this software. See license.txt for
|
||||
details. */
|
||||
|
||||
package java.nio.channels;
|
||||
|
||||
public class ClosedSelectorException extends IllegalStateException { }
|
@ -15,7 +15,7 @@ import java.util.Iterator;
|
||||
import java.net.Socket;
|
||||
|
||||
class SocketSelector extends Selector {
|
||||
protected long state;
|
||||
protected volatile long state;
|
||||
protected final Object lock = new Object();
|
||||
protected boolean woken = false;
|
||||
|
||||
@ -31,7 +31,7 @@ class SocketSelector extends Selector {
|
||||
|
||||
public Selector wakeup() {
|
||||
synchronized (lock) {
|
||||
if (! woken) {
|
||||
if (isOpen() && (! woken)) {
|
||||
woken = true;
|
||||
|
||||
natWakeup(state);
|
||||
@ -66,6 +66,10 @@ class SocketSelector extends Selector {
|
||||
}
|
||||
|
||||
public int doSelect(long interval) throws IOException {
|
||||
if (! isOpen()) {
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
|
||||
selectedKeys.clear();
|
||||
|
||||
if (clearWoken()) interval = -1;
|
||||
@ -107,9 +111,11 @@ class SocketSelector extends Selector {
|
||||
}
|
||||
|
||||
public synchronized void close() {
|
||||
if (isOpen()) {
|
||||
natClose(state);
|
||||
state = 0;
|
||||
synchronized (lock) {
|
||||
if (isOpen()) {
|
||||
natClose(state);
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user