From 2770da027a761aecb17610374f4f60cc1c6e76cd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 13 Feb 2018 18:27:05 +0100 Subject: [PATCH] sd-bus: add APIs to query the current read and write queue size --- man/rules/meson.build | 1 + man/sd_bus_get_n_queued_read.xml | 129 +++++++++++++++++++++++++++++++ src/libsystemd/libsystemd.sym | 6 ++ src/libsystemd/sd-bus/sd-bus.c | 20 +++++ 4 files changed, 156 insertions(+) create mode 100644 man/sd_bus_get_n_queued_read.xml diff --git a/man/rules/meson.build b/man/rules/meson.build index bfc267b544..84b911b365 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -186,6 +186,7 @@ manpages = [ ['SD_BUS_ERROR_END', 'SD_BUS_ERROR_MAP', 'sd_bus_error_map'], ''], ['sd_bus_get_fd', '3', [], ''], + ['sd_bus_get_n_queued_read', '3', ['sd_bus_get_n_queued_write'], ''], ['sd_bus_is_open', '3', ['sd_bus_is_ready'], ''], ['sd_bus_message_append', '3', ['sd_bus_message_appendv'], ''], ['sd_bus_message_append_array', diff --git a/man/sd_bus_get_n_queued_read.xml b/man/sd_bus_get_n_queued_read.xml new file mode 100644 index 0000000000..b39e87f8dd --- /dev/null +++ b/man/sd_bus_get_n_queued_read.xml @@ -0,0 +1,129 @@ + + + + + + + + + sd_bus_get_fd + systemd + + + + Developer + Lennart + Poettering + lennart@poettering.net + + + + + + sd_bus_get_n_queued_read + 3 + + + + sd_bus_get_n_queued_read + sd_bus_get_n_queued_write + + Get the number of pending bus messages in the read and write queues of a bus connection object + + + + + #include <systemd/sd-bus.h> + + + int sd_bus_get_n_queued_read + sd_bus *bus + uint64_t *ret + + + + int sd_bus_get_n_queued_write + sd_bus *bus + uint64_t *ret + + + + + + Description + + + sd_bus_get_n_queued_read() may be used to query the number of bus messages in the read queue + of a bus connection object. The read queue contains all messages read from the transport medium (e.g. network + socket) but not yet processed locally. The function expects two arguments: the bus object to query the number of + queued messages of, and a pointer to a 64bit counter variable to write the current queue size to. Use + sd_bus_process() in order to process queued messages, i.e. to reduce the size of the read + queue (as well as, in fact, the write queue, see below) when it is non-zero. + + + + Similar, sd_bus_get_n_queued_write() may be used to query the number of currently pending + bus messages in the write queue of a bus connection object. The write queue contains all messages enqueued into + the connection with a call such as sd_bus_send() but not yet written to the transport + medium. The expected arguments are similar to the ones of sd_bus_get_n_queued_read(). Here + too, use sd_bus_process() to reduce the size of the write queue. Alternatively, use + sd_bus_flush() to synchronously write out any pending bus messages until the write queue is + empty. + + + + + Return Value + + On success, these functions return 0 or a positive integer. On failure, they return a negative errno-style + error code. + + + + Errors + + Returned errors may indicate the following problems: + + + + -ECHILD + + The bus connection has been created in a different process. + + + + + + + See Also + + + systemd1, + sd-bus3, + sd_bus_process3, + sd_bus_send3, + sd_bus_flush3 + + + + diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 00aeefbe19..7ff5816180 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -549,3 +549,9 @@ global: sd_event_source_get_io_fd_own; sd_event_source_set_io_fd_own; } LIBSYSTEMD_236; + +LIBSYSTEMD_238 { +global: + sd_bus_get_n_queued_read; + sd_bus_get_n_queued_write; +} LIBSYSTEMD_237; diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index cbbc6b6f0c..2f5e483ae2 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -4091,3 +4091,23 @@ _public_ int sd_bus_get_sender(sd_bus *bus, const char **ret) { *ret = bus->patch_sender; return 0; } + +_public_ int sd_bus_get_n_queued_read(sd_bus *bus, uint64_t *ret) { + assert_return(bus, -EINVAL); + assert_return(bus = bus_resolve(bus), -ENOPKG); + assert_return(!bus_pid_changed(bus), -ECHILD); + assert_return(ret, -EINVAL); + + *ret = bus->rqueue_size; + return 0; +} + +_public_ int sd_bus_get_n_queued_write(sd_bus *bus, uint64_t *ret) { + assert_return(bus, -EINVAL); + assert_return(bus = bus_resolve(bus), -ENOPKG); + assert_return(!bus_pid_changed(bus), -ECHILD); + assert_return(ret, -EINVAL); + + *ret = bus->wqueue_size; + return 0; +}