Remove redundant defines (#20744)
Refactor time handling in mqtt_wss_client to use now_boottime_usec function
Stelios Fragkakis committed
Jul 31, 2025 at 15:33 UTC
2db8729ce556a9cc9b4da5449e1e15033fa5a0c2
1 file changed
+2
-20
src/aclk/mqtt_websockets/mqtt_wss_client.c
+2
-20
@@ -620,24 +620,6 @@ int mqtt_wss_connect(
620
return 0;
621
}
622
623
-#define NSEC_PER_USEC 1000ULL
624
-#define USEC_PER_SEC 1000000ULL
625
-#define NSEC_PER_MSEC 1000000ULL
626
-#define NSEC_PER_SEC 1000000000ULL
627
-
628
-static uint64_t boottime_usec(void) {
629
- struct timespec ts;
630
-#if defined(__APPLE__) || defined(__FreeBSD__)
631
- if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
632
-#else
633
- if (clock_gettime(CLOCK_BOOTTIME, &ts) == -1) {
634
-#endif
635
- nd_log(NDLS_DAEMON, NDLP_ERR, "clock_gettimte failed");
636
- return 0;
637
- }
638
- return (uint64_t)ts.tv_sec * USEC_PER_SEC + (ts.tv_nsec % NSEC_PER_SEC) / NSEC_PER_USEC;
639
-}
640
-
623
#define MWS_TIMED_OUT 1
624
#define MWS_ERROR 2
625
#define MWS_OK 0
@@ -656,10 +638,10 @@ static const char *mqtt_wss_error_tos(int ec)
638
639
static int mqtt_wss_service_all(mqtt_wss_client client, int timeout_ms)
640
{
659
- uint64_t exit_by_us = boottime_usec() + (timeout_ms * NSEC_PER_MSEC);
641
+ uint64_t exit_by_us = now_boottime_usec() + (timeout_ms * NSEC_PER_MSEC);
642
client->poll_fds[POLLFD_SOCKET].events |= POLLOUT; // TODO when entering mwtt_wss_service use out buffer size to arm POLLOUT
643
while (rbuf_bytes_available(client->ws_client->buf_write)) {
662
- const uint64_t now_us = boottime_usec();
644
+ const uint64_t now_us = now_boottime_usec();
645
if (now_us >= exit_by_us)
646
return MWS_TIMED_OUT;
647
if (mqtt_wss_service(client, (exit_by_us - now_us) / USEC_PER_SEC))