0

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?

4

1 回答 1

0

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

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

从规范:

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

于 2017-02-05T18:21:06.120 回答