Message batching#
AES70 traffic often consists of many small messages. To use the network efficiently, it is therefore important to ensure that many small commands or events are combined into larger messages.
In libaes70 this happens on two levels:
- If possible, libaes70 will try to combine identical AES70 message types into larger AES70 messages.
- If possible, libaes70 will try to buffer data for sending in order to write larger chunks at once.
Since it is generally difficult to decide when to buffer and wait for additional messages to be generated, this only happens in the following situations:
-
While processing incoming data, outgoing messages are not immediately sent. This ensures that a series of commands that are received from a controller are usually responded to in the same response message. A similar logic is applied for controllers.
-
When connections are manually set to buffer data using the
cork()anduncork()methods.
One typical example of when to use the cork() and uncork() API is when
sending out level meter updates on multiple channels or other property
changes.
An example of this can be found in examples/devices/gains_and_levels/device.cpp:
static void update_level_meters(uv_timer_t *)
{
auto tmp = device.cork_handle();
for (auto &level : levels)
level.get().update_level(random_level());
}
The cork_handle() in the above example returns an object that calls
cork() on construction and uncork() on destruction.
This provides an exception-safe mechanism to cork and uncork connections.
Warn
Make sure to not cork() devices or connections for a long period. It is usually
not safe to do that. Specifically, it must not be possible for new connections
to be created while a device is corked.
It is usually okay to cork() temporarily in a function.