OpenSplice DDS: Publish, until some timeout

半世苍凉 提交于 2019-12-12 04:23:39

问题


I'm learning every day more about dds, so my question my sound weird. I hope it makes sense.

One of the requirements of some dds wrapper I'm writing, is that it times out after some timeout period if it fails to write. My question: How can I do that?

On Prism Tech's website's tutorial, there's explanation on how to use a WaitSet to block a read operation, but what about write?

Here's some code including the question:

dds::domain::DomainParticipant dp(0);
dds::topic::Topic<MyType> topic(dp, "MyTopic");
dds::pub::Publisher pub(dp);
dds::pub::DataWriter<MyType> dw(pub, topic);

MyType t;
dw.write(t); //how can I make this block for 5 seconds (tops), and then throw an error on failure?

I noticed there exists a function in the API DataWriter::wait_for_acknowledgements(int timeout), but this seems to be bound to the DataWriter object, not to the specific call of writing. Can I bind it with the call above?


回答1:


This is configured in QoS, cf RELIABILITY, field "max_blocking_time". How you set this value will depend on the vendor's implementation. Generally you get the current QoS, update the field, write the QoS back. Keep in mind that certain QoS policies must be set before something else happens. Reliability is "Before Enable" (at least in the implementation I'm most familiar with), which means you need to create the data-writer disabled, update the QoS, then enable the writer.

If QoS can be set outside the application (via XML for example), then you can set the policy easily. Otherwise, you need to do it in code.

From the spec:

The value of the max_blocking_time indicates the maximum time the operation DataWriter::write is allowed to block if the DataWriter does not have space to store the value written. The default max_blocking_time=100ms.



来源:https://stackoverflow.com/questions/42023478/opensplice-dds-publish-until-some-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!