58# pragma clang diagnostic push
59# pragma clang diagnostic ignored "-Wshadow"
66#include <boost/asio/deadline_timer.hpp>
72#include <boost/asio/io_context.hpp>
78#include <boost/asio/ip/tcp.hpp>
84#include <boost/asio/strand.hpp>
91# pragma clang diagnostic pop
131 :
public std::enable_shared_from_this<ServerSession>,
153 boost::asio::io_context &io_context,
189 template <
typename... Buffers>
193 "This function only accepts arguments of type BufferView.");
194 return std::make_shared<const Message>(buffers...);
200 void Write(std::shared_ptr<const Message> message);
206 template <
typename... Buffers>
227 void CloseNow(boost::system::error_code ec = boost::system::error_code());
包含 Carla 框架中与网络流相关的类和函数的声明。
stream_id_type get_stream_id() const
获取流ID。
boost::asio::deadline_timer _deadline
定时器,用于在会话超时后触发关闭操作。
void CloseNow(boost::system::error_code ec=boost::system::error_code())
立即关闭会话。
boost::asio::ip::tcp::socket socket_type
套接字类型别名。
Server & _server
对 Server 对象的引用。
ServerSession(boost::asio::io_context &io_context, time_duration timeout, Server &server)
构造函数。
void Open(callback_function_type on_opened, callback_function_type on_closed)
启动会话。
callback_function_type _on_closed
会话关闭时的回调函数。
boost::asio::io_context::strand _strand
用于保证异步操作顺序的 strand 对象。
socket_type _socket
套接字类型,用于网络通信。
stream_id_type _stream_id
流标识符,用于标识会话中传输的数据流。
static auto MakeMessage(Buffers... buffers)
创建消息。
const size_t _session_id
会话的唯一标识符。
std::function< void(std::shared_ptr< ServerSession >)> callback_function_type
回调函数类型别名。
void Write(Buffers... buffers)
向套接字写入一些数据(模板函数)。
time_duration _timeout
会话超时时长,表示会话在多长时间内无活动将被关闭。
bool _is_writing
表示当前是否正在进行写入操作的标志。
void Write(std::shared_ptr< const Message > message)
向套接字写入一些数据。
警告:在io_context停止之前,不能销毁这个服务器实例
Positive time duration up to milliseconds resolution.
uint32_t stream_id_type
流ID的类型定义。
std::shared_ptr< BufferView > SharedBufferView