sd-netlink: append multipart messages in O(1)
Commit52ceba53d3made multipart replies append in receive order, but each append walked the chain from the head. Cache the tail on the chain head, so new fragments can be linked directly. The visible next-pointer chain and order stay unchanged. Follow-up for:52ceba53d3
This commit is contained in:
committed by
Yu Watanabe
parent
0168430d91
commit
1a43aec562
@@ -128,6 +128,7 @@ typedef struct sd_netlink_message {
|
||||
bool sealed:1;
|
||||
|
||||
sd_netlink_message *next; /* next in a chain of multi-part messages */
|
||||
sd_netlink_message *tail; /* last message in a multi-part chain */
|
||||
} sd_netlink_message;
|
||||
|
||||
int message_new_empty(sd_netlink *nl, sd_netlink_message **ret);
|
||||
|
||||
@@ -411,9 +411,11 @@ int socket_read_message(sd_netlink *nl) {
|
||||
if (existing) {
|
||||
/* This is the continuation of the previously read messages.
|
||||
* Let's append this message at the end. */
|
||||
while (existing->next)
|
||||
existing = existing->next;
|
||||
existing->next = TAKE_PTR(m);
|
||||
if (existing->tail)
|
||||
existing->tail->next = m;
|
||||
else
|
||||
existing->next = m;
|
||||
existing->tail = TAKE_PTR(m);
|
||||
} else {
|
||||
/* This is the first message. Put it into the queue for partially
|
||||
* received messages. */
|
||||
|
||||
Reference in New Issue
Block a user