mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
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:
1 parent
44e7da6d56
commit
a1969efac1
5 files changed
+94
-51
No files matched your search
+27
-11
@@ -70,6 +70,27 @@ struct link_parked {
|
||||
uint8_t buf[LINK_PARKED_MSG_MAX];
|
||||
};
|
||||
|
||||
/* Calls in flight in either direction: inbound ones held while we ask
|
||||
* who sent them, outbound ones waiting for their reply. Both belong
|
||||
* to a conversation with a broker, so this hangs off the connection
|
||||
* and is allocated on first use. An ordinary peer, which only ever
|
||||
* calls in and is identified by SO_PEERCRED, never gets one.
|
||||
*
|
||||
* Tokens are handed out per bus, which is all link_uid_resolved()
|
||||
* needs: it is told the connection the answer belongs to. */
|
||||
struct link_bus {
|
||||
struct link_parked parked[LINK_PARKED_CAP];
|
||||
link_authz_t next_tok;
|
||||
|
||||
/* Outbound calls we made on this connection, awaiting replies. */
|
||||
struct {
|
||||
int used;
|
||||
uint32_t serial;
|
||||
link_reply_cb_t cb;
|
||||
void *userdata;
|
||||
} pending[LINK_PENDING_CAP];
|
||||
};
|
||||
|
||||
struct link_server {
|
||||
int fd;
|
||||
char path[LINK_PATH_MAX];
|
||||
@@ -83,8 +104,6 @@ struct link_server {
|
||||
/* Set by link_server_set_authorizer(); see link.h. */
|
||||
link_authorizer_t authorizer;
|
||||
void *authz_userdata;
|
||||
struct link_parked parked[LINK_PARKED_CAP];
|
||||
link_authz_t next_tok;
|
||||
};
|
||||
|
||||
/* The reply being assembled inside a method handler.
|
||||
@@ -147,15 +166,8 @@ struct link_connection {
|
||||
|
||||
uint32_t next_serial;
|
||||
|
||||
/* Outbound calls we made on this connection, awaiting replies.
|
||||
* Only a broker connection uses these today, to ask the bus
|
||||
* driver who a sender is. */
|
||||
struct {
|
||||
int used;
|
||||
uint32_t serial;
|
||||
link_reply_cb_t cb;
|
||||
void *userdata;
|
||||
} pending[LINK_PENDING_CAP];
|
||||
/* Allocated on the first park or outbound call, see above. */
|
||||
struct link_bus *bus;
|
||||
|
||||
struct link_server *server; /* back-pointer for dispatch */
|
||||
};
|
||||
@@ -174,6 +186,10 @@ int __auth_process(link_connection_t *conn);
|
||||
void __auth_generate_guid(char out[33]);
|
||||
int __auth_client(int fd, uid_t uid);
|
||||
|
||||
/* connection.c — the per-connection bus state, made on demand. */
|
||||
struct link_bus *__bus_get (link_connection_t *conn);
|
||||
void __bus_free(link_connection_t *conn);
|
||||
|
||||
/* dispatch.c */
|
||||
int __dispatch_message(link_connection_t *conn, const struct link_msg *m, size_t framelen);
|
||||
void __dispatch_forget_conn(link_connection_t *conn);
|
||||
|
||||
Reference in new issue
Block a user