6#ifndef KCENON_NETWORK_INTERNAL_TCP_SECURE_TCP_SOCKET_H_
7#define KCENON_NETWORK_INTERNAL_TCP_SECURE_TCP_SOCKET_H_
15#include <system_error>
19#include <asio/ssl.hpp>
49 using ssl_socket = asio::ssl::stream<asio::ip::tcp::socket>;
62 asio::ssl::context& ssl_context);
77 asio::ssl::stream_base::handshake_type type,
78 std::function<
void(std::error_code)> handler) -> void;
92 std::function<
void(
const std::vector<uint8_t>&)> callback) -> void;
127 std::function<
void(std::span<const uint8_t>)> callback) -> void;
165 std::vector<uint8_t>&& data,
166 std::function<
void(std::error_code, std::size_t)> handler) -> void;
178 auto socket() -> ssl_socket::lowest_layer_type&
195 auto close() -> void;
201 [[nodiscard]]
auto is_closed() const ->
bool;
221 std::array<uint8_t, 4096>
A lightweight wrapper around asio::ssl::stream<asio::ip::tcp::socket>, enabling asynchronous TLS/SSL ...
std::shared_ptr< receive_callback_view_t > receive_callback_view_
std::shared_ptr< error_callback_t > error_callback_
auto set_receive_callback(std::function< void(const std::vector< uint8_t > &)> callback) -> void
Sets a callback to receive inbound data chunks.
secure_tcp_socket(asio::ip::tcp::socket socket, asio::ssl::context &ssl_context)
Constructs a secure_tcp_socket by taking ownership of a moved socket and SSL context.
auto async_handshake(asio::ssl::stream_base::handshake_type type, std::function< void(std::error_code)> handler) -> void
Performs asynchronous SSL handshake.
auto close() -> void
Safely closes the socket and stops all async operations.
std::atomic< bool > is_reading_
auto stream() -> ssl_socket &
Provides direct access to the underlying SSL stream.
std::atomic< bool > is_closed_
asio::ssl::stream< asio::ip::tcp::socket > ssl_socket
std::mutex callback_mutex_
auto socket() -> ssl_socket::lowest_layer_type &
Provides access to the underlying TCP socket.
std::function< void(std::span< const uint8_t >)> receive_callback_view_t
auto start_read() -> void
Begins the continuous asynchronous read loop.
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type aliases for lock-free storage.
std::array< uint8_t, 4096 > read_buffer_
auto async_send(std::vector< uint8_t > &&data, std::function< void(std::error_code, std::size_t)> handler) -> void
Initiates an asynchronous write of the given data buffer with encryption.
auto do_read() -> void
Internal function to handle the read logic with async_read_some().
auto is_closed() const -> bool
Checks if the socket has been closed.
auto set_receive_callback_view(std::function< void(std::span< const uint8_t >)> callback) -> void
Sets a zero-copy callback to receive inbound data as a view.
std::function< void(std::error_code)> error_callback_t
auto set_error_callback(std::function< void(std::error_code)> callback) -> void
Sets a callback to handle socket errors (e.g., read/write failures).
std::shared_ptr< receive_callback_t > receive_callback_
auto stop_read() -> void
Stops the read loop to prevent further async operations.
~secure_tcp_socket()=default
Default destructor (no special cleanup needed).