diff options
author | Koushik Dutta <koushd@gmail.com> | 2014-09-10 14:44:45 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2014-09-10 14:46:39 -0700 |
commit | 681789004dab5cf5460c31b064edd2d6a510817e (patch) | |
tree | cef5eb725f74ce7ad503d0009b1adf00ea7b839b | |
parent | 0b99866b2b74a37a419183e1ff4b1c59974cfa8d (diff) | |
download | AndroidAsync-681789004dab5cf5460c31b064edd2d6a510817e.tar.gz AndroidAsync-681789004dab5cf5460c31b064edd2d6a510817e.tar.bz2 AndroidAsync-681789004dab5cf5460c31b064edd2d6a510817e.zip |
AsyncServer: Catch all selector exceptions.
Various firmwares seem to throw all sorts of insane exceptions.
Conflicts:
AndroidAsync/src/com/koushikdutta/async/AsyncServer.java
-rw-r--r-- | AndroidAsync/src/com/koushikdutta/async/AsyncServer.java | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java b/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java index be4a363..251132a 100644 --- a/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java +++ b/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java @@ -20,7 +20,6 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedChannelException; -import java.nio.channels.ClosedSelectorException; import java.nio.channels.DatagramChannel; import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; @@ -586,7 +585,9 @@ public class AsyncServer { try { runLoop(this, selector, queue); } - catch (ClosedSelectorException e) { + catch (AsyncSelectorException e) { + Log.e(LOGTAG, "Selector exception", e); + StreamUtility.closeQuietly(selector.getSelector()); } return; } @@ -607,10 +608,8 @@ public class AsyncServer { try { runLoop(server, selector, queue); } - catch (ClosedSelectorException e) { - StreamUtility.closeQuietly(selector.getSelector()); - } catch (AsyncSelectorException e) { + Log.e(LOGTAG, "Selector exception", e); StreamUtility.closeQuietly(selector.getSelector()); } // see if we keep looping, this must be in a synchronized block since the queue is accessed. @@ -690,7 +689,7 @@ public class AsyncServer { return wait; } - private static class AsyncSelectorException extends RuntimeException { + private static class AsyncSelectorException extends IOException { public AsyncSelectorException(Exception e) { super(e); } @@ -731,10 +730,7 @@ public class AsyncServer { } } } - catch (NullPointerException e) { - throw new AsyncSelectorException(e); - } - catch (IOException e) { + catch (Exception e) { throw new AsyncSelectorException(e); } |