Skip to content

Commit

Permalink
close context when last connection is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZDmitry committed Jan 16, 2017
1 parent 49d53d9 commit 231b19e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions android/src/main/java/org/zeromq/rnzeromq/ReactNativeZeroMQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ void _destroy() {
it.remove();
}

if (_context != null) {
_context.term();
_context = null;
}
_closeContext(true);
}

@Override
Expand Down Expand Up @@ -104,7 +101,21 @@ private Boolean _delObject(final String uuid) {
return false;
}

private Boolean _closeContext(Boolean forced) {
if (_storage.size() == 0 || forced) {
if (_context != null) {
_context.term();
_context = null;
}
return true;
}
return false;
}

private ZMQ.Socket _socket(final Integer socType) {
if (_context == null) {
_context = ZMQ.context(1);
}
return _context.socket(socType);
}

Expand Down Expand Up @@ -168,6 +179,7 @@ Object run() throws Exception {
socket.close();

ReactNativeZeroMQ.this._delObject(uuid);
ReactNativeZeroMQ.this._closeContext(false);
return this._successResult(true);
}
}).start();
Expand Down

0 comments on commit 231b19e

Please sign in to comment.