Skip to content

Commit

Permalink
Add permanent subscription option
Browse files Browse the repository at this point in the history
This patch enhances the subscription expiration logic in the clock module
by extending the functionality for subscriptions with a duration of UINT16_MAX.
With this update, a UINT16_MAX duration now enables a permanent subscription,
ensuring such subscriptions are not prematurely removed and can persist
indefinitely.

Signed-off-by: Christopher S Hall <christopher.s.hall@intel.com>
Signed-off-by: Noor Azura Ahmad Tarmizi <noor.azura.ahmad.tarmizi@intel.com>
Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com>
Signed-off-by: Lai Peter Jun Ann <peter.jun.ann.lai@intel.com>
  • Loading branch information
christopher-s-hall authored and richardcochran committed Sep 1, 2024
1 parent 8157559 commit 7c2b446
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ static void clock_update_subscription(struct clock *c, struct ptp_message *req,
s->addr = req->address;
memcpy(s->events, bitmask, EVENT_BITMASK_CNT);
clock_gettime(CLOCK_MONOTONIC, &now);
s->expiration = now.tv_sec + duration;
/* Subscription will not expire if the duration is set to UINT16_MAX. */
s->expiration = duration != UINT16_MAX ? now.tv_sec + duration : 0;
} else {
remove_subscriber(s);
}
Expand All @@ -267,7 +268,8 @@ static void clock_update_subscription(struct clock *c, struct ptp_message *req,
s->addr = req->address;
memcpy(s->events, bitmask, EVENT_BITMASK_CNT);
clock_gettime(CLOCK_MONOTONIC, &now);
s->expiration = now.tv_sec + duration;
/* Subscription will not expire if the duration is set to UINT16_MAX. */
s->expiration = duration != UINT16_MAX ? now.tv_sec + duration : 0;
s->sequenceId = 0;
LIST_INSERT_HEAD(&c->subscribers, s, list);
}
Expand Down Expand Up @@ -311,7 +313,7 @@ static void clock_prune_subscriptions(struct clock *c)

clock_gettime(CLOCK_MONOTONIC, &now);
LIST_FOREACH_SAFE(s, &c->subscribers, list, tmp) {
if (s->expiration <= now.tv_sec) {
if (s->expiration != 0 && s->expiration <= now.tv_sec) {
pr_info("subscriber %s timed out",
pid2str(&s->targetPortIdentity));
remove_subscriber(s);
Expand Down

0 comments on commit 7c2b446

Please sign in to comment.