Proper use of take_next_sample() and SampleInfo

2 posts / 0 new
Last post
Last seen: 1 year 3 months ago
Joined: 10/23/2013
Posts: 43
Proper use of take_next_sample() and SampleInfo

I have an application that uses read_next_sample()/take_next_sample().   What is the proper way for the application to determine if a valid sample has been read/taken.  Does return value of DDS_RETURN_OK indicate a valid sample?  Or must SampleInfo.valid_data also be checked before using the sample data?

This link suggests that checking return value is sufficient.

This this link indicates that sampleInfo also needs to be checked.. but not sure if it applies to take_next_sample()/read_next_sample()





Last seen: 4 months 1 week ago
Joined: 02/11/2016
Posts: 144

Hey Mark,

reading the links you've put up (as well as the api: it would seem that the answer is this:

The sample you receive may still be "invalid" in the sense that it may be a sample that signifies other instance states (for example: NOT_ALIVE_DISPOSED or NOT_ALIVE_NO_WRITERS).

That being said, I am glad you taught me about this api, I may use it :)

As I am not 100% certain I would recommend giving it a try:

setup a reader, then setup a writer.

use the writer to write a sample and make sure that you can read(or take) next sample.

then have the writer dispose (or unregister) the instance and see if the reader can read a new sample.


Thank you and good luck,