ServerConnection.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibIPC/Connection.h>
  8. namespace IPC {
  9. template<typename ClientEndpoint, typename ServerEndpoint>
  10. class ServerConnection : public IPC::Connection<ClientEndpoint, ServerEndpoint>
  11. , public ClientEndpoint::Stub
  12. , public ServerEndpoint::template Proxy<ClientEndpoint> {
  13. public:
  14. using ClientStub = typename ClientEndpoint::Stub;
  15. using IPCProxy = typename ServerEndpoint::template Proxy<ClientEndpoint>;
  16. ServerConnection(ClientStub& local_endpoint, const StringView& address)
  17. : Connection<ClientEndpoint, ServerEndpoint>(local_endpoint, Core::LocalSocket::construct())
  18. , ServerEndpoint::template Proxy<ClientEndpoint>(*this, {})
  19. {
  20. // We want to rate-limit our clients
  21. this->socket().set_blocking(true);
  22. if (!this->socket().connect(Core::SocketAddress::local(address))) {
  23. perror("connect");
  24. VERIFY_NOT_REACHED();
  25. }
  26. VERIFY(this->socket().is_connected());
  27. }
  28. virtual void die() override
  29. {
  30. // Override this function if you don't want your app to exit if it loses the connection.
  31. exit(0);
  32. }
  33. };
  34. }