From ddd14033524fdc24d92b572cbad0836083da763a Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 18 Jan 2014 20:03:29 -0800 Subject: Catch cancelled key exceptions. Eat data on http client connect cancellation. Add keySet method for HashedList. Change-Id: I7a15d1e8ecdd58c3b853c7d51ea17574da7d7102 --- AndroidAsync/src/com/koushikdutta/async/AsyncServer.java | 5 ++++- AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java | 4 +++- AndroidAsync/src/com/koushikdutta/async/util/HashList.java | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java b/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java index cdfa8c9..6fb0336 100644 --- a/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java +++ b/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java @@ -18,6 +18,7 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; +import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedSelectorException; import java.nio.channels.DatagramChannel; @@ -576,7 +577,7 @@ public class AsyncServer { } catch (Exception e) { Log.e(LOGTAG, "exception?", e); - } + } return; } @@ -764,6 +765,8 @@ public class AsyncServer { assert false; } } + catch (CancelledKeyException ex) { + } catch (Exception ex) { Log.e(LOGTAG, "inner loop exception", ex); } diff --git a/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java b/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java index f18adf9..37a8372 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java @@ -93,8 +93,10 @@ public class AsyncHttpClient { if (!super.cancel()) return false; - if (socket != null) + if (socket != null) { + socket.setDataCallback(new NullDataCallback()); socket.close(); + } if (scheduled != null) mServer.removeAllCallbacks(scheduled); diff --git a/AndroidAsync/src/com/koushikdutta/async/util/HashList.java b/AndroidAsync/src/com/koushikdutta/async/util/HashList.java index 7ea19a8..9fd41b6 100644 --- a/AndroidAsync/src/com/koushikdutta/async/util/HashList.java +++ b/AndroidAsync/src/com/koushikdutta/async/util/HashList.java @@ -2,6 +2,7 @@ package com.koushikdutta.async.util; import java.util.ArrayList; import java.util.Hashtable; +import java.util.Set; /** * Created by koush on 5/27/13. @@ -15,6 +16,10 @@ public class HashList { public HashList() { } + public Set keySet() { + return internal.keySet(); + } + public synchronized V tag(String key) { TaggedList list = internal.get(key); if (list == null) -- cgit v1.2.3