From: Alexandru Ardelean Date: Fri, 27 Jun 2014 16:11:41 +0000 (+0300) Subject: libubus: add logic to reduce msgbuf data size after 16 small messages X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=82da9db3a985a53c73a21e0fda92a4a59d176f71;p=oweals%2Fubus.git libubus: add logic to reduce msgbuf data size after 16 small messages --- diff --git a/libubus-io.c b/libubus-io.c index 48bb72d..f38403f 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -28,6 +28,8 @@ #define STATIC_IOV(_var) { .iov_base = (char *) &(_var), .iov_len = sizeof(_var) } +#define UBUS_MSGBUF_REDUCTION_INTERVAL 16 + static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = { [UBUS_ATTR_STATUS] = { .type = BLOB_ATTR_INT32 }, [UBUS_ATTR_OBJID] = { .type = BLOB_ATTR_INT32 }, @@ -250,6 +252,17 @@ static bool get_next_msg(struct ubus_context *ctx, int *recv_fd) len = blob_raw_len(&hdrbuf.data); if (len > ctx->msgbuf_data_len) { + ctx->msgbuf_reduction_counter = UBUS_MSGBUF_REDUCTION_INTERVAL; + } else if (ctx->msgbuf_data_len > UBUS_MSG_CHUNK_SIZE) { + if (ctx->msgbuf_reduction_counter > 0) { + len = -1; + --ctx->msgbuf_reduction_counter; + } else + len = UBUS_MSG_CHUNK_SIZE; + } else + len = -1; + + if (len > -1) { ctx->msgbuf.data = realloc(ctx->msgbuf.data, len * sizeof(char)); if (ctx->msgbuf.data) ctx->msgbuf_data_len = len; diff --git a/libubus.h b/libubus.h index 78ffa38..a63ce31 100644 --- a/libubus.h +++ b/libubus.h @@ -156,6 +156,7 @@ struct ubus_context { struct ubus_msghdr_buf msgbuf; uint32_t msgbuf_data_len; + int msgbuf_reduction_counter; }; struct ubus_object_data {