mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +01:00
PeerGroup: Closing streams and sockets where necessary
This commit is contained in:
parent
6692c0e06b
commit
3ab1d5811d
1 changed files with 10 additions and 6 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue