Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::server::ConnectionManager Class Reference

Manages active HTTP connections. More...

#include <ConnectionManager.hpp>

Collaboration diagram for orbit::server::ConnectionManager:

Public Member Functions

 ConnectionManager (network::Proactor &proactor, const routing::Router &router, concurrency::ThreadPool &thread_pool, TimerManager &timer_manager, size_t max_body_size, network::TlsContext *tls_context=nullptr)
 Constructs a ConnectionManager.
 
 ~ConnectionManager ()
 
void set_timeouts (const ConnectionTimeouts &timeouts)
 Sets the timeouts applied to connections accepted from now on.
 
void set_limits (const ConnectionLimits &limits)
 
void set_on_removed (std::function< void()> callback)
 Called once for each connection removed (from the thread removing it).
 
void ping_websockets ()
 Event-loop thread: pings every WebSocket connection.
 
void add_connection (network::Socket socket, const std::string &client_ip)
 Adds a new connection to the manager.
 
void remove_connection (int fd)
 Removes a connection by file descriptor.
 
size_t get_connection_count () const
 Gets the current number of active connections.
 
void notify_shutdown ()
 
void mark_shutting_down ()
 
bool shutting_down () const
 

Private Attributes

std::atomic< bool > shutting_down_ {false}
 
network::Proactor & proactor_
 
const routing::Router & router_
 
concurrency::ThreadPool & thread_pool_
 
TimerManager & timer_manager_
 
ConnectionTimeouts timeouts_
 
ConnectionLimits limits_
 
std::unordered_map< int, std::shared_ptr< Connection > > connections_
 
std::mutex map_mutex_
 
std::function< void()> on_removed_
 
size_t max_body_size_
 
network::TlsContext * tls_context_
 

Detailed Description

Manages active HTTP connections.

Constructor & Destructor Documentation

◆ ConnectionManager()

orbit::server::ConnectionManager::ConnectionManager ( network::Proactor &  proactor,
const routing::Router &  router,
concurrency::ThreadPool &  thread_pool,
TimerManager &  timer_manager,
size_t  max_body_size,
network::TlsContext *  tls_context = nullptr 
)

Constructs a ConnectionManager.

Parameters
proactorThe proactor for I/O.
routerThe router.
thread_poolThe thread pool.
timer_managerThe timer manager.
max_body_sizeThe maximum body size allowed.
tls_contextThe TLS context (optional).

◆ ~ConnectionManager()

orbit::server::ConnectionManager::~ConnectionManager ( )

Connections still open (the server is going away) are closed for anyone still holding one as a ResponseWriter.

Member Function Documentation

◆ add_connection()

void orbit::server::ConnectionManager::add_connection ( network::Socket  socket,
const std::string &  client_ip 
)

Adds a new connection to the manager.

Parameters
socketThe connection socket.
client_ipThe client's IP address.

◆ get_connection_count()

size_t orbit::server::ConnectionManager::get_connection_count ( ) const

Gets the current number of active connections.

Returns
The number of connections.

◆ mark_shutting_down()

void orbit::server::ConnectionManager::mark_shutting_down ( )
inline

Any thread: set as soon as shutdown is requested, before the event loop gets to notify_shutdown(), so responses sent in between already carry "Connection: close".

◆ notify_shutdown()

void orbit::server::ConnectionManager::notify_shutdown ( )

Event-loop thread: asks every connection to finish up (see Connection::on_server_shutdown). Called repeatedly while draining.

◆ ping_websockets()

void orbit::server::ConnectionManager::ping_websockets ( )

Event-loop thread: pings every WebSocket connection.

◆ remove_connection()

void orbit::server::ConnectionManager::remove_connection ( int  fd)

Removes a connection by file descriptor.

Parameters
fdThe file descriptor.

◆ set_limits()

void orbit::server::ConnectionManager::set_limits ( const ConnectionLimits &  limits)
inline

◆ set_on_removed()

void orbit::server::ConnectionManager::set_on_removed ( std::function< void()>  callback)
inline

Called once for each connection removed (from the thread removing it).

◆ set_timeouts()

void orbit::server::ConnectionManager::set_timeouts ( const ConnectionTimeouts &  timeouts)
inline

Sets the timeouts applied to connections accepted from now on.

◆ shutting_down()

bool orbit::server::ConnectionManager::shutting_down ( ) const
inline

Member Data Documentation

◆ connections_

std::unordered_map<int, std::shared_ptr<Connection> > orbit::server::ConnectionManager::connections_
private

◆ limits_

ConnectionLimits orbit::server::ConnectionManager::limits_
private

◆ map_mutex_

std::mutex orbit::server::ConnectionManager::map_mutex_
mutableprivate

◆ max_body_size_

size_t orbit::server::ConnectionManager::max_body_size_
private

◆ on_removed_

std::function<void()> orbit::server::ConnectionManager::on_removed_
private

◆ proactor_

network::Proactor& orbit::server::ConnectionManager::proactor_
private

◆ router_

const routing::Router& orbit::server::ConnectionManager::router_
private

◆ shutting_down_

std::atomic<bool> orbit::server::ConnectionManager::shutting_down_ {false}
private

◆ thread_pool_

concurrency::ThreadPool& orbit::server::ConnectionManager::thread_pool_
private

◆ timeouts_

ConnectionTimeouts orbit::server::ConnectionManager::timeouts_
private

◆ timer_manager_

TimerManager& orbit::server::ConnectionManager::timer_manager_
private

◆ tls_context_

network::TlsContext* orbit::server::ConnectionManager::tls_context_
private

The documentation for this class was generated from the following file: