Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
i_protocol_server.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
12#pragma once
13
22#include "i_network_component.h"
23#include "i_session.h"
24
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <string_view>
29#include <system_error>
30#include <vector>
31
33
35{
36
112 {
113 public:
115 using connection_callback_t = std::function<void(std::shared_ptr<i_session>)>;
117 using disconnection_callback_t = std::function<void(std::string_view)>;
119 using receive_callback_t = std::function<void(std::string_view, const std::vector<uint8_t>&)>;
121 using error_callback_t = std::function<void(std::string_view, std::error_code)>;
122
154 [[nodiscard]] virtual auto start(uint16_t port) -> VoidResult = 0;
155
187 [[nodiscard]] virtual auto stop() -> VoidResult = 0;
188
210 [[nodiscard]] virtual auto connection_count() const -> size_t = 0;
211
246 virtual auto set_connection_callback(connection_callback_t callback) -> void = 0;
247
281 virtual auto set_disconnection_callback(disconnection_callback_t callback) -> void = 0;
282
316 virtual auto set_receive_callback(receive_callback_t callback) -> void = 0;
317
360 virtual auto set_error_callback(error_callback_t callback) -> void = 0;
361 };
362
363} // namespace kcenon::network::interfaces
Base interface for all network components.
Unified interface for all protocol server implementations.
virtual auto connection_count() const -> size_t=0
Gets the number of active client connections.
virtual auto set_connection_callback(connection_callback_t callback) -> void=0
Sets the callback for new connections.
virtual auto set_receive_callback(receive_callback_t callback) -> void=0
Sets the callback for received data.
virtual auto stop() -> VoidResult=0
Stops the server and closes all connections.
virtual auto set_disconnection_callback(disconnection_callback_t callback) -> void=0
Sets the callback for disconnections.
std::function< void(std::string_view)> disconnection_callback_t
Callback type for disconnections (session_id)
virtual auto set_error_callback(error_callback_t callback) -> void=0
Sets the callback for errors.
virtual auto start(uint16_t port) -> VoidResult=0
Starts the server and begins listening for connections.
std::function< void(std::string_view, const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data (session_id, data)
std::function< void(std::string_view, std::error_code)> error_callback_t
Callback type for errors (session_id, error)
std::function< void(std::shared_ptr< i_session >)> connection_callback_t
Callback type for new connections.
Base interface for all network components.
Session interface representing an active client-server connection.
Public header for Result<T> error handling types.