libubus: use calloc_a for queued msgs to reduce the number of allocations

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libubus: remove ubus_msghdr_data() by passing in the right data structure pointer

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libubus: rework buffer allocation code

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libubus: preserve the received message buffer for incoming invoke calls

Set ctx->msgbuf.data to NULL during the call. If ctx->msgbuf is needed
during the call, a new buffer will be allocated. If not,
ctx->msgbuf.data is restored to the previous value afterwards

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libubus: restore uloop_cancelled on timeout

Context: 1 loop with a single ubus_invoke() that times out calls
uloop_end() which ends the loop, and thus ends the application.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libubus: replace __init with __constructor

__init has a naming collision with C++ and prevents ubus_common.h
from being included. Instead, use __constructor as defined from
libubox.

Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>
libubus: fix build error in examples/server

This fixes build warning:
/ubus.git/examples/server.c: In function 'test_hello_reply':
/ubus.git/examples/server.c:69:6: error: ignoring return value of 'pipe', declared with attribute warn_unused_result [-Werror=unused-result]

Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>
libubus: define _GNU_SOURCE, needed for O_CLOEXEC

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
libubus: expose ubus_connect_ctx() in public API

ubus_connect_ctx() is equivalent to ubus_connect() but accepts a
pointer to a previously allocated ubus_context struct.
ubus_shutdown() is made available as an alternative to ubus_free()
to clean up contexts initialised by ubus_connect_ctx().

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>