3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 11:45:51 +00:00

PeerGroup: Closing streams and sockets where necessary

This commit is contained in:
Kirill Vlasov 2015-12-07 11:40:01 +05:00 committed by Andreas Schildbach
parent 6692c0e06b
commit 3ab1d5811d

View File

@ -933,19 +933,23 @@ public class PeerGroup implements TransactionBroadcaster {
checkState(lock.isHeldByCurrentThread());
if (localhostCheckState == LocalhostCheckState.NOT_TRIED) {
// Do a fast blocking connect to see if anything is listening.
Socket socket = null;
try {
Socket socket = new Socket();
socket = new Socket();
socket.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), params.getPort()), vConnectTimeoutMillis);
localhostCheckState = LocalhostCheckState.FOUND;
try {
socket.close();
} catch (IOException e) {
// Ignore.
}
return true;
} catch (IOException e) {
log.info("Localhost peer not detected.");
localhostCheckState = LocalhostCheckState.NOT_THERE;
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// Ignore.
}
}
}
}
return false;