1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-05 00:13:14 +02:00

For JSON-RPC with UNIX Domain sockets, split on \n (newline).

This so multiple parallel requests can be handled properly.

JSON-RPC over websockets is unchanged, as every JSON-RPC
requests goes into its own websocket frame there (easy).
This commit is contained in:
Bram Matthys
2023-04-01 12:24:47 +02:00
parent 89f75bd6e7
commit 275cb97cfc
2 changed files with 19 additions and 4 deletions
+13 -4
View File
@@ -498,13 +498,22 @@ int rpc_packet_in_websocket(Client *client, char *readbuf, int length)
int rpc_packet_in_unix_socket(Client *client, const char *readbuf, int *length)
{
char buf[READBUFSIZE];
if (!RPC_PORT(client) || !(client->local->listener->socket_type == SOCKET_TYPE_UNIX) || (*length <= 0))
return 1; /* Not for us */
// FIXME: this assumes a single request in 'readbuf' while in fact:
// - it could only contain partial JSON, eg no ending } yet
// - there could be multiple requests
rpc_call_text(client, readbuf, *length);
dbuf_put(&client->local->recvQ, readbuf, *length);
while (DBufLength(&client->local->recvQ))
{
int len = dbuf_getmsg(&client->local->recvQ, buf);
if (len <= 0)
break;
rpc_call_text(client, buf, len);
if (IsDead(client))
break;
}
return 0;
}