eclipse-cyclonedds / cyclonedds

Eclipse Cyclone DDS project
https://projects.eclipse.org/projects/iot.cyclonedds
Other
889 stars 363 forks source link

The dds_get_matched_subscription_data function be called in publication_matched listener, It can't get proxy reader's information #2073

Closed caojiebao closed 3 weeks ago

caojiebao commented 3 months ago

If proxy_reader created between local create_participant and local create_writer , local writer and proxy_reader will match and at the same time the callback function on_publication_matched will be called, but writer is still in pending sattus,
dds_get_matched_subscription_data will check this status. so it will get NULL.

Is this a bug which will to be fixed? How can i get remote reader guid in publication_matched callback?

void print_guid(dds_guid_t *guid)
{
    uint32_t i;

    if (guid == NULL)
        return ;
    printf("GUID = ");
    for (i = 0; i < 16; i++) 
    {
        printf("%02x", guid->v[i]);
    }
    //printf("\n");
    return;
}
static void on_publication_matched (dds_entity_t writer, const dds_publication_matched_status_t  status, void* arg)
{
  (void)arg;
  printf("---------writer is %d------on_publication_matched----status.current_count is %d status.current_count_change is %d status.total_count is %d status.total_count_change is %d --------\n", writer,status.total_count, status.total_count_change, status.current_count, status.current_count_change);
  dds_builtintopic_endpoint_t *sub = dds_get_matched_subscription_data(writer, status.last_subscription_handle);
  printf("--------i want to know who matched . and proxy reader is sub handle is -%p  guid is \n", sub);
  print_guid(&sub->key);
}
........

int main (int argc, char ** argv)
{
  participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
  if (participant < 0)
    DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant));
dds_sleepfor (DDS_SECS (5));
dds_lset_publication_matched(lis, on_publication_matched);
writer = dds_create_writer (participant, topic, NULL, lis);
........
}
caojiebao commented 3 months ago

@eboasson

eboasson commented 3 months ago

I would like to change the listeners to be called from a specific listener thread(-pool) by default. That should make it easy to delay the listener call until everything's ready. The current behaviour can then be opt-in.

That it doesn't do it asynchronously was an intentional decision. There are some things you can do now that otherwise you can never do, and it is straightforward to build asynchronous ones yourself (see, e.g. what doing ddsperf does with its asynchronous listener, which you can probably copy with very few modifications). In hindsight, though, it was not the right decision to not offer it standard.

caojiebao commented 3 months ago

thks for the advice

eboasson commented 3 weeks ago

I guess it is ok if I close this.