|
ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
|
每个帧TCP/KCP数据包前置的固定大小线路头部。 More...
#include <pack_head.h>
Public Member Functions | |
| pack_head () | |
| 默认构造函数。 | |
| void | set_mask () |
| 设置当前头部的掩码。 | |
| EPH_HEAD_VAL | check_mask () const |
| 验证当前头部的掩码。 | |
| void | set_time () |
| 设置当前头部的时间戳。 | |
| i32_time | get_time () const |
| 获取当前头部的时间戳。 | |
| void | set_actor (i64_actorid aactor, i64_actorid arequestactorid) |
| 设置当前头部的目标/源actor ID。 | |
| void | set_requestactor (i64_actorid arequestactorid) |
| 设置当前头部的源actor ID。 | |
| i64_actorid | get_actor () const |
| 从头部读取目标actor ID。 | |
| i64_actorid | get_request_actor () const |
| 从头部读取源actor ID。 | |
| i16_actortype | get_actortype () const |
| 打包的目标actor guid的便捷访问器。 | |
| i16_actortype | get_request_actortype () const |
| 打包的源actor guid的便捷访问器。 | |
| i16_area | get_actorarea () const |
| 目标actor区域/分片。 | |
| i32_actordataid | get_actordataid () const |
| 目标actor本地数值ID。 | |
| void | reset () |
| 清除部分读取状态和所有头部字段。 | |
| int32_t | getvalue (EPH aeph) const |
| 帧代码使用的原始槽位访问器。 | |
| int32_t | get_bytes () const |
| 声明的有效载荷字节数。 | |
| EPH_HEAD_VAL | isready () const |
| 报告掩码/头部是完整的、仍在接收中还是无效的。 | |
| i32_protocolnum | protocolnum () const |
| 头部中存储的协议号。 | |
| i32_protocolnum | get_protocolnumber () const |
| 为旧调用点保留的别名。 | |
| void | set_protocol (i32_protocolnum aprotocolnum) |
| 设置头部中存储的协议号。 | |
| EPH_HEAD_VAL | push (const char *&abuff, int32_t &alen) |
| 将数据推送到头部。 | |
| bool | push_format (ngl::ser::serialize_push *aserialize) const |
| 将头部数据推送到序列化器。 | |
| void | reservebuff (char *abuff, int abufflen, std::pair< char *, int32_t > &apair) |
| 当调用方需要可写的有效载荷区间时,跳过头部前缀。 | |
Static Public Member Functions | |
| static void | head_set_mask (int32_t *abuff) |
| 每个数据包前缀一个常量字节掩码,让接收方能够区分帧数据流量和临时telnet命令。 | |
| static EPH_HEAD_VAL | head_check_mask (const int32_t *abuff, int awpos) |
| 在头部流式传入时验证帧掩码。 | |
| static void | head_set_time (int32_t *abuff) |
| 将发送方的当前逻辑时间戳写入头部。 | |
| static i32_time | head_get_time (const int32_t *abuff) |
| 从头部读取发送方时间戳。 | |
| static void | head_set_actor (int32_t *abuff, i64_actorid aactor, i64_actorid arequestactorid) |
| 将目标/源actor ID写入头部。 | |
| static void | head_set_actor (int32_t *abuff, i64_actorid aactor) |
| 将目标actor ID写入头部。 | |
| static int32_t | size () |
| 返回固定的序列化头部大小(字节)。 | |
| static std::shared_ptr< pack_head > | make_pooled () |
| 从内存池分配一个pack_head对象。 | |
| static std::shared_ptr< pack_head > | make_pooled (const pack_head &other) |
| 从内存池分配一个pack_head对象,并拷贝其他对象的数据。 | |
Public Attributes | |
| int32_t | m_data [EPH_SUM] = {0} |
| 头部以原始int32槽位存储,可直接复制到网络缓冲区中,无需额外的序列化层。 | |
| int32_t | m_wpos = 0 |
| 当前写入位置,用于跟踪头部接收进度。 | |
每个帧TCP/KCP数据包前置的固定大小线路头部。
数据包头部结构体,用于在TCP/KCP传输中标记数据包边界、携带时间戳、目标/源actor ID等信息。 头部以原始int32槽位存储,可直接复制到网络缓冲区中,无需额外的序列化层。 包含掩码验证、时间戳管理、actor ID读写等功能。
| ngl::pack_head::pack_head | ( | ) |
默认构造函数。
初始化写入位置为0,头部数据清零。
初始化数据包头部,将写入位置设置为0。
| EPH_HEAD_VAL ngl::pack_head::check_mask | ( | ) | const |
验证当前头部的掩码。
检查数据包头部的掩码。
调用head_check_mask验证m_data的掩码字段。
验证数据包头部的前m_wpos个字节是否为掩码值。
| i64_actorid ngl::pack_head::get_actor | ( | ) | const |
从头部读取目标actor ID。
获取发送方Actor ID。
| i16_area ngl::pack_head::get_actorarea | ( | ) | const |
目标actor区域/分片。
获取发送方Actor区域。
| i32_actordataid ngl::pack_head::get_actordataid | ( | ) | const |
目标actor本地数值ID。
获取发送方Actor数据ID。
| i16_actortype ngl::pack_head::get_actortype | ( | ) | const |
打包的目标actor guid的便捷访问器。
获取发送方Actor类型。
| int32_t ngl::pack_head::get_bytes | ( | ) | const |
声明的有效载荷字节数。
获取消息体字节数。
| i32_protocolnum ngl::pack_head::get_protocolnumber | ( | ) | const |
为旧调用点保留的别名。
获取协议号(别名)。
| i64_actorid ngl::pack_head::get_request_actor | ( | ) | const |
从头部读取源actor ID。
获取请求方Actor ID。
| i16_actortype ngl::pack_head::get_request_actortype | ( | ) | const |
打包的源actor guid的便捷访问器。
获取请求方Actor类型。
| i32_time ngl::pack_head::get_time | ( | ) | const |
获取当前头部的时间戳。
获取数据包时间戳。
调用head_get_time获取m_data的时间戳字段。
| int32_t ngl::pack_head::getvalue | ( | EPH | aeph | ) | const |
帧代码使用的原始槽位访问器。
获取指定偏移量的值。
| aeph | 头部字段枚举值。 |
| aeph | 偏移量(EPH枚举值) |
|
static |
在头部流式传入时验证帧掩码。
检查数据包头部缓冲区的掩码。
| abuff | 头部数据缓冲区指针。 |
| awpos | 当前写入位置。 |
验证数据包头部缓冲区的前awpos个字节是否为掩码值。
| abuff | 数据包头部缓冲区指针 |
| awpos | 要检查的字节数 |
|
static |
从头部读取发送方时间戳。
从数据包头部缓冲区获取时间戳。
| abuff | 头部数据缓冲区指针。 |
| abuff | 数据包头部缓冲区指针 |
|
static |
将目标actor ID写入头部。
设置发送方Actor ID到数据包头部缓冲区。
| abuff | 头部数据缓冲区指针。 |
| aactor | 目标actor ID。 |
仅设置发送方的Actor ID到指定的数据包头部缓冲区中。
| abuff | 数据包头部缓冲区指针 |
| aactor | 发送方Actor ID |
|
static |
将目标/源actor ID写入头部。
设置Actor ID到数据包头部缓冲区。
| abuff | 头部数据缓冲区指针。 |
| aactor | 目标actor ID。 |
| arequestactorid | 源actor ID。 |
将发送方和请求方的Actor ID设置到指定的数据包头部缓冲区中。
| abuff | 数据包头部缓冲区指针 |
| aactor | 发送方Actor ID |
| arequestactorid | 请求方Actor ID |
|
static |
每个数据包前缀一个常量字节掩码,让接收方能够区分帧数据流量和临时telnet命令。
设置数据包头部缓冲区的掩码。
| abuff | 头部数据缓冲区指针。 |
将数据包头部缓冲区的前EPH_MASK_COUNT_BYTES个字节设置为掩码值。 掩码用于验证数据包头部的完整性。
| abuff | 数据包头部缓冲区指针 |
|
static |
将发送方的当前逻辑时间戳写入头部。
设置数据包头部缓冲区的时间戳。
| abuff | 头部数据缓冲区指针。 |
将当前系统时间设置到指定的数据包头部缓冲区中。
| abuff | 数据包头部缓冲区指针 |
| EPH_HEAD_VAL ngl::pack_head::isready | ( | ) | const |
报告掩码/头部是完整的、仍在接收中还是无效的。
检查数据包头部是否就绪。
验证数据包头部是否已完全接收并验证通过。
|
static |
从内存池分配一个pack_head对象。
从内存池创建数据包头部。
从pack_head_pool中分配内存并创建数据包头部实例。 使用自定义删除器确保正确释放内存。
从内存池分配一个pack_head对象,并拷贝其他对象的数据。
从内存池创建数据包头部(拷贝构造)。
| other | 要拷贝的pack_head对象。 |
从pack_head_pool中分配内存并创建数据包头部实例,使用拷贝构造。 使用自定义删除器确保正确释放内存。
| other | 要拷贝的数据包头部 |
| i32_protocolnum ngl::pack_head::protocolnum | ( | ) | const |
头部中存储的协议号。
获取协议号。
| EPH_HEAD_VAL ngl::pack_head::push | ( | const char *& | abuff, |
| int32_t & | alen ) |
将数据推送到头部。
推送数据到数据包头部。
| abuff | 数据缓冲区指针,会被更新为已处理的数据位置。 |
| alen | 数据长度,会被更新为剩余未处理的数据长度。 |
将接收到的数据推送到数据包头部缓冲区中。 头部可能跨多次socket读取分片到达。
| abuff | 数据指针(引用,会更新位置) |
| alen | 数据长度(引用,会更新) |
| bool ngl::pack_head::push_format | ( | ngl::ser::serialize_push * | aserialize | ) | const |
将头部数据推送到序列化器。
序列化数据包头部。
| aserialize | 序列化器指针。 |
将数据包头部数据序列化到指定的序列化器中。
| aserialize | 序列化器指针 |
| void ngl::pack_head::reservebuff | ( | char * | abuff, |
| int | abufflen, | ||
| std::pair< char *, int32_t > & | apair ) |
当调用方需要可写的有效载荷区间时,跳过头部前缀。
预留消息体缓冲区。
| abuff | 数据缓冲区指针。 |
| abufflen | 数据缓冲区长度。 |
| apair | 输出参数,包含有效载荷区间指针和长度。 |
在固定大小的数据包头部之后预留消息体区间。
| abuff | 缓冲区指针 |
| abufflen | 缓冲区总长度 |
| apair | 输出参数:消息体区间指针和长度 |
| void ngl::pack_head::reset | ( | ) |
清除部分读取状态和所有头部字段。
重置数据包头部。
将m_data清零,m_wpos重置为0。
将数据包头部的所有数据清零,并将写入位置重置为0。
| void ngl::pack_head::set_actor | ( | i64_actorid | aactor, |
| i64_actorid | arequestactorid ) |
设置当前头部的目标/源actor ID。
设置Actor ID。
| aactor | 目标actor ID。 |
| arequestactorid | 源actor ID。 |
设置数据包的发送方和请求方Actor ID。
| aactor | 发送方Actor ID |
| arequestactorid | 请求方Actor ID |
| void ngl::pack_head::set_mask | ( | ) |
设置当前头部的掩码。
设置数据包头部的掩码。
调用head_set_mask设置m_data的掩码字段。
将数据包头部的前EPH_MASK_COUNT_BYTES个字节设置为掩码值。
| void ngl::pack_head::set_protocol | ( | i32_protocolnum | aprotocolnum | ) |
设置头部中存储的协议号。
设置协议号。
| aprotocolnum | 协议号。 |
| aprotocolnum | 协议号 |
| void ngl::pack_head::set_requestactor | ( | i64_actorid | arequestactor | ) |
设置当前头部的源actor ID。
设置请求方Actor ID。
| arequestactorid | 源actor ID。 |
仅设置数据包的请求方Actor ID。
| arequestactor | 请求方Actor ID |
| void ngl::pack_head::set_time | ( | ) |
设置当前头部的时间戳。
设置数据包时间戳。
调用head_set_time设置m_data的时间戳字段。
将当前系统时间设置到数据包头部中。
|
static |
返回固定的序列化头部大小(字节)。
获取数据包头部大小。
| int32_t ngl::pack_head::m_data[EPH_SUM] = {0} |
头部以原始int32槽位存储,可直接复制到网络缓冲区中,无需额外的序列化层。
存储头部所有字段的原始int32数组,大小为EPH_SUM。
| int32_t ngl::pack_head::m_wpos = 0 |
当前写入位置,用于跟踪头部接收进度。
在流式接收头部时,记录已写入的字节数。