NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::ip_socket类 参考

IP协议族Socket基类 更多...

#include <ip_socket.hpp>

类 neforce::ip_socket 继承关系图:
[图例]

Public 成员函数

 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
virtual void connect (const ip_address &endpoint)
 连接到远程端点(TCP客户端)
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_baseoperator= (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< millisecondsget_send_timeout () const noexcept
 获取发送超时时间
bool set_send_timeout (milliseconds timeout) noexcept
 设置发送超时时间
optional< millisecondsget_receive_timeout () const noexcept
 获取接收超时时间
bool set_receive_timeout (milliseconds timeout) noexcept
 设置接收超时时间
optional< ip_addresslocal_endpoint () const
 获取本地端点地址
optional< ip_addressremote_endpoint () const
 获取远程端点地址
void bind (const ip_address &endpoint)
 绑定socket到本地地址
void listen (int backlog)
 开始监听连接(TCP)
native_handle_type release () noexcept
 释放socket所有权

Protected 属性

family family_ = family::UNDEF
 地址族
Protected 属性 继承自 neforce::socket_base
native_handle_type fd_ = invalid_handle
 Socket句柄
bool nonblocking_ {false}
 非阻塞模式状态跟踪

额外继承的成员函数

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
 无效句柄常量

详细描述

IP协议族Socket基类

继承自socket_base,专门用于IP协议族(IPv4/IPv6)的Socket操作。 增加了地址族约束、连接功能和地址族查询。

主要功能:

  • 地址族约束
  • IPv4/IPv6地址族检测
  • 连接操作
  • IP头结构定义
注解
此类是抽象基类,具体使用TCP或UDP时应使用tcp_socket或udp_socket。

在文件 ip_socket.hpp73 行定义.

构造及析构函数说明

◆ ip_socket()

neforce::ip_socket::ip_socket ( const native_handle_type fd)
inlineexplicitnoexcept

从原生句柄构造

参数
fd原生socket句柄

在文件 ip_socket.hpp89 行定义.

成员函数说明

◆ close()

bool neforce::ip_socket::close ( )
inlineoverridevirtualnoexcept

关闭socket

返回
关闭成功返回true

重置地址族为AF_UNSPEC,然后关闭socket。

重载 neforce::socket_base .

neforce::ssl_socket 重载.

在文件 ip_socket.hpp137 行定义.

引用了 neforce::socket_base::close() , 以及 family_.

◆ connect()

virtual void neforce::ip_socket::connect ( const ip_address & endpoint)
virtual

连接到远程端点(TCP客户端)

参数
endpoint远程IP地址和端口
异常
socket_exception连接失败时抛出
value_exceptionsocket未打开或端点无效时抛出

发起TCP连接到指定的远程服务器。 对于非阻塞socket,连接可能不会立即完成。

◆ is_ipv4()

bool neforce::ip_socket::is_ipv4 ( ) const
inlinenodiscardnoexcept

检查是否为IPv4 socket

返回
IPv4返回true

在文件 ip_socket.hpp112 行定义.

引用了 family_.

◆ is_ipv6()

bool neforce::ip_socket::is_ipv6 ( ) const
inlinenodiscardnoexcept

检查是否为IPv6 socket

返回
IPv6返回true

在文件 ip_socket.hpp118 行定义.

引用了 family_.


该类的文档由以下文件生成: