What is a "slot" in sd-bus (C language)

There sd-bus.hare several APIs in the systemd file that optionally take an argument slot. Here are some examples:

int sd_bus_call_async(sd_bus *bus, sd_bus_slot **slot, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec);
int sd_bus_add_filter(sd_bus *bus, sd_bus_slot **slot, sd_bus_message_handler_t callback, void *userdata);
int sd_bus_add_fallback(sd_bus *bus, sd_bus_slot **slot, const char *prefix, sd_bus_message_handler_t callback, void *userdata);

If the calling code indicates NULL, then it becomes a "floating slot", which, I believe, means that the calling code does not need to worry about it.

Basically, the source code example that I see looks like this example: https://github.com/tasleson/dbus-signals/blob/6d0e43d02d24ed51a17ce7df15a3a0a64ec0170d/spamsignals.c#L160

A slot is required, and then after a while it does not remove the slot. But in fact, he does nothing with it.

+4
source share
2 answers

Passing your own slot causes your sd-bus-match life to get entangled in one of the slots. Thus, when you do not pay attention to the slot, you also destroy the match.
Otherwise, passing NULL will tie your matching life to one of the bus objects.
The same goes for the other functions that you specified:
* sd_bus_call_async with a slot gives you the ability to destroy an asynchronous call without paying attention to the slot.
 * sd_bus_add_filter with a slot will destroy the filter when you do not refer to the slot.
I am not sure about sd_bus_add_fallback because I have never heard of this. Check here that the function is called when the slot does not receive a response:https://github.com/systemd/systemd/blob/a7753693547233e4a1d6e10b1a8f6515a477f227/src/libsystemd/sd-bus/bus-slot.c#L68

+3

, , , ? , , sd_bus (vtable, , ..). , - , .

, , / sd_bus, , , , NULL.

+3

Source: https://habr.com/ru/post/1674835/


All Articles