diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-23 11:59:15 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-23 11:59:15 -0500 |
| commit | 171c58d8ffb29c08ce55d789f0cc1b593c7f5e86 (patch) | |
| tree | 08d8104ac58b10856b43436762efa4accea16ed2 | |
| parent | 937751bb700c215680596e3629b4aacd1c4b2022 (diff) | |
| download | soen423-171c58d8ffb29c08ce55d789f0cc1b593c7f5e86.zip | |
runicast.Retransmit: catch ClosedChannelException before IOException
| -rw-r--r-- | src/main/java/derms/net/runicast/Retransmit.java | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/main/java/derms/net/runicast/Retransmit.java b/src/main/java/derms/net/runicast/Retransmit.java index 16f8859..6b8fb74 100644 --- a/src/main/java/derms/net/runicast/Retransmit.java +++ b/src/main/java/derms/net/runicast/Retransmit.java @@ -15,7 +15,7 @@ import java.util.logging.Logger; /** Retransmit unacknowledged messages. */ class Retransmit<T extends MessagePayload> implements Runnable { - private static final Duration timeout = Duration.ofMillis(500); + private static final Duration period = Duration.ofMillis(500); private final AtomicLong unacked; private final Queue<Message<T>> sent; @@ -31,28 +31,27 @@ class Retransmit<T extends MessagePayload> implements Runnable { @Override public void run() { - try { - for (;;) { - Wait.forDuration(timeout); + for (;;) { + try { + Wait.forDuration(period); for (Message<T> msg : sent) { if (msg.seq >= unacked.get()) { retransmit(msg); } } + } catch (InterruptedException | ClosedChannelException e) { + log.info("Shutting down."); + return; + } catch (IOException e) { + log.warning(e.getMessage()); } - } catch (InterruptedException | ClosedChannelException e) { - log.info("Shutting down."); } } - private void retransmit(Message<T> msg) throws ClosedChannelException { - try { - ByteBuffer buf = Serial.encode(msg); - sock.send(buf, sock.getRemoteAddress()); - log.info("Retransmitted " + msg); - } catch (IOException e) { - log.warning("Failed to retransmit " + msg + ": " + e.getMessage()); - } + private void retransmit(Message<T> msg) throws IOException { + ByteBuffer buf = Serial.encode(msg); + sock.send(buf, sock.getRemoteAddress()); + log.info("Retransmitted " + msg); } } |