4#ifdef MAYAFLUX_PLATFORM_WINDOWS
51 using MessageHandler = std::function<std::expected<std::string, std::string>(std::string_view)>;
79 [[nodiscard]]
bool start() noexcept;
90 [[nodiscard]]
bool is_running()
const {
return m_running; }
133 void broadcast_event(
const StreamEvent& event, std::optional<std::string_view> target_session = std::nullopt);
146 void set_client_session(
int client_fd, std::string session_id);
159 [[nodiscard]] std::vector<ClientInfo> get_connected_clients()
const;
163 int m_server_fd { -1 };
164 std::atomic<bool> m_running {
false };
180#ifndef MAYAFLUX_JTHREAD_BROKEN
181 void server_loop(
const std::stop_token& stop_token);
190 void handle_client(
int client_fd);
197 [[nodiscard]] std::expected<std::string, std::string> read_message(
int client_fd);
205 [[nodiscard]]
bool send_message(
int client_fd, std::string_view message);
212 void process_control_message(
int client_fd, std::string_view message);
218 void cleanup_client(
int client_fd);
Platform-specific threading wrapper for Server class.
Thread-safe event subscription and publishing system for Lila.
API-compatible stop token for platforms without std::stop_token.
Fallback std::thread-based thread wrapper with manual stop signaling.
ServerThread m_server_thread
Server thread.
void broadcast_to_all(std::string_view message)
Broadcasts a raw message to all connected clients.
ConnectionHandler m_disconnect_handler
Handler for client disconnections.
std::shared_mutex m_clients_mutex
Mutex for client map.
std::optional< std::string > get_client_session(int client_fd) const
Gets the session ID for a client.
void set_message_handler(MessageHandler handler)
Sets the handler for incoming client messages.
std::function< void(const ClientInfo &)> ConnectionHandler
Handler for client connection/disconnection events.
void on_client_disconnected(ConnectionHandler handler)
Registers a handler for client disconnection events.
EventBus & event_bus()
Accesses the event bus for subscribing to server events.
std::unordered_map< int, ClientInfo > m_connected_clients
Map of connected clients.
int m_port
TCP port to listen on.
MessageHandler m_message_handler
Handler for client messages.
void on_client_connected(ConnectionHandler handler)
Registers a handler for client connection events.
StartHandler m_start_handler
Handler for server start.
EventBus m_event_bus
Event bus for publishing server events.
ConnectionHandler m_connect_handler
Handler for client connections.
std::function< void()> StartHandler
Handler for server start events.
void on_server_started(StartHandler handler)
Registers a handler for server start events.
std::function< std::expected< std::string, std::string >(std::string_view)> MessageHandler
Handler for processing incoming client messages.
const EventBus & event_bus() const noexcept
Const access to the event bus.
TCP server for interactive live coding sessions in MayaFlux.
Information about a connected client.
Represents a published event in the system.