14 : m_port(port), m_onNewClientCallback(onNewClientCallback)
48 throw std::runtime_error(
"Failed to open acceptor");
72 sockpp::error_code err{sockResult.error()};
74 bool isExpectedError =
75 (err == std::errc::resource_unavailable_try_again ||
76 err == std::errc::operation_would_block || err == std::errc::timed_out);
80 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
83 IRSOL_LOG_WARN(
"Failed to accept connection: {}", sockResult.error_message());
Accepts and forwards incoming client connections to the session handler.
Assertion macros and utilities based on the PPK_ASSERT library.
OnNewClientCallback_t m_onNewClientCallback
Callback to handle accepted client connections.
ClientSessionAcceptor(irsol::types::port_t port, OnNewClientCallback_t onNewClientCallback)
Constructs the acceptor.
const irsol::types::port_t m_port
Port on which to accept incoming TCP connections.
irsol::types::acceptor_t m_acceptor
TCP acceptor socket bound to m_port.
std::atomic< bool > m_running
Flag indicating whether the acceptor should continue running.
void stop()
Stops the accept loop.
bool isOpen() const
Checks if the acceptor is actively listening.
std::string error() const
Gets the current error message, if any.
void run()
Starts the accept loop.
irsol::types::connection_result_t m_isOpen
Result of attempting to bind and open the acceptor socket.
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
#define IRSOL_LOG_ERROR(...)
Logs an error-level message using the default logger.
#define IRSOL_LOG_WARN(...)
Logs a warning-level message using the default logger.
#define IRSOL_LOG_DEBUG(...)
Logs a debug-level message using the default logger.
std::function< void(irsol::types::client_id_t, irsol::types::socket_t &&)> OnNewClientCallback_t
Callback function for handling new client connections.
Logging utilities and configuration for the irsol library.
std::string client_id_t
Represents a unique client identifier. Typically used to identify connected clients by string IDs.
uint16_t port_t
Represents a network port number. Typically used to specify TCP or UDP ports.
sockpp::inet_address inet_address_t
Alias for an IPv4/IPv6 internet address.
std::string uuid()
Generates a new UUID string.
Declaration of the ClientSession class.
General utility functions used throughout the irsol library.