sd-bus: maintain a counter for incoming msgs

Let's count incoming messages and attach the current counter when we
first read them to the message objects. This allows us to nicely order
messages later on.
This commit is contained in:
Lennart Poettering 2019-03-29 15:40:56 +01:00
parent 66d3159739
commit f1617a3b61
4 changed files with 11 additions and 0 deletions

View File

@ -226,6 +226,7 @@ struct sd_bus {
size_t wqueue_allocated;
uint64_t cookie;
uint64_t read_counter; /* A counter for each incoming msg */
char *unique_name;
uint64_t unique_id;

View File

@ -128,6 +128,8 @@ struct sd_bus_message {
size_t header_offsets[_BUS_MESSAGE_HEADER_MAX];
unsigned n_header_offsets;
uint64_t read_counter;
};
static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) {

View File

@ -1146,6 +1146,7 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) {
bus->n_fds = 0;
if (t) {
t->read_counter = ++bus->read_counter;
bus->rqueue[bus->rqueue_size++] = bus_message_ref_queued(t, bus);
sd_bus_message_unref(t);
}

View File

@ -484,6 +484,7 @@ static int synthesize_connected_signal(sd_bus *bus) {
return r;
bus_message_set_sender_local(bus, m);
m->read_counter = ++bus->read_counter;
r = bus_seal_synthetic_message(bus, m);
if (r < 0)
@ -2422,6 +2423,8 @@ static int process_timeout(sd_bus *bus) {
if (r < 0)
return r;
m->read_counter = ++bus->read_counter;
r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
@ -2524,6 +2527,7 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
synthetic_reply->realtime = m->realtime;
synthetic_reply->monotonic = m->monotonic;
synthetic_reply->seqnum = m->seqnum;
synthetic_reply->read_counter = m->read_counter;
r = bus_seal_synthetic_message(bus, synthetic_reply);
if (r < 0)
@ -2866,6 +2870,8 @@ static int process_closing_reply_callback(sd_bus *bus, struct reply_callback *c)
if (r < 0)
return r;
m->read_counter = ++bus->read_counter;
r = bus_seal_synthetic_message(bus, m);
if (r < 0)
return r;
@ -2930,6 +2936,7 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
return r;
bus_message_set_sender_local(bus, m);
m->read_counter = ++bus->read_counter;
r = bus_seal_synthetic_message(bus, m);
if (r < 0)