mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 16:25:08 +00:00

All programs that have a CEventLoop now allow local socket connections via /tmp/rpc.PID and will dump a serialized JSON array of all the live CObjects in the program onto connecting sockets. Also added a small /bin/rpcdump tool that connects to an RPC socket and produces a raw dump of the JSON that comes out.
42 lines
922 B
C++
42 lines
922 B
C++
#include <LibCore/CEventLoop.h>
|
|
#include <LibCore/CLocalSocket.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if (argc != 2) {
|
|
printf("usage: %s <pid>\n", argv[0]);
|
|
return 0;
|
|
}
|
|
|
|
CEventLoop loop;
|
|
|
|
int pid = atoi(argv[1]);
|
|
|
|
CLocalSocket socket;
|
|
auto success = socket.connect(CSocketAddress::local(String::format("/tmp/rpc.%d", pid)));
|
|
if (!success) {
|
|
fprintf(stderr, "Couldn't connect to PID %d\n", pid);
|
|
return 1;
|
|
}
|
|
|
|
socket.on_connected = [&] {
|
|
dbg() << "Connected to PID " << pid;
|
|
};
|
|
|
|
socket.on_ready_to_read = [&] {
|
|
if (socket.eof()) {
|
|
dbg() << "Disconnected from PID " << pid;
|
|
loop.quit(0);
|
|
return;
|
|
}
|
|
|
|
auto data = socket.read_all();
|
|
|
|
for (int i = 0; i < data.size(); ++i)
|
|
putchar(data[i]);
|
|
printf("\n");
|
|
};
|
|
|
|
return loop.exec();
|
|
}
|