19#ifndef PACS_NETWORK_DETAIL_ACCEPT_WORKER_HPP
20#define PACS_NETWORK_DETAIL_ACCEPT_WORKER_HPP
22#include <kcenon/thread/core/thread_base.h>
23#include <kcenon/common/patterns/result.h>
34#pragma comment(lib, "ws2_32.lib")
37#include <netinet/in.h>
38#include <sys/socket.h>
144 [[nodiscard]] uint16_t
port() const noexcept;
166 [[nodiscard]] std::
string to_string() const override;
272 bool wsa_initialized_{
false};
connection_callback on_connection_
Callback for new connections.
int backlog_
Maximum pending connections in listen queue.
result_void after_stop() override
Cleans up resources after the worker thread stops.
result_void do_work() override
Main work routine - checks for incoming connections.
accept_worker(accept_worker &&)=delete
void set_max_pending_connections(int backlog)
Sets the maximum number of pending connections in the listen queue.
common::VoidResult result_void
int listen_socket_
Listen socket file descriptor (POSIX)
uint64_t next_session_id()
Generates a unique session ID for new connections.
std::function< void()> maintenance_callback
Callback type for periodic maintenance tasks.
void on_stop_requested() override
Called when stop() is requested.
accept_worker & operator=(const accept_worker &)=delete
bool should_continue_work() const override
Determines whether there is pending work that must complete.
std::function< void(uint64_t session_id)> connection_callback
Callback type for new connection events.
accept_worker(const accept_worker &)=delete
result_void before_start() override
Initializes resources before the worker thread starts.
uint16_t port_
TCP port to listen on.
std::atomic< uint64_t > session_id_counter_
Session ID counter for unique connection identification.
maintenance_callback on_maintenance_
Optional callback for maintenance tasks.
uint16_t port() const noexcept
Gets the configured port number.
int max_pending_connections() const noexcept
Gets the current backlog setting.
accept_worker(uint16_t port, connection_callback on_connection, maintenance_callback on_maintenance=nullptr)
Constructs an accept_worker with the specified configuration.
bool is_accepting() const noexcept
Checks if the worker is actively accepting connections.
~accept_worker() override
Destructor.
std::atomic< bool > accepting_
Flag indicating if actively accepting connections.
accept_worker & operator=(accept_worker &&)=delete