ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
tools_sys.cpp File Reference

实现工具库中的系统和文件系统辅助函数 More...

#include "actor/actor_base/core/nguid.h"
#include "tools/tools/tools_thread.h"
#include "tools/tab/xml/sysconfig.h"
#include "tools/tools/tools_split.h"
#include "actor/tab/ttab_servers.h"
#include "tools/tools/tools_curl.h"
#include "tools/tools/tools_time.h"
#include "tools/tools/tools_sys.h"
#include <shared_mutex>
#include <system_error>
#include <filesystem>
#include <iostream>
#include <cstdlib>
#include <random>
#include <thread>
#include <chrono>
#include <memory>
#include <mutex>

Namespaces

namespace  ngl::tools
 工具函数命名空间。
namespace  ngl::tools::rand_detail
 随机数生成的内部实现命名空间
namespace  ngl::tools::mail_detail
 邮件发送的内部实现命名空间

Functions

uint64_t ngl::tools::rand_detail::splitmix64 (uint64_t ax)
 SplitMix64哈希函数
std::once_flag & ngl::tools::rand_detail::seed_once ()
 获取种子初始化的once_flag
std::atomic< uint64_t > & ngl::tools::rand_detail::seed_ctr ()
 获取原子种子计数器
uint64_t ngl::tools::rand_detail::make_seed ()
 生成初始随机种子
uint64_t ngl::tools::rand_detail::next_seed ()
 生成线程唯一的种子值
void ngl::tools::mail_detail::prune_mail (int32_t anow)
 清理过期的邮件记录
std::string ngl::tools::time2str (int autc, const char *aformat)
 将UTC时间戳转换为格式化字符串
const std::string & ngl::tools::server_name ()
 获取当前服务器名称
int ngl::tools::rand ()
 生成随机整数
bool ngl::tools::directories_exists (const std::string &apath)
 检查目录是否存在
bool ngl::tools::file_exists (const std::string &apath)
 检查文件是否存在
bool ngl::tools::create_dir (const std::string &apath)
 创建目录(包括父目录)
bool ngl::tools::file_remove (const std::string &afile)
 删除文件
void ngl::tools::dir (const std::string &apath, std::vector< std::string > &afiles, bool aiter)
 获取目录下的所有文件
void ngl::tools::no_core_dump (bool anocreate)
 终止程序(用于致命错误)
std::function< void()> ngl::tools::send_mail (const std::string &acontent, bool asynchronize)
 创建邮件发送函数
int64_t ngl::tools::nguidstr2int64 (const char *anguid)
 将GUID字符串转换为int64_t

Variables

std::map< std::string, int32_t > ngl::tools::mail_detail::g_mailmap
 邮件内容到发送时间的映射表
std::shared_mutex ngl::tools::mail_detail::g_maillock
 保护邮件映射表的读写锁
int32_t ngl::tools::mail_detail::g_mail_int = tools::time::MINUTES_SECOND * 10
 邮件发送间隔(秒),默认10分钟
constexpr std::size_t ngl::tools::mail_detail::g_mail_lim = 1024
 邮件映射表最大容量

Detailed Description

实现工具库中的系统和文件系统辅助函数

包含随机数生成、文件系统操作、邮件发送、GUID转换等功能 这些是系统级工具函数,被服务器核心模块广泛使用

Note
随机数生成使用线程本地存储确保线程安全