3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-19 13:45:48 +00:00

Fixes for r165 code review

This commit is contained in:
Miron Cuperman (devrandom) 2011-08-10 17:32:59 +00:00
parent 0c8638ae2e
commit 381cda1ff2

View File

@ -95,7 +95,7 @@ public class Peer {
* *
* @throws PeerException when there is a temporary problem with the peer and we should retry later * @throws PeerException when there is a temporary problem with the peer and we should retry later
*/ */
public void connect() throws PeerException { public synchronized void connect() throws PeerException {
try { try {
conn = new NetworkConnection(address, params, bestHeight, 60000); conn = new NetworkConnection(address, params, bestHeight, 60000);
} catch (IOException ex) { } catch (IOException ex) {
@ -136,11 +136,11 @@ public class Peer {
} }
} }
} catch (IOException e) { } catch (IOException e) {
disconnect();
if (!running) { if (!running) {
// This exception was expected because we are tearing down the socket as part of quitting. // This exception was expected because we are tearing down the socket as part of quitting.
log.info("Shutting down peer loop"); log.info("Shutting down peer loop");
} else { } else {
disconnect();
throw new PeerException(e); throw new PeerException(e);
} }
} catch (ProtocolException e) { } catch (ProtocolException e) {
@ -398,10 +398,8 @@ public class Peer {
/** /**
* Terminates the network connection and stops the message handling loop. * Terminates the network connection and stops the message handling loop.
*/ */
public void disconnect() { public synchronized void disconnect() {
synchronized (this) {
running = false; running = false;
}
try { try {
// This is the correct way to stop an IO bound loop // This is the correct way to stop an IO bound loop
if (conn != null) if (conn != null)