blob: 0b421a7d5b0656cabcfb9d5386a962d2bbb7f4d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#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();
}
|