mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 13:37:24 +00:00
PeerGroup: Closing streams and sockets where necessary
This commit is contained in:
committed by
Andreas Schildbach
parent
8a7aa1ef0d
commit
2969be2ad7
@@ -849,19 +849,23 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
checkState(lock.isHeldByCurrentThread());
|
checkState(lock.isHeldByCurrentThread());
|
||||||
if (localhostCheckState == LocalhostCheckState.NOT_TRIED) {
|
if (localhostCheckState == LocalhostCheckState.NOT_TRIED) {
|
||||||
// Do a fast blocking connect to see if anything is listening.
|
// Do a fast blocking connect to see if anything is listening.
|
||||||
|
Socket socket = null;
|
||||||
try {
|
try {
|
||||||
Socket socket = new Socket();
|
socket = new Socket();
|
||||||
socket.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), params.getPort()), vConnectTimeoutMillis);
|
socket.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), params.getPort()), vConnectTimeoutMillis);
|
||||||
localhostCheckState = LocalhostCheckState.FOUND;
|
localhostCheckState = LocalhostCheckState.FOUND;
|
||||||
try {
|
|
||||||
socket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignore.
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.info("Localhost peer not detected.");
|
log.info("Localhost peer not detected.");
|
||||||
localhostCheckState = LocalhostCheckState.NOT_THERE;
|
localhostCheckState = LocalhostCheckState.NOT_THERE;
|
||||||
|
} finally {
|
||||||
|
if (socket != null) {
|
||||||
|
try {
|
||||||
|
socket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Ignore.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user