diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/ganarchy/friendcode/client/I2PSamPinger.java | 8 | ||||
-rw-r--r-- | src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java | 6 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/ganarchy/friendcode/client/I2PSamPinger.java b/src/main/java/ganarchy/friendcode/client/I2PSamPinger.java index 96448db..0476c61 100644 --- a/src/main/java/ganarchy/friendcode/client/I2PSamPinger.java +++ b/src/main/java/ganarchy/friendcode/client/I2PSamPinger.java @@ -12,7 +12,6 @@ public class I2PSamPinger extends LanServerPinger implements LanSendPing { private I2PSamStreamForwarder stream; private final String port; private volatile Status status = Status.IDLE; - private boolean hasWarned; private volatile boolean stopSam; public I2PSamPinger(String motd, String port) throws IOException { @@ -62,6 +61,9 @@ public class I2PSamPinger extends LanServerPinger implements LanSendPing { @Override public void friendcodeSendPing() { + if (this.status != Status.RUNNING) { + return; + } if (this.stopSam) { if (this.stream != null) { try { @@ -74,7 +76,6 @@ public class I2PSamPinger extends LanServerPinger implements LanSendPing { } catch (IOException ignored) { } this.status = Status.CONNECTION_CLOSED; - this.hasWarned = true; return; } if (this.sam.sendPing() < 0) { @@ -85,8 +86,7 @@ public class I2PSamPinger extends LanServerPinger implements LanSendPing { this.status = Status.CONNECTION_CLOSED; } } - if (this.status == Status.CONNECTION_CLOSED && !this.hasWarned) { - this.hasWarned = true; + if (this.status == Status.CONNECTION_CLOSED) { FriendCode.LOGGER.warn("Friend Code connection closed!"); } } diff --git a/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java b/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java index d05717d..1c55bc6 100644 --- a/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java +++ b/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java @@ -41,10 +41,10 @@ public abstract class I2PSamStateMachine implements Closeable { public abstract boolean connect(); protected boolean connect(Socket samSocket) { - this.samSocket = samSocket; if (this.connected) { throw new IllegalStateException(); } + this.samSocket = samSocket; this.connected = true; return true; } @@ -207,7 +207,9 @@ public abstract class I2PSamStateMachine implements Closeable { * @throws IOException As per {@link Socket#close()}. */ public void close() throws IOException { - this.samSocket.close(); + if (this.connected) { + this.samSocket.close(); + } } protected Socket unwrap() { |