From c1e737bbe45bab94c69dbd4fe206c2acd40e7bc0 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Tue, 26 Aug 2025 10:40:13 +0200 Subject: [PATCH] module-rtp: Attempt to reconnect the ptp management socket This should gracefully recover the cases where the other end of the socket isn't ready yet when we start or terminates and gets restarted. --- src/modules/module-rtp-sap.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index 22fe89b68..6ab0c8477 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -548,8 +548,13 @@ error: static bool update_ts_refclk(struct impl *impl) { - if (!impl->ptp_mgmt_socket || impl->ptp_fd < 0) + if (!impl->ptp_mgmt_socket) return false; + if (impl->ptp_fd < 0) { + impl->ptp_fd = make_unix_socket(impl->ptp_mgmt_socket); + if (impl->ptp_fd < 0) + return false; + } // Read if something is left in the socket int avail; @@ -581,6 +586,12 @@ static bool update_ts_refclk(struct impl *impl) if (write(impl->ptp_fd, &req, sizeof(req)) == -1) { pw_log_warn("Failed to send PTP management request: %m"); + if (errno != ENOTCONN) + return false; + close(impl->ptp_fd); + impl->ptp_fd = make_unix_socket(impl->ptp_mgmt_socket); + if (impl->ptp_fd > -1) + pw_log_info("Reopened PTP management socket"); return false; }