From 0b9ab170184d32a21825493dc45df1422a142340 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Tue, 10 Mar 2020 15:50:22 +0100 Subject: [PATCH] Do not set DCPSParticipant listener too early The participant listener creates a pong writer, setting a publication matched listener on it. That listener can be invoked immediately and as it queries the subscriptions reader, it must not be enabled before the latter reader has been created. Signed-off-by: Erik Boasson --- src/tools/ddsperf/ddsperf.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tools/ddsperf/ddsperf.c b/src/tools/ddsperf/ddsperf.c index bed06bd..b6f248e 100644 --- a/src/tools/ddsperf/ddsperf.c +++ b/src/tools/ddsperf/ddsperf.c @@ -2051,8 +2051,15 @@ int main (int argc, char *argv[]) has convenience functions for that ...) */ if ((rd_participants = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL)) < 0) error2 ("dds_create_reader(participants) failed: %d\n", (int) rd_participants); - /* set listener later: DATA_AVAILABLE still has the nasty habit of potentially triggering - before the reader is accessible to the application via its handle */ + if ((rd_subscriptions = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL)) < 0) + error2 ("dds_create_reader(subscriptions) failed: %d\n", (int) rd_subscriptions); + if ((rd_publications = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, NULL, NULL)) < 0) + error2 ("dds_create_reader(publications) failed: %d\n", (int) rd_publications); + + /* Set DATA_AVAILABLE listener on participant later: it has the nasty habit of potentially + triggering before the reader is accessible to the application via its handle. Furthermore, + upon matching a participant, a new writer is created that gets a publication_matched + listener, which in turn depends on rd_subscriptions. */ listener = dds_create_listener (NULL); dds_lset_data_available (listener, participant_data_listener); dds_set_listener (rd_participants, listener); @@ -2060,10 +2067,6 @@ int main (int argc, char *argv[]) /* then there is the matter of data arriving prior to setting the listener ... this state of affairs is undoubtedly a bug */ participant_data_listener (rd_participants, NULL); - if ((rd_subscriptions = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL)) < 0) - error2 ("dds_create_reader(subscriptions) failed: %d\n", (int) rd_subscriptions); - if ((rd_publications = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, NULL, NULL)) < 0) - error2 ("dds_create_reader(publications) failed: %d\n", (int) rd_publications); /* stats writer always exists, reader only when we were requested to collect & print stats */ qos = dds_create_qos ();