Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
[INSTORE-467] Exiting listen loop when listener is interrupted (#5)
Browse files Browse the repository at this point in the history
* trying close of listener before closing socket

* checking interrupt status and exiting

* exiting when interrupted without communicating an error
  • Loading branch information
gareth-ivatt-fivestars authored and darran-kelinske-fivestars committed Nov 8, 2019
1 parent 9205e4a commit d7c215b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/android/DatagramSocketListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public void run() {
Log.d(Dgram.TAG, "Received message " + message + " from " + address + " and port " + port);
emitMessageResult(message, address, port);
} catch (Exception e) {
if (this.isInterrupted()) {
Log.d(Dgram.TAG, "Exiting message loop because listener was interrupted.");
return;
}
Log.e(Dgram.TAG, "Exception in listener:" + e.toString());
emitMessageErrorResult(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/android/Dgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ private void startListening(

private void closeSocket() {
try {
this.closeListener();

if (this.datagramSocket != null) {
if (!this.datagramSocket.isClosed()) {
this.datagramSocket.close();
}

this.datagramSocket = null;
this.closeListener();
}
} catch (Exception e) {
Log.e(TAG, "Attempting to close socket failed: " + e.toString(), e);
Expand Down

0 comments on commit d7c215b

Please sign in to comment.