Kagome
Polkadot Runtime Engine in C++17
listener.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_API_TRANSPORT_LISTENER_HPP
7 #define KAGOME_CORE_API_TRANSPORT_LISTENER_HPP
8 
9 #include <boost/asio/ip/tcp.hpp>
10 #include <memory>
11 
14 #include "outcome/outcome.hpp"
15 
16 namespace kagome::api {
21  class Listener {
22  protected:
23  using Acceptor = boost::asio::ip::tcp::acceptor;
24  using Endpoint = boost::asio::ip::tcp::endpoint;
25  using NewSessionHandler =
26  std::function<void(const std::shared_ptr<Session> &)>;
27 
28  public:
30 
31  struct Configuration {
34 
36  uint32_t ws_max_connections{};
37 
39  endpoint.address(boost::asio::ip::address_v4::any());
40  endpoint.port(0);
41  }
42  };
43 
44  virtual ~Listener() = default;
45 
50  virtual bool prepare() = 0;
51 
56  virtual bool start() = 0;
57 
62  virtual void stop() = 0;
63 
65  virtual void setHandlerForNewSession(
66  NewSessionHandler &&on_new_session) = 0;
67 
68  protected:
70  virtual void acceptOnce() = 0;
71  };
72 } // namespace kagome::api
73 
74 #endif // KAGOME_CORE_API_TRANSPORT_LISTENER_IMPL_HPP
virtual bool start()=0
Start handling inner connection.
boost::asio::ip::tcp::acceptor Acceptor
Definition: listener.hpp:23
server which listens for incoming connection, accepts connections making session from socket ...
Definition: listener.hpp:21
std::function< void(const std::shared_ptr< Session > &)> NewSessionHandler
Definition: listener.hpp:26
Endpoint endpoint
listening endpoint
Definition: listener.hpp:33
virtual bool prepare()=0
Bind endpoint.
virtual void setHandlerForNewSession(NewSessionHandler &&on_new_session)=0
Set handler for working new session.
virtual void acceptOnce()=0
Accept incoming connection.
virtual void stop()=0
Stop working.
boost::asio::ip::tcp::endpoint Endpoint
Definition: listener.hpp:24
uint32_t ws_max_connections
max allowed simultaneous connections through websocket
Definition: listener.hpp:36
virtual ~Listener()=default