|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
SSL/TLS服务器Acceptor类 更多...
#include <ssl_acceptor.hpp>
Public 成员函数 | |
| ssl_acceptor ()=default | |
| 默认构造函数 | |
| void | set_ssl_context (ssl_context ctx) |
| 设置SSL上下文 | |
| ssl_context & | context () noexcept |
| 获取SSL上下文引用 | |
| const ssl_context & | context () const noexcept |
| 获取SSL上下文常量引用 | |
| ssl_socket | accept_ssl () |
| 接受TLS客户端连接 | |
| optional< ssl_socket > | accept_ssl_nonblock () |
| 非阻塞接受TLS客户端连接 | |
| Public 成员函数 继承自 neforce::tcp_acceptor | |
| tcp_acceptor ()=default | |
| 默认构造函数 | |
| void | open (const ip_address &endpoint, int backlog=SOMAXCONN) |
| 打开并开始监听 | |
| tcp_socket | accept () |
| 接受客户端连接(阻塞模式) | |
| optional< tcp_socket > | accept_nonblock () |
| 接受客户端连接(非阻塞模式) | |
| void | async_accept (io_context &ctx, function< void(error_code, tcp_socket)> handler) |
| 异步接受客户端连接 | |
| void | async_accept (io_context &ctx, cancellation_slot &slot, function< void(error_code, tcp_socket)> handler) |
| 异步接受连接(带取消槽) | |
| template<typename Token, enable_if_t<!is_same_v< decay_t< Token >, function< void(error_code, tcp_socket)> >, int > = 0> | |
| void | async_accept (io_context &ctx, Token &&token) |
| 异步接受—任意可调用对象 | |
| decltype(auto) | async_accept (io_context &ctx, use_future_t) |
| 异步接受—use_future | |
| void | async_accept (io_context &ctx, detached_t) |
| 异步接受—detached(即发即忘) | |
| decltype(auto) | async_accept (io_context &ctx, use_awaitable_t) |
| 异步接受—use_awaitable | |
| void | open (family f, type t=type::STREAM, protocol p=protocol::AUTO) |
| 打开socket | |
| Public 成员函数 继承自 neforce::ip_socket | |
| ip_socket ()=default | |
| 默认构造函数 | |
| ip_socket (const native_handle_type fd) noexcept | |
| 从原生句柄构造 | |
| ~ip_socket () override=default | |
| 析构函数 | |
| family | address_family () const noexcept |
| 获取地址族 | |
| bool | is_ipv4 () const noexcept |
| 检查是否为IPv4 socket | |
| bool | is_ipv6 () const noexcept |
| 检查是否为IPv6 socket | |
| bool | close () noexcept override |
| 关闭socket | |
| Public 成员函数 继承自 neforce::socket_base | |
| socket_base () | |
| 默认构造函数 | |
| socket_base (const native_handle_type fd) noexcept | |
| 从原生句柄构造 | |
| socket_base (socket_base &&other) noexcept | |
| 移动构造函数 | |
| socket_base & | operator= (socket_base &&other) noexcept |
| 移动赋值运算符 | |
| virtual | ~socket_base () |
| 析构函数 | |
| native_handle_type | native_handle () const noexcept |
| 获取原生句柄 | |
| bool | is_open () const noexcept |
| 检查socket是否已打开 | |
| operator bool () const noexcept | |
| 布尔转换运算符 | |
| void | open (family f, type t=type::STREAM, protocol p=protocol::AUTO) |
| 打开socket | |
| bool | try_open (family f, type t=type::STREAM, protocol p=protocol::AUTO) noexcept |
| 尝试打开socket | |
| bool | is_nonblocking () const noexcept |
| 查询是否为非阻塞模式 | |
| bool | set_nonblocking (bool enable) noexcept |
| 设置非阻塞模式 | |
| bool | shutdown_send () noexcept |
| 关闭发送方向 | |
| bool | shutdown_receive () noexcept |
| 关闭接收方向 | |
| bool | shutdown_both () noexcept |
| 关闭双向通信 | |
| bool | set_option (int level, int optname, const void *value, ::socklen_t len) noexcept |
| 设置socket选项 | |
| bool | get_option (int level, int optname, void *optval, ::socklen_t *optlen) const noexcept |
| 获取socket选项 | |
| bool | get_reuse_address () const noexcept |
| 查询地址重用 | |
| bool | set_reuse_address (bool enable=true) noexcept |
| 设置地址重用 | |
| bool | get_reuse_port () const noexcept |
| 查询端口重用 | |
| bool | set_reuse_port (bool enable=true) noexcept |
| 设置端口重用 | |
| bool | get_keep_alive () const noexcept |
| 查询TCP KeepAlive | |
| bool | set_keep_alive (bool enable=true) noexcept |
| 设置TCP KeepAlive | |
| bool | get_tcp_nodelay () const noexcept |
| 查询Nagle算法 | |
| bool | set_tcp_nodelay (bool enable=true) noexcept |
| 设置禁用Nagle算法 | |
| int | get_receive_buffer_size () const noexcept |
| 查询接收缓冲区大小 | |
| bool | set_receive_buffer_size (int size) noexcept |
| 设置接收缓冲区大小 | |
| int | get_send_buffer_size () const noexcept |
| 查询发送缓冲区大小 | |
| bool | set_send_buffer_size (int size) noexcept |
| 设置发送缓冲区大小 | |
| optional< milliseconds > | get_send_timeout () const noexcept |
| 获取发送超时时间 | |
| bool | set_send_timeout (milliseconds timeout) noexcept |
| 设置发送超时时间 | |
| optional< milliseconds > | get_receive_timeout () const noexcept |
| 获取接收超时时间 | |
| bool | set_receive_timeout (milliseconds timeout) noexcept |
| 设置接收超时时间 | |
| optional< ip_address > | local_endpoint () const |
| 获取本地端点地址 | |
| optional< ip_address > | remote_endpoint () const |
| 获取远程端点地址 | |
| void | bind (const ip_address &endpoint) |
| 绑定socket到本地地址 | |
| void | listen (int backlog) |
| 开始监听连接(TCP) | |
| native_handle_type | release () noexcept |
| 释放socket所有权 | |
额外继承的成员函数 | |
| Public 类型 继承自 neforce::socket_base | |
| enum class | type : int32_t { STREAM = SOCK_STREAM , DGRAM = SOCK_DGRAM , RAW = SOCK_RAW , RDM = SOCK_RDM , SEQPACKET = SOCK_SEQPACKET , CLOEXEC = SOCK_CLOEXEC , NONBLOCK = SOCK_NONBLOCK , DCCP = SOCK_DCCP } |
| socket 类型枚举 更多... | |
| enum class | protocol : int32_t { AUTO = 0 , ICMP = IPPROTO_ICMP , TCP = IPPROTO_TCP , UDP = IPPROTO_UDP , SCTP = IPPROTO_SCTP , RAW = IPPROTO_RAW , ESP = IPPROTO_ESP , AH = IPPROTO_AH , DCCP = IPPROTO_DCCP , IP = ETH_P_IP , ARP = ETH_P_ARP , IPV6 = ETH_P_IPV6 , LAT = ETH_P_LAT , VLAN = ETH_P_8021Q , LLDP = ETH_P_LLDP , MPLS = ETH_P_MPLS_UC } |
| socket 协议枚举 更多... | |
| using | native_handle_type |
| 平台原生句柄类型 | |
| using | family = ip_address::family |
| 网络地址族类型 | |
| 静态 Public 属性 继承自 neforce::socket_base | |
| static constexpr native_handle_type | invalid_handle |
| 无效句柄常量 | |
| Protected 属性 继承自 neforce::ip_socket | |
| family | family_ = family::UNDEF |
| 地址族 | |
| Protected 属性 继承自 neforce::socket_base | |
| native_handle_type | fd_ = invalid_handle |
| Socket句柄 | |
| bool | nonblocking_ {false} |
| 非阻塞模式状态跟踪 | |
SSL/TLS服务器Acceptor类
实现SSL/TLS服务器的连接接受功能,继承自tcp_acceptor。 自动为每个接受的连接完成SSL/TLS握手,返回加密的ssl_socket。
使用示例:
在文件 ssl_acceptor.hpp 第 77 行定义.
|
nodiscard |
接受TLS客户端连接
| socket_exception | 接受连接失败时抛出 |
| ssl_exception | SSL握手失败时抛出 |
| value_exception | acceptor未打开或SSL上下文无效时抛出 |
|
nodiscard |
非阻塞接受TLS客户端连接
| socket_exception | 发生错误时抛出 |
| ssl_exception | SSL握手失败时抛出 |
非阻塞地尝试接受新的TLS连接并完成握手。 如果没有待处理的TCP连接,立即返回none。 需要先设置acceptor为非阻塞模式。
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
| void neforce::ssl_acceptor::set_ssl_context | ( | ssl_context | ctx | ) |