OpenSplice DDS:发布,直到超时 [英] OpenSplice DDS: Publish, until some timeout

查看:338
本文介绍了OpenSplice DDS:发布,直到超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天都在学习有关dds的更多信息,所以我的问题听起来很奇怪。我希望这是有道理的。

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

我正在编写的一些dds包装器的要求之一是,如果写入失败,它将在一段时间后超时。 我的问题:我该怎么做?

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?

Prism Tech网站的教程,其中说明了如何使用 WaitSet 进行阻止读操作,但是写操作呢?

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?

我注意到API中有一个函数 DataWriter :: wait_for_acknowledgements(int timeout),但这似乎绑定到 DataWriter 对象,而不是特定的编写调用。我可以将其与上面的调用绑定吗?

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?

推荐答案

这是在QoS中配置的,请参见可靠性字段 max_blocking_time。如何设置此值将取决于供应商的实现。通常,您会获得当前的QoS,更新字段,然后写回QoS。请记住,必须先设置某些QoS策略,然后才能进行其他操作。可靠性是启用之前(至少在我最熟悉的实现中),这意味着您需要创建禁用的数据写入器,更新QoS,然后启用写入器。

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.

如果可以在应用程序外部设置QoS(例如,通过XML),则可以轻松设置策略。否则,您需要在代码中完成此操作。

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.

根据规范:

max_blocking_time表示如果DataWriter没有空间来存储写入的值,则允许DataWriter :: write操作阻塞的最长时间。默认的max_blocking_time = 100ms。

这篇关于OpenSplice DDS:发布,直到超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆