summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Ballard <peter.ballard@isode.com>2015-07-20 13:44:28 (GMT)
committerNick Hudson <nick.hudson@isode.com>2015-07-28 16:14:55 (GMT)
commite0c9b2b7b40743ec4f5f1dd5bc1eaf0e815ed72e (patch)
treebb763921849b66411cc6b26c9ef71d11ea8bd785 /src
parent251813ccca9404d8d4122b2848f9fec86a451bf5 (diff)
downloadstroke-e0c9b2b7b40743ec4f5f1dd5bc1eaf0e815ed72e.zip
stroke-e0c9b2b7b40743ec4f5f1dd5bc1eaf0e815ed72e.tar.bz2
Fixed CancelledKeyException in JavaConnection
If synchroniseReads was enabled then if was possible for CancelledKeyExceptions to occur if the channel closed, whilst data was being procsessed on the event loop. I have also made the selectorKey_ reference volatile as this is used by both threads since my previous change 1afab8c1f2c417b08371bc12569e03171851d785 Change-Id: I48edcab9ef090b8a4561331d6aecc7f95cb8924d
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/network/JavaConnection.java6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java
index 66f068f..db748e8 100644
--- a/src/com/isode/stroke/network/JavaConnection.java
+++ b/src/com/isode/stroke/network/JavaConnection.java
@@ -49,7 +49,7 @@ public class JavaConnection extends Connection implements EventOwner {
private final HostAddressPort address_;
private final List<byte[]> writeBuffer_ = Collections.synchronizedList(new ArrayList<byte[]>());
- private SelectionKey selectionKey_;
+ private volatile SelectionKey selectionKey_;
private boolean disconnected_ = false;
public Worker(HostAddressPort address) {
@@ -311,7 +311,9 @@ public class JavaConnection extends Connection implements EventOwner {
// https://code.google.com/p/android/issues/detail?id=80785
if (synchroniseReads_ && selector_ != null) {
synchronized (selectorLock_) {
- selectionKey_.interestOps(SelectionKey.OP_READ);
+ if (selectionKey_.isValid()) {
+ selectionKey_.interestOps(SelectionKey.OP_READ);
+ }
if (selector_.isOpen()) {
selector_.wakeup();
}