SD_BUS_GET_N_QUEUED_READ(3)

πŸ’… SD_BUS_GET_N_QUEUED_READ(3) πŸ’…

okay bestie, welcome to the sd_bus_get_fd manual page β€” yes that's the page family, we're just hanging out in the queue-counting corner of it today πŸŽ€ buckle up, this one's actually pretty chill.


✨ NAME ✨

sd_bus_get_n_queued_read, sd_bus_get_n_queued_write β€” get the number of pending bus messages chillin' in the read and write queues of a bus connection object πŸ’Œ


🌸 SYNOPSIS 🌸

#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 πŸ¦‹

So sd_bus_get_n_queued_read() is literally your girl for asking "how many bus messages are sitting in the read queue of this bus connection object rn?" πŸ‘€ The read queue holds all the messages that have been read from the transport medium (think: a network socket, iykyk) but that haven't been processed locally yet. It's giving "inbox energy."

The function takes two arguments: the bus object you wanna query, and a pointer to a uint64_t 64-bit counter variable where the current queue size gets written. That's it, that's the whole vibe 🫢

Wanna actually shrink that read queue? Use sd_bus_process() β€” that's the one that processes queued messages, which reduces the read queue size (and honestly, the write queue too, see below, it's a whole thing 😭).

Similarly, sd_bus_get_n_queued_write() is the matching icon for querying the number of currently pending bus messages in the write queue of a bus connection object ✨ The write queue holds all the messages that got enqueued into the connection via a call like sd_bus_send() but that haven't been written out to the transport medium yet. The arguments are the same as sd_bus_get_n_queued_read() β€” same shape, same energy πŸ’…

Here too, use sd_bus_process() if you wanna reduce the size of the write queue. Or, alternate route: use sd_bus_flush() to synchronously write out any pending bus messages until the write queue is literally empty. no cap, empty empty 🧚


⭐ RETURN VALUE ⭐

On success, these functions return 0 or a positive integer πŸ’– On failure, they return a negative errno-style error code (rude, but okay).

πŸ™ˆ Errors

Returned errors may indicate the following problems:

  • -ECHILD β€” the bus connection was created in a different process, library or module instance. bestie... that's not your bus. 🫠

πŸ‘‘ NOTES πŸ‘‘

The functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file 🌈

All functions listed here are thread-agnostic, and only a single thread may operate on a given object at any given time ⏰ Different threads may access the same object at different times β€” no double-teaming. Multiple independent objects, though? Go off, use them from different threads in parallel, that's totally fine πŸ’…βœ¨

⚠️ okay important one: the code described here uses getenv(3), which is declared to be not multi-thread-safe. That means the code calling the functions described here must not call setenv(3) from a parallel thread. It's recommended to only make calls to setenv() from an early phase of the program, back when no other threads have been started πŸ“

πŸ”₯ HISTORY πŸ”₯

sd_bus_get_n_queued_read() and sd_bus_get_n_queued_write() were added in version 238 β€” vintage, but iconic πŸ‘‘


πŸ’œ SEE ALSO πŸ’œ

systemd(1), sd-bus(3), sd_bus_process(3), sd_bus_send(3), sd_bus_flush(3)


that's the whole page, bestie β€” go count some queues πŸ’– this was systemd 261.3, page SD_BUS_GET_N_QUEUED_READ(3), brought to you by the sd_bus_get_fd manual family. mwah πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from