blob: 3d4b5b69f1b62e7a2ae72f77391580ca710f3235 (
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
|
#include <LibCore/CEventLoop.h>
#include <LibCore/CTimer.h>
#include <LibCore/CoreIPCServer.h>
#include <LibCore/CLocalServer.h>
#include <stdio.h>
#include "SimpleEndpoint.h"
class SimpleIPCServer final :
public IPC::Server::ConnectionNG<SimpleEndpoint>,
public SimpleEndpoint {
C_OBJECT(SimpleIPCServer)
public:
SimpleIPCServer(CLocalSocket& socket, int client_id)
: ConnectionNG(*this, socket, client_id)
{
}
virtual OwnPtr<Simple::ComputeSumResponse> handle(const Simple::ComputeSum& message)
{
return make<Simple::ComputeSumResponse>(message.a() + message.b() + message.c());
}
};
int main(int, char**)
{
CEventLoop event_loop;
unlink("/tmp/simple-ipc");
CLocalServer server_sock;
server_sock.listen("/tmp/simple-ipc");
server_sock.on_ready_to_accept = [&] {
auto* client_socket = server_sock.accept();
ASSERT(client_socket);
static int next_client_id = 0;
IPC::Server::new_connection_ng_for_client<SimpleIPCServer>(*client_socket, ++next_client_id);
};
return event_loop.exec();
}
|