|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
WebSocket服务器类 更多...
#include <websocket.hpp>
Public 类型 | |
| using | session_ptr = shared_ptr<websocket_session> |
| 会话智能指针类型 | |
| using | session_handler = function<void(session_ptr)> |
| 会话处理器类型 | |
Public 成员函数 | |
| void | set_io_context (io_context &ctx) noexcept |
| 设置异步 I/O 执行上下文 | |
| void | route (const string &path, session_handler handler) |
| 注册WebSocket路由 | |
| bool | handle_upgrade (const http_request &request, unique_ptr< tcp_socket > sock) |
| 处理WebSocket升级请求 | |
| void | remove_session (const session_ptr &session) |
| 移除会话 | |
| void | broadcast (const string &data, websocket_opcode opcode=websocket_opcode::TEXT) |
| 向所有会话广播消息 | |
| size_t | session_count () const noexcept |
| 获取活动会话数量 | |
WebSocket服务器类
管理WebSocket路由和会话,处理协议升级请求。
使用示例:
在文件 websocket.hpp 第 135 行定义.
| void neforce::http::websocket_server::broadcast | ( | const string & | data, |
| websocket_opcode | opcode = websocket_opcode::TEXT ) |
| bool neforce::http::websocket_server::handle_upgrade | ( | const http_request & | request, |
| unique_ptr< tcp_socket > | sock ) |
处理WebSocket升级请求
| request | HTTP升级请求 |
| sock | 已建立的TCP/SSL socket |
| void neforce::http::websocket_server::remove_session | ( | const session_ptr & | session | ) |
移除会话
| session | 要移除的会话 |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
设置异步 I/O 执行上下文
| ctx | io_context 引用 |
设置后,新创建的 WebSocket 会话将使用 io_context 驱动 I/O 替代默认的线程模式。
在文件 websocket.hpp 第 163 行定义.
引用了 set_io_context().
被这些函数引用 set_io_context().