From b6c80f2e6a544e5de6785d0615902316e46fa330 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Wed, 10 Mar 2021 16:14:30 +0100 Subject: [PATCH] Postpone reader detection to the write call and skip writing if there is no reader yet. --- simgear/io/SGDataDistributionService.cxx | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/simgear/io/SGDataDistributionService.cxx b/simgear/io/SGDataDistributionService.cxx index 00ae89e9..69b2f256 100644 --- a/simgear/io/SGDataDistributionService.cxx +++ b/simgear/io/SGDataDistributionService.cxx @@ -116,19 +116,6 @@ SG_DDS::open( SGProtocolDir direction ) << dds_strretcode(-rc)); return false; } - - uint32_t status = 0; - while(!(status & DDS_PUBLICATION_MATCHED_STATUS)) - { - rc = dds_get_status_changes(writer, &status); - if (rc != DDS_RETCODE_OK) { - SG_LOG(SG_IO, SG_ALERT, "dds_get_status_changes: " - << dds_strretcode(-rc)); - } - - /* Polling sleep. */ - dds_sleepfor(DDS_MSECS(20)); - } } return true; @@ -170,6 +157,19 @@ SG_DDS::write( const char *buf, const int length ) return 0; } + dds_return_t rc; + uint32_t status = 0; + rc = dds_get_status_changes(writer, &status); + if (rc != DDS_RETCODE_OK) { + SG_LOG(SG_IO, SG_ALERT, "dds_get_status_changes: " + << dds_strretcode(-rc)); + return 0; + } + if (!(status & DDS_PUBLICATION_MATCHED_STATUS)) { + SG_LOG(SG_IO, SG_INFO, "DDS skipping write: no readers."); + return length; // no readers yet. + } + result = dds_write(writer, buf); if(result != DDS_RETCODE_OK) {