libink: broker state belongs to the connection that has a broker

Parked calls and outbound calls awaiting a reply only ever happen on a
connection talking to a broker, but the parked array sat on the server
and the pending array on every connection.  A server with no broker
carried 4 KiB of slots it could never fill, and both were reachable
from code paths that have no business in them.

Move both behind one struct, allocated on the first park or call and
freed with the connection.  link_server_t goes from 4400 to 168 bytes;
link_connection_t barely moves, its buffers dominate, but an ordinary
peer no longer carries reply-tracking it never uses.

Tokens are now per bus rather than per server, so link_uid_resolved()
takes the connection the answer is about.  Every resolver already has
it: it is the first argument to both the resolver and the reply
callback.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-08-13 10:15:19 +02:00
1 parent 44e7da6d56
commit a1969efac1
5 files changed
+94 -51

No files matched your search

+24 -5
View File
@@ -35,6 +35,7 @@ int link_connection_call(link_connection_t *conn, const char *destination,
uint8_t hdr[LINK_CALL_HDR_MAX];
ssize_t blen = 0;
ssize_t hlen;
struct link_bus *bus;
uint32_t serial;
int i;
@@ -43,8 +44,12 @@ int link_connection_call(link_connection_t *conn, const char *destination,
return -1;
}
bus = __bus_get(conn);
if (!bus)
return -1;
for (i = 0; i < LINK_PENDING_CAP; i++) {
if (!conn->pending[i].used)
if (!bus->pending[i].used)
break;
}
if (i == LINK_PENDING_CAP) {
@@ -80,14 +85,28 @@ int link_connection_call(link_connection_t *conn, const char *destination,
__dbg("calling %s.%s on %s, serial %u", interface ? interface : "-",
member, destination ? destination : "peer", serial);
conn->pending[i].used = 1;
conn->pending[i].serial = serial;
conn->pending[i].cb = cb;
conn->pending[i].userdata = userdata;
bus->pending[i].used = 1;
bus->pending[i].serial = serial;
bus->pending[i].cb = cb;
bus->pending[i].userdata = userdata;
return 0;
}
struct link_bus *__bus_get(link_connection_t *conn)
{
if (!conn->bus)
conn->bus = calloc(1, sizeof(*conn->bus));
return conn->bus;
}
void __bus_free(link_connection_t *conn)
{
free(conn->bus);
conn->bus = NULL;
}
void link_connection_close(link_connection_t *conn)
{
size_t i;