Introduce non-droppable control messages

Control messages are queued from the main thread and sent to the device
from a separate thread.

When the queue is full, messages are just dropped. This avoids to
accumulate too much delay between the client and the device in case of
network issue.

However, some messages should not be dropped: for example, dropping a
UHID_CREATE message would make invalid all further UHID_INPUT messages.
Therefore, mark these messages as non-droppable.

A non-droppable event is queued anyway (resizing the queue if
necessary, unless the allocation fails).
This commit is contained in:
Romain Vimont
2024-09-06 23:08:08 +02:00
parent 97e83fa3d6
commit 70a9bbbc06
3 changed files with 31 additions and 5 deletions

View File

@@ -278,6 +278,13 @@ sc_control_msg_log(const struct sc_control_msg *msg) {
}
}
bool
sc_control_msg_is_droppable(const struct sc_control_msg *msg) {
// Cannot drop UHID_CREATE messages, because it would cause all further
// UHID_INPUT messages for this device to be invalid
return msg->type != SC_CONTROL_MSG_TYPE_UHID_CREATE;
}
void
sc_control_msg_destroy(struct sc_control_msg *msg) {
switch (msg->type) {