Skip to content

Commit 6817890

Browse files
committed
AsyncServer: Catch all selector exceptions.
Various firmwares seem to throw all sorts of insane exceptions. Conflicts: AndroidAsync/src/com/koushikdutta/async/AsyncServer.java
1 parent 0b99866 commit 6817890

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

AndroidAsync/src/com/koushikdutta/async/AsyncServer.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.net.SocketAddress;
2121
import java.nio.channels.CancelledKeyException;
2222
import java.nio.channels.ClosedChannelException;
23-
import java.nio.channels.ClosedSelectorException;
2423
import java.nio.channels.DatagramChannel;
2524
import java.nio.channels.SelectionKey;
2625
import java.nio.channels.ServerSocketChannel;
@@ -586,7 +585,9 @@ public void run() {
586585
try {
587586
runLoop(this, selector, queue);
588587
}
589-
catch (ClosedSelectorException e) {
588+
catch (AsyncSelectorException e) {
589+
Log.e(LOGTAG, "Selector exception", e);
590+
StreamUtility.closeQuietly(selector.getSelector());
590591
}
591592
return;
592593
}
@@ -607,10 +608,8 @@ private static void run(final AsyncServer server, final SelectorWrapper selector
607608
try {
608609
runLoop(server, selector, queue);
609610
}
610-
catch (ClosedSelectorException e) {
611-
StreamUtility.closeQuietly(selector.getSelector());
612-
}
613611
catch (AsyncSelectorException e) {
612+
Log.e(LOGTAG, "Selector exception", e);
614613
StreamUtility.closeQuietly(selector.getSelector());
615614
}
616615
// see if we keep looping, this must be in a synchronized block since the queue is accessed.
@@ -690,7 +689,7 @@ private static long lockAndRunQueue(final AsyncServer server, final PriorityQueu
690689
return wait;
691690
}
692691

693-
private static class AsyncSelectorException extends RuntimeException {
692+
private static class AsyncSelectorException extends IOException {
694693
public AsyncSelectorException(Exception e) {
695694
super(e);
696695
}
@@ -731,10 +730,7 @@ private static void runLoop(final AsyncServer server, final SelectorWrapper sele
731730
}
732731
}
733732
}
734-
catch (NullPointerException e) {
735-
throw new AsyncSelectorException(e);
736-
}
737-
catch (IOException e) {
733+
catch (Exception e) {
738734
throw new AsyncSelectorException(e);
739735
}
740736

0 commit comments

Comments
 (0)