Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/org/openlcb/implementations/MemoryConfigurationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,14 @@ public void run() {
retryTimer.schedule(tt, timeout);
}

static int computeTimeout(int flags) {
int timeoutExp = flags & 0x0F;
if (timeoutExp == 0) {
return 3000; // no timeout specified, 3 seconds is default
}
return (1 << timeoutExp) * 1000; // 2^N seconds to msec
}

// invoked when retryTimer times out
private void timeoutRetry(final McsRequestMemo memo) {
logger.log(Level.FINE, "timeoutRetry entry");
Expand Down Expand Up @@ -556,8 +564,7 @@ public void handleSuccess(int flags) {
((flags & DatagramService.FLAG_REPLY_PENDING) != 0)) {
// Leave the memo in the pending, will wait for reply datagram.
logger.fine("rcvd RequestWithReplyDatagram with flags "+flags);
int timeout = 1 << (flags & 0x0F) * 1000; // to msec
if ((flags & 0x0F) == 0) timeout = 3000; // no timeout specified, 3 seconds is default
int timeout = computeTimeout(flags);
logger.fine(" and timeout "+timeout+", restarting");
restartTimeout(memo, timeout);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,20 @@ public void handleAddrSpaceData(NodeID dest, int space, long hiAddress, long low

}

@Test
public void testComputeTimeout() {
// Exponent 0: default 3000 ms
Assert.assertEquals(3000, MemoryConfigurationService.computeTimeout(0));
Assert.assertEquals(3000, MemoryConfigurationService.computeTimeout(DatagramService.FLAG_REPLY_PENDING | 0));

// Exponents 1..4: 2^N seconds in milliseconds
Assert.assertEquals(2000, MemoryConfigurationService.computeTimeout(DatagramService.FLAG_REPLY_PENDING | 1));
Assert.assertEquals(4000, MemoryConfigurationService.computeTimeout(DatagramService.FLAG_REPLY_PENDING | 2));
Assert.assertEquals(8000, MemoryConfigurationService.computeTimeout(DatagramService.FLAG_REPLY_PENDING | 3));
Assert.assertEquals(16000, MemoryConfigurationService.computeTimeout(DatagramService.FLAG_REPLY_PENDING | 4));

// Max exponent 15: 2^15 seconds in milliseconds
Assert.assertEquals(32768000, MemoryConfigurationService.computeTimeout(DatagramService.FLAG_REPLY_PENDING | 15));
}

}
Loading