1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

Inspector+LibCore+rpcdump: Rework the RPC stuff to be request/response

RPC clients now send JSON-encoded requests to the RPC server.
The connection also stays alive instead of disconnecting automatically
after the initial CObject graph dump.

JSON payloads are preceded by a single host-order encoded 32-bit int
containing the length of the payload.

So far, we have three RPC commands:

    - Identify
    - GetAllObjects
    - Disconnect

We'll be adding more of these as we go along. :^)
This commit is contained in:
Andreas Kling 2019-09-11 21:19:23 +02:00
parent 38b75d2a97
commit f89944e804
5 changed files with 217 additions and 38 deletions

View file

@ -1,3 +1,5 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <LibCore/CEventLoop.h>
#include <LibCore/CLocalSocket.h>
#include <stdio.h>
@ -18,6 +20,13 @@ int main(int argc, char** argv)
socket.on_connected = [&] {
dbg() << "Connected to PID " << pid;
JsonObject request;
request.set("type", "GetAllObjects");
auto serialized = request.to_string();
i32 length = serialized.length();
socket.write((const u8*)&length, sizeof(length));
socket.write(serialized);
};
socket.on_ready_to_read = [&] {
@ -32,6 +41,8 @@ int main(int argc, char** argv)
for (int i = 0; i < data.size(); ++i)
putchar(data[i]);
printf("\n");
loop.quit(0);
};
auto success = socket.connect(CSocketAddress::local(String::format("/tmp/rpc.%d", pid)));