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 <eb@ilities.com>
This commit is contained in:
Erik Boasson 2020-03-10 15:50:22 +01:00 committed by eboasson
parent 4df38f5bf9
commit 0b9ab17018

View file

@ -2051,8 +2051,15 @@ int main (int argc, char *argv[])
has convenience functions for that ...) */ has convenience functions for that ...) */
if ((rd_participants = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL)) < 0) 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); error2 ("dds_create_reader(participants) failed: %d\n", (int) rd_participants);
/* set listener later: DATA_AVAILABLE still has the nasty habit of potentially triggering if ((rd_subscriptions = dds_create_reader (dp, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, NULL, NULL)) < 0)
before the reader is accessible to the application via its handle */ 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); listener = dds_create_listener (NULL);
dds_lset_data_available (listener, participant_data_listener); dds_lset_data_available (listener, participant_data_listener);
dds_set_listener (rd_participants, 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 /* then there is the matter of data arriving prior to setting the listener ... this state
of affairs is undoubtedly a bug */ of affairs is undoubtedly a bug */
participant_data_listener (rd_participants, NULL); 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 */ /* stats writer always exists, reader only when we were requested to collect & print stats */
qos = dds_create_qos (); qos = dds_create_qos ();