diff options
author | Tom Gundersen <teg@jklm.no> | 2014-04-14 17:20:51 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-04-14 17:53:21 +0200 |
commit | a88f77c406ea56160c1e5a4b39eab1de134abe40 (patch) | |
tree | d1da4d5a0fae4a11dfa5429e65c03b09109a55a6 /src/libsystemd/sd-rtnl/sd-rtnl.c | |
parent | 1403f45ab61d6f2026a3a7a06b52a536c1b7a3b3 (diff) |
sd-rtnl: socket_read - use a read buffer
Rather than allocating/freeing memory for each message read, keep a global read buffer
in the rtnl object. Also, rather than using a fixed size, peek at the pending message
header to get the message size and reallocate as necessary.
Diffstat (limited to 'src/libsystemd/sd-rtnl/sd-rtnl.c')
-rw-r--r-- | src/libsystemd/sd-rtnl/sd-rtnl.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c index 367f165a1c..e4d436bb17 100644 --- a/src/libsystemd/sd-rtnl/sd-rtnl.c +++ b/src/libsystemd/sd-rtnl/sd-rtnl.c @@ -54,6 +54,12 @@ static int sd_rtnl_new(sd_rtnl **ret) { if (!GREEDY_REALLOC(rtnl->wqueue, rtnl->wqueue_allocated, 1)) return -ENOMEM; + /* We guarantee that the read buffer has at least space for + * a message header */ + if (!greedy_realloc((void**)&rtnl->rbuffer, &rtnl->rbuffer_allocated, + sizeof(struct nlmsghdr), sizeof(uint8_t))) + return -ENOMEM; + *ret = rtnl; rtnl = NULL; @@ -133,6 +139,8 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) { sd_rtnl_message_unref(rtnl->wqueue[i]); free(rtnl->wqueue); + free(rtnl->rbuffer); + hashmap_free_free(rtnl->reply_callbacks); prioq_free(rtnl->reply_callbacks_prioq); |