From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 28 Feb 2022 06:58:15 +0000 (+1100) Subject: Wait for two seconds for the NQPTP service to appear. X-Git-Tag: 4.1-rc1~24^2~274 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8fec7fa704950c10ddf5178a7941953ec508d7f;p=thirdparty%2Fshairport-sync.git Wait for two seconds for the NQPTP service to appear. --- diff --git a/shairport.c b/shairport.c index 3dcdcff5..dc8b5408 100644 --- a/shairport.c +++ b/shairport.c @@ -2211,13 +2211,23 @@ int main(int argc, char **argv) { #endif #ifdef CONFIG_AIRPLAY_2 - ptp_shm_interface_init(); - ptp_send_control_message_string("T"); // incidentally create the named SHM and remove all previous history - usleep(1000000); // wait for it to get done (?) - if (ptp_shm_interface_open() == 0) { - debug(1,"shm interface opened successfully!"); + ptp_send_control_message_string("T"); // get nqptp to create the named shm interface + int ptp_check_times = 0; + const int ptp_wait_interval_us = 5000; + // wait for up to two seconds for NQPTP to come online + do { + ptp_send_control_message_string("T"); // get nqptp to create the named shm interface + usleep(ptp_wait_interval_us); + ptp_check_times++; + } while ((ptp_shm_interface_open() != 0) && (ptp_check_times < (2000000 / ptp_wait_interval_us))); + + if (ptp_shm_interface_open() != 0) { + die("Can't access NQPTP! Is it installed and running?"); } else { - warn("Unable to open the shm interface at startup!"); + if (ptp_check_times == 1) + debug(1,"NQPTP is online."); + else + debug(1,"NQPTP is online after %u microseconds.",ptp_check_times * ptp_wait_interval_us); } #endif