diff --git a/config.c b/config.c index b75ade3..9d6000c 100644 --- a/config.c +++ b/config.c @@ -79,6 +79,11 @@ static void scan_line(char *s, struct config *cfg) } else if (1 == sscanf(s, " announceReceiptTimeout %hhu", &u8)) { pod->announceReceiptTimeout = u8; + + } else if (1 == sscanf(s, " tx_timestamp_retries %u", &val)) { + + if (val > 0) + *cfg->tx_timestamp_retries = val; } } diff --git a/config.h b/config.h index dd05d7d..923c324 100644 --- a/config.h +++ b/config.h @@ -25,6 +25,7 @@ struct config { struct defaultDS *dds; struct port_defaults *pod; + int *tx_timestamp_retries; }; int config_read(char *name, struct config *cfg); diff --git a/default.cfg b/default.cfg index a2f86e9..bc6748d 100644 --- a/default.cfg +++ b/default.cfg @@ -16,3 +16,7 @@ logAnnounceInterval 1 logSyncInterval 0 logMinDelayReqInterval 0 announceReceiptTimeout 3 +# +# Run time options +# +tx_timestamp_retries 2 diff --git a/ptp4l.c b/ptp4l.c index e461935..7ec8b6e 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -29,6 +29,8 @@ #define DEFAULT_PHC "/dev/ptp0" +int sk_tx_retries = 2; /*see sk.c*/ + static int running = 1; static struct defaultDS ds; static struct port_defaults pod; @@ -178,6 +180,7 @@ int main(int argc, char *argv[]) cfg_settings.dds = &ds; cfg_settings.pod = &pod; + cfg_settings.tx_timestamp_retries = &sk_tx_retries; if (config && config_read(config, &cfg_settings)) { fprintf(stderr, "failed to read configuration file\n"); diff --git a/sk.c b/sk.c index 7dfe968..810d036 100644 --- a/sk.c +++ b/sk.c @@ -126,7 +126,7 @@ int sk_receive(int fd, void *buf, int buflen, msg.msg_control = control; msg.msg_controllen = sizeof(control); - try_again = flags == MSG_ERRQUEUE ? 2 : 1; + try_again = flags == MSG_ERRQUEUE ? sk_tx_retries : 1; for ( ; try_again; try_again--) { cnt = recvmsg(fd, &msg, flags); diff --git a/sk.h b/sk.h index cfe49fd..78f1085 100644 --- a/sk.h +++ b/sk.h @@ -60,4 +60,10 @@ int sk_receive(int fd, void *buf, int buflen, */ int sk_timestamping_init(int fd, char *device, enum timestamp_type type); +/** + * Limits the number of RECVMSG(2) calls when attempting to obtain a + * transmit time stamp on an event message. + */ +extern int sk_tx_retries; + #endif