Kagome
Polkadot Runtime Engine in C++17
ws_listener_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_API_TRANSPORT_IMPL_WS_LISTENER_IMPL_HPP
7 #define KAGOME_CORE_API_TRANSPORT_IMPL_WS_LISTENER_IMPL_HPP
8 
10 
11 #include <atomic>
12 
14 #include "log/logger.hpp"
15 #include "metrics/metrics.hpp"
16 
17 namespace kagome::application {
18  class AppStateManager;
19 }
20 
21 namespace kagome::api {
26  class WsListenerImpl : public Listener,
27  public std::enable_shared_from_this<WsListenerImpl> {
28  public:
30 
32  const std::shared_ptr<application::AppStateManager> &app_state_manager,
33  std::shared_ptr<Context> context,
34  Configuration listener_config,
35  SessionImpl::Configuration session_config);
36 
37  ~WsListenerImpl() override = default;
38 
40  bool prepare() override;
41 
43  bool start() override;
44 
46  void stop() override;
47 
48  void setHandlerForNewSession(NewSessionHandler &&on_new_session) override;
49 
50  private:
51  void acceptOnce() override;
52 
53  std::shared_ptr<Context> context_;
56  const uint32_t max_ws_connections_;
57 
58  std::unique_ptr<Acceptor> acceptor_;
59  std::unique_ptr<NewSessionHandler> on_new_session_;
60 
61  std::atomic<Session::SessionId> next_session_id_;
62  std::shared_ptr<SessionImpl> new_session_;
63  std::atomic<uint32_t> active_connections_;
64 
65  // metrics
69 
71  };
72 
73 } // namespace kagome::api
74 
75 #endif // KAGOME_CORE_API_TRANSPORT_IMPL_WS_LISTENER_IMPL_HPP
std::atomic< uint32_t > active_connections_
server which listens for incoming connection, accepts connections making session from socket ...
const SessionImpl::Configuration session_config_
std::unique_ptr< NewSessionHandler > on_new_session_
std::atomic< Session::SessionId > next_session_id_
std::unique_ptr< Registry > RegistryPtr
Definition: metrics.hpp:15
RegistryPtr createRegistry()
std::shared_ptr< Context > context_
std::unique_ptr< Acceptor > acceptor_
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
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
std::shared_ptr< SessionImpl > new_session_
metrics::Counter * opened_session_
metrics::Counter * closed_session_
A counter metric to represent a monotonically increasing value.
Definition: metrics.hpp:27