Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

When sending, don't retry forever in ERROR_RECOVERY_LINK mode #40

Open
wants to merge 1 commit into from

2 participants

@karlp

This is more inline with receiving, which only closes and reopens the link once. Sending
should still retry, but just not forever. Currently hardcoded to 3 times.

This "fixes" issue #39

However, I'm not 100% convinced that this is the best path for everybody? Should the amount be configurable? with the default of 0 being the same as now (forever?)

@karlp karlp When sending, don't retry forever in ERROR_RECOVERY_LINK mode
This is more inline with receiving, which only closes and reopens the link once.  Sending
should still retry, but just not forever.  Currently hardcoded to 3 times.
88cd2da
@stephane
Owner

Karl, sorry to reply so late.

The idea behind this error recovery mode is to recover at all means so yes, the default must be forever (and we mustn't change this behavior on library update).

It's not as convenient as with your patch but it's also possible to control how many times your want to retry by catching the errors (user side).

Could you change the default behavior to forever and I'll merge your patch it?

@karlp

I can, but I can't promise it will be anytime soon, sorry :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2011
  1. @karlp

    When sending, don't retry forever in ERROR_RECOVERY_LINK mode

    karlp authored
    This is more inline with receiving, which only closes and reopens the link once.  Sending
    should still retry, but just not forever.  Currently hardcoded to 3 times.
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 1 deletion.
  1. +7 −1 src/modbus.c
  2. +2 −0  src/modbus.h
View
8 src/modbus.c
@@ -165,6 +165,7 @@ static int send_msg(modbus_t *ctx, uint8_t *msg, int msg_length)
{
int rc;
int i;
+ int send_attempts = 0;
msg_length = ctx->backend->send_msg_pre(msg, msg_length);
@@ -193,12 +194,17 @@ static int send_msg(modbus_t *ctx, uint8_t *msg, int msg_length)
}
}
} while ((ctx->error_recovery & MODBUS_ERROR_RECOVERY_LINK) &&
- rc == -1);
+ rc == -1 &&
+ send_attempts++ < MODBUS_MAX_SEND_RETRIES);
if (rc > 0 && rc != msg_length) {
errno = EMBBADDATA;
return -1;
}
+ if (send_attempts >= MODBUS_MAX_SEND_RETRIES) {
+ errno = EMBXSFAIL;
+ return -1;
+ }
return rc;
}
View
2  src/modbus.h
@@ -81,6 +81,8 @@ MODBUS_BEGIN_DECLS
#define MODBUS_MAX_WRITE_REGISTERS 123
#define MODBUS_MAX_RW_WRITE_REGISTERS 121
+#define MODBUS_MAX_SEND_RETRIES 3
+
/* Random number to avoid errno conflicts */
#define MODBUS_ENOBASE 112345678
Something went wrong with that request. Please try again.