1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00
serenity/Userland/Libraries/LibIPC/ServerConnection.h
Gunnar Beutner 78803ce384 Userland: Split IPC endpoints into proxies and stubs
This enables support for automatically generating client methods.
With this added the user gets code completion support for all
IPC methods which are available on a connection object.
2021-05-03 21:14:06 +02:00

42 lines
1.1 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibIPC/Connection.h>
namespace IPC {
template<typename ClientEndpoint, typename ServerEndpoint>
class ServerConnection : public IPC::Connection<ClientEndpoint, ServerEndpoint>, public ClientEndpoint::Stub {
public:
using ClientStub = typename ClientEndpoint::Stub;
using ServerProxy = typename ServerEndpoint::Proxy;
ServerConnection(ClientStub& local_endpoint, const StringView& address)
: Connection<ClientEndpoint, ServerEndpoint>(local_endpoint, Core::LocalSocket::construct())
{
// We want to rate-limit our clients
this->socket().set_blocking(true);
if (!this->socket().connect(Core::SocketAddress::local(address))) {
perror("connect");
VERIFY_NOT_REACHED();
}
VERIFY(this->socket().is_connected());
}
virtual void handshake() = 0;
virtual void die() override
{
// Override this function if you don't want your app to exit if it loses the connection.
exit(0);
}
};
}