change:改为clangd引擎。
This commit is contained in:
parent
13423d5172
commit
a81cc54025
@ -6,20 +6,12 @@ BreakBeforeBraces: Custom
|
|||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterFunction: true
|
AfterFunction: true
|
||||||
AfterClass: true
|
AfterClass: true
|
||||||
AfterLambdaBody: false
|
|
||||||
BeforeLambdaBody: false
|
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
ReflowComments: true
|
ReflowComments: true
|
||||||
SpacesBeforeTrailingComments: 3
|
SpacesBeforeTrailingComments: 3
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
ColumnLimit: 110
|
ColumnLimit: 130
|
||||||
AllowShortBlocksOnASingleLine: Never
|
AllowShortBlocksOnASingleLine: Never
|
||||||
AllowShortFunctionsOnASingleLine: None
|
AllowShortFunctionsOnASingleLine: None
|
||||||
AllowShortEnumsOnASingleLine: false
|
AllowShortEnumsOnASingleLine: false
|
||||||
IncludeBlocks: Regroup
|
|
||||||
IncludeCategories:
|
|
||||||
- Regex: '^<.*>'
|
|
||||||
Priority: 1
|
|
||||||
- Regex: '^".*"'
|
|
||||||
Priority: 2
|
|
135
.clang-tidy
Normal file
135
.clang-tidy
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
Checks: "-*,
|
||||||
|
|
||||||
|
clang-*,
|
||||||
|
|
||||||
|
google-build-explicit-make-pair,
|
||||||
|
google-build-namespaces,
|
||||||
|
google-default-arguments,
|
||||||
|
google-explicit-constructor,
|
||||||
|
google-readability-avoid-underscore-in-googletest-name,
|
||||||
|
google-runtime-int,
|
||||||
|
google-runtime-operator,
|
||||||
|
|
||||||
|
|
||||||
|
-readability-non-const-parameter,
|
||||||
|
readability-avoid-const-params-in-decls,
|
||||||
|
readability-const-return-type,
|
||||||
|
readability-container-size-empty,
|
||||||
|
-readability-convert-member-functions-to-static,
|
||||||
|
readability-delete-null-pointer,
|
||||||
|
readability-deleted-default,
|
||||||
|
readability-make-member-function-const,
|
||||||
|
readability-misplaced-array-index,
|
||||||
|
readability-qualified-auto,
|
||||||
|
readability-redundant-control-flow,
|
||||||
|
readability-redundant-function-ptr-dereference,
|
||||||
|
readability-redundant-smartptr-get,
|
||||||
|
readability-redundant-string-cstr,
|
||||||
|
readability-static-definition-in-anonymous-namespace,
|
||||||
|
readability-string-compare,
|
||||||
|
readability-uniqueptr-delete-release,
|
||||||
|
readability-redundant-member-init,
|
||||||
|
readability-simplify-subscript-expr,
|
||||||
|
readability-simplify-boolean-expr,
|
||||||
|
readability-inconsistent-declaration-parameter-name,
|
||||||
|
|
||||||
|
cert-dcl21-cpp,
|
||||||
|
cert-dcl50-cpp,
|
||||||
|
# 不要使用 system()
|
||||||
|
-cert-env33-c,
|
||||||
|
cert-err34-c,
|
||||||
|
cert-err52-cpp,
|
||||||
|
cert-flp30-c,
|
||||||
|
cert-mem57-cpp,
|
||||||
|
cert-msc50-cpp,
|
||||||
|
cert-oop58-cpp,
|
||||||
|
|
||||||
|
modernize-avoid-bind,
|
||||||
|
modernize-deprecated-headers,
|
||||||
|
modernize-loop-convert,
|
||||||
|
modernize-make-shared,
|
||||||
|
modernize-make-unique,
|
||||||
|
-modernize-pass-by-value,
|
||||||
|
modernize-raw-string-literal,
|
||||||
|
modernize-redundant-void-arg,
|
||||||
|
modernize-replace-auto-ptr,
|
||||||
|
modernize-shrink-to-fit,
|
||||||
|
modernize-use-bool-literals,
|
||||||
|
modernize-use-emplace,
|
||||||
|
modernize-use-equals-delete,
|
||||||
|
modernize-use-nullptr,
|
||||||
|
modernize-use-override,
|
||||||
|
|
||||||
|
cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
|
-cppcoreguidelines-narrowing-conversions,
|
||||||
|
cppcoreguidelines-pro-type-member-init,
|
||||||
|
|
||||||
|
misc-unconventional-assign-operator,
|
||||||
|
-misc-unused-parameters,
|
||||||
|
misc-throw-by-value-catch-by-reference,
|
||||||
|
misc-misplaced-const,
|
||||||
|
misc-redundant-expression,
|
||||||
|
misc-static-assert,
|
||||||
|
misc-uniqueptr-reset-release,
|
||||||
|
-misc-unused-alias-decls,
|
||||||
|
-misc-unused-using-decls,
|
||||||
|
|
||||||
|
bugprone-undelegated-constructor,
|
||||||
|
bugprone-macro-parentheses,
|
||||||
|
bugprone-macro-repeated-side-effects,
|
||||||
|
bugprone-forward-declaration-namespace,
|
||||||
|
bugprone-bool-pointer-implicit-conversion,
|
||||||
|
bugprone-misplaced-widening-cast,
|
||||||
|
bugprone-argument-comment,
|
||||||
|
bugprone-bad-signal-to-kill-thread,
|
||||||
|
bugprone-copy-constructor-init,
|
||||||
|
bugprone-dangling-handle,
|
||||||
|
bugprone-fold-init-type,
|
||||||
|
bugprone-inaccurate-erase,
|
||||||
|
bugprone-incorrect-roundings,
|
||||||
|
bugprone-integer-division,
|
||||||
|
bugprone-misplaced-operator-in-strlen-in-alloc,
|
||||||
|
bugprone-misplaced-pointer-arithmetic-in-alloc,
|
||||||
|
bugprone-move-forwarding-reference,
|
||||||
|
bugprone-multiple-statement-macro,
|
||||||
|
bugprone-parent-virtual-call,
|
||||||
|
bugprone-posix-return,
|
||||||
|
bugprone-reserved-identifier,
|
||||||
|
bugprone-signed-char-misuse,
|
||||||
|
bugprone-sizeof-container,
|
||||||
|
bugprone-sizeof-expression,
|
||||||
|
bugprone-string-constructor,
|
||||||
|
bugprone-string-integer-assignment,
|
||||||
|
bugprone-string-literal-with-embedded-nul,
|
||||||
|
bugprone-suspicious-enum-usage,
|
||||||
|
bugprone-suspicious-include,
|
||||||
|
bugprone-suspicious-memset-usage,
|
||||||
|
bugprone-suspicious-missing-comma,
|
||||||
|
bugprone-suspicious-string-compare,
|
||||||
|
bugprone-swapped-arguments,
|
||||||
|
bugprone-terminating-continue,
|
||||||
|
bugprone-throw-keyword-missing,
|
||||||
|
bugprone-too-small-loop-variable,
|
||||||
|
bugprone-undefined-memory-manipulation,
|
||||||
|
bugprone-unhandled-self-assignment,
|
||||||
|
bugprone-unused-raii,
|
||||||
|
bugprone-unused-return-value,
|
||||||
|
bugprone-use-after-move,
|
||||||
|
bugprone-virtual-near-miss,
|
||||||
|
|
||||||
|
hicpp-exception-baseclass,
|
||||||
|
hicpp-ignored-remove-result,
|
||||||
|
hicpp-no-assembler,
|
||||||
|
-hicpp-signed-bitwise,
|
||||||
|
|
||||||
|
performance-faster-string-find,
|
||||||
|
performance-for-range-copy,
|
||||||
|
performance-implicit-conversion-in-loop,
|
||||||
|
performance-inefficient-algorithm,
|
||||||
|
performance-inefficient-vector-operation,
|
||||||
|
performance-move-constructor-init,
|
||||||
|
performance-no-automatic-move,
|
||||||
|
-performance-trivially-destructible,
|
||||||
|
performance-unnecessary-copy-initialization'
|
||||||
|
|
||||||
|
WarningsAsErrors: "*"
|
9
.clangd
Normal file
9
.clangd
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Hover:
|
||||||
|
ShowAKA: true
|
||||||
|
Diagnostics:
|
||||||
|
UnusedIncludes: None # 禁用未使用头文件提示
|
||||||
|
Suppress:
|
||||||
|
- anon_type_definition # 禁用匿名的typedef提示
|
||||||
|
- unused-variable # 禁用未使用变量提示
|
||||||
|
- unused-function # 禁用未使用函数提示
|
||||||
|
- unused-includes # 禁用未使用的头文件提示
|
152
.vscode/settings.json
vendored
152
.vscode/settings.json
vendored
@ -1,10 +1,6 @@
|
|||||||
{
|
{
|
||||||
"files.autoSave": "onFocusChange",
|
"files.autoSave": "onFocusChange",
|
||||||
"editor.fontSize": 14,
|
"editor.fontSize": 14,
|
||||||
"editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
|
|
||||||
"terminal.integrated.fontFamily": "Source Code Pro",
|
|
||||||
"editor.fontLigatures": true,
|
|
||||||
//"C_Cpp.default.configurationProvider": "tboox.xmake-vscode",
|
|
||||||
"cmake.configureOnOpen": true,
|
"cmake.configureOnOpen": true,
|
||||||
"cmake.debugConfig": {
|
"cmake.debugConfig": {
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
@ -19,147 +15,33 @@
|
|||||||
"ignoreFailures": true
|
"ignoreFailures": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis",
|
|
||||||
"args": [
|
"args": [
|
||||||
//"-u", "0"
|
"9999"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"cmake.environment": {
|
"cmake.configureSettings": {
|
||||||
"PATH": "${env:PATH};"
|
//"CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||||
},
|
},
|
||||||
"cmake.configureArgs": [
|
|
||||||
"-Wno-dev",
|
|
||||||
"-DCMAKE_PREFIX_PATH:STRING=C:/dev/wxwigets",
|
|
||||||
"-DUSE_GUI=ON",
|
|
||||||
"-DUSE_TRANSM_TEST=ON"
|
|
||||||
],
|
|
||||||
"cmake.options.statusBarVisibility": "visible",
|
"cmake.options.statusBarVisibility": "visible",
|
||||||
"cmake.generator": "Ninja",
|
"cmake.generator": "Ninja",
|
||||||
"cmake.ctestArgs": ["-V"],
|
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||||
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
|
|
||||||
"C_Cpp.default.cppStandard": "c++17",
|
|
||||||
"editor.inlayHints.enabled": "off",
|
"editor.inlayHints.enabled": "off",
|
||||||
"editor.unicodeHighlight.allowedLocales": {
|
"editor.unicodeHighlight.allowedLocales": {
|
||||||
"ja": true,
|
"ja": true,
|
||||||
"zh-hant": true,
|
"zh-hant": true,
|
||||||
"zh-hans": true
|
"zh-hans": true
|
||||||
},
|
},
|
||||||
"files.associations": {
|
"C_Cpp.intelliSenseEngine": "disabled",
|
||||||
"xstring": "cpp",
|
"clangd.arguments": [
|
||||||
"vector": "cpp",
|
"--header-insertion=never",
|
||||||
"string": "cpp",
|
"--all-scopes-completion",
|
||||||
"algorithm": "cpp",
|
"--completion-style=detailed",
|
||||||
"any": "cpp",
|
"-j=4",
|
||||||
"array": "cpp",
|
"--clang-tidy",
|
||||||
"atomic": "cpp",
|
"--pch-storage=memory",
|
||||||
"bitset": "cpp",
|
"--compile-commands-dir=build",
|
||||||
"cctype": "cpp",
|
"--background-index",
|
||||||
"chrono": "cpp",
|
"--ranking-model=heuristics",
|
||||||
"cinttypes": "cpp",
|
"--function-arg-placeholders=false"
|
||||||
"clocale": "cpp",
|
],
|
||||||
"cmath": "cpp",
|
|
||||||
"codecvt": "cpp",
|
|
||||||
"complex": "cpp",
|
|
||||||
"condition_variable": "cpp",
|
|
||||||
"csignal": "cpp",
|
|
||||||
"cstdarg": "cpp",
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"cstdint": "cpp",
|
|
||||||
"cstdio": "cpp",
|
|
||||||
"cstdlib": "cpp",
|
|
||||||
"cstring": "cpp",
|
|
||||||
"ctime": "cpp",
|
|
||||||
"cwchar": "cpp",
|
|
||||||
"cwctype": "cpp",
|
|
||||||
"deque": "cpp",
|
|
||||||
"exception": "cpp",
|
|
||||||
"filesystem": "cpp",
|
|
||||||
"forward_list": "cpp",
|
|
||||||
"fstream": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"future": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"iomanip": "cpp",
|
|
||||||
"ios": "cpp",
|
|
||||||
"iosfwd": "cpp",
|
|
||||||
"iostream": "cpp",
|
|
||||||
"istream": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"limits": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"locale": "cpp",
|
|
||||||
"map": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"mutex": "cpp",
|
|
||||||
"new": "cpp",
|
|
||||||
"numeric": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"ostream": "cpp",
|
|
||||||
"queue": "cpp",
|
|
||||||
"random": "cpp",
|
|
||||||
"ratio": "cpp",
|
|
||||||
"set": "cpp",
|
|
||||||
"shared_mutex": "cpp",
|
|
||||||
"sstream": "cpp",
|
|
||||||
"stdexcept": "cpp",
|
|
||||||
"streambuf": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"strstream": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"thread": "cpp",
|
|
||||||
"tuple": "cpp",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"typeindex": "cpp",
|
|
||||||
"typeinfo": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"utility": "cpp",
|
|
||||||
"valarray": "cpp",
|
|
||||||
"variant": "cpp",
|
|
||||||
"xfacet": "cpp",
|
|
||||||
"xhash": "cpp",
|
|
||||||
"xiosbase": "cpp",
|
|
||||||
"xlocale": "cpp",
|
|
||||||
"xlocbuf": "cpp",
|
|
||||||
"xlocinfo": "cpp",
|
|
||||||
"xlocmes": "cpp",
|
|
||||||
"xlocmon": "cpp",
|
|
||||||
"xlocnum": "cpp",
|
|
||||||
"xloctime": "cpp",
|
|
||||||
"xmemory": "cpp",
|
|
||||||
"xmemory0": "cpp",
|
|
||||||
"xstddef": "cpp",
|
|
||||||
"xtr1common": "cpp",
|
|
||||||
"xtree": "cpp",
|
|
||||||
"xutility": "cpp",
|
|
||||||
"qbytearray": "cpp",
|
|
||||||
"*.ipp": "cpp",
|
|
||||||
"xthread": "cpp",
|
|
||||||
"*.tcc": "cpp",
|
|
||||||
"regex": "cpp",
|
|
||||||
"bit": "cpp",
|
|
||||||
"memory_resource": "cpp",
|
|
||||||
"source_location": "cpp",
|
|
||||||
"charconv": "cpp",
|
|
||||||
"compare": "cpp",
|
|
||||||
"concepts": "cpp",
|
|
||||||
"coroutine": "cpp",
|
|
||||||
"format": "cpp",
|
|
||||||
"stop_token": "cpp",
|
|
||||||
"expected": "cpp",
|
|
||||||
"numbers": "cpp",
|
|
||||||
"semaphore": "cpp",
|
|
||||||
"span": "cpp",
|
|
||||||
"text_encoding": "cpp",
|
|
||||||
"*.in": "cpp",
|
|
||||||
"hash_map": "cpp",
|
|
||||||
"stdfloat": "cpp",
|
|
||||||
"unordered_set": "cpp",
|
|
||||||
"cfenv": "cpp",
|
|
||||||
"cassert": "cpp",
|
|
||||||
"version": "cpp",
|
|
||||||
"resumable": "cpp",
|
|
||||||
"stack": "cpp"
|
|
||||||
},
|
|
||||||
"makefile.configureOnOpen": false,
|
|
||||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ set(PROJECT_URL "https://www.sinxmiao.cn/taynpg/transm")
|
|||||||
set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
|
set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_compile_options(/source-charset:utf-8)
|
add_compile_options(/source-charset:utf-8)
|
||||||
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 2a59b1066a076fc27157992aa4adbe39d2758cb5
|
Subproject commit 4b6612cc63f21b4d092a0b5731ceb7f817f20d23
|
@ -82,7 +82,7 @@ void TransmServer::get_client_list(CMessageInfo& msg_info)
|
|||||||
std::string online_time;
|
std::string online_time;
|
||||||
std::string uuid;
|
std::string uuid;
|
||||||
std::string task;
|
std::string task;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp{};
|
||||||
};
|
};
|
||||||
std::vector<TmpInfo> vec;
|
std::vector<TmpInfo> vec;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
@ -101,8 +101,7 @@ void TransmServer::get_client_list(CMessageInfo& msg_info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 排序 vec 根据 client->timestamp
|
// 排序 vec 根据 client->timestamp
|
||||||
std::sort(vec.begin(), vec.end(),
|
std::sort(vec.begin(), vec.end(), [](const TmpInfo& a, const TmpInfo& b) { return a.timestamp < b.timestamp; });
|
||||||
[](const TmpInfo& a, const TmpInfo& b) { return a.timestamp < b.timestamp; });
|
|
||||||
|
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (const auto& item : vec) {
|
for (const auto& item : vec) {
|
||||||
@ -190,8 +189,7 @@ void TransmServer::trans_data(CFrameBuffer* buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransmServer::check_double(CFrameBuffer* buf, std::shared_ptr<ClientCache>& fcli,
|
bool TransmServer::check_double(CFrameBuffer* buf, std::shared_ptr<ClientCache>& fcli, std::shared_ptr<ClientCache>& tcli)
|
||||||
std::shared_ptr<ClientCache>& tcli)
|
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_mutex> lock(cli_mut_);
|
std::shared_lock<std::shared_mutex> lock(cli_mut_);
|
||||||
if (client_map_.count(buf->fid_)) {
|
if (client_map_.count(buf->fid_)) {
|
||||||
@ -255,8 +253,7 @@ void TransmServer::accept_client()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransmServer::th_client(const std::shared_ptr<asio::ip::tcp::socket>& socket,
|
void TransmServer::th_client(const std::shared_ptr<asio::ip::tcp::socket>& socket, const std::string& client_key)
|
||||||
const std::string& client_key)
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<int> deleter(new int(0), [&](int* p) {
|
std::shared_ptr<int> deleter(new int(0), [&](int* p) {
|
||||||
std::unique_lock<std::shared_mutex> lock(cli_mut_);
|
std::unique_lock<std::shared_mutex> lock(cli_mut_);
|
||||||
@ -344,14 +341,13 @@ bool TransmServer::send_frame(const std::shared_ptr<asio::ip::tcp::socket>& sock
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!socket->send(asio::buffer(out_buf, out_len))) {
|
if (!socket->send(asio::buffer(out_buf, out_len))) {
|
||||||
TLOGE("{} send failed, buf type:{}, fid:{}, tid:{}", __FUNCTION__, static_cast<int>(buf->type_),
|
TLOGE("{} send failed, buf type:{}, fid:{}, tid:{}", __FUNCTION__, static_cast<int>(buf->type_), buf->fid_,
|
||||||
buf->fid_, buf->tid_);
|
buf->tid_);
|
||||||
delete[] out_buf;
|
delete[] out_buf;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
TLOGE("send failed, type:{}, fid:{}, tid:{}, mark:{}", static_cast<int>(buf->type_), buf->fid_,
|
TLOGE("send failed, type:{}, fid:{}, tid:{}, mark:{}", static_cast<int>(buf->type_), buf->fid_, buf->tid_, buf->mark_);
|
||||||
buf->tid_, buf->mark_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] out_buf;
|
delete[] out_buf;
|
||||||
@ -369,9 +365,7 @@ void TransmServer::monitor_idle()
|
|||||||
std::unique_lock<std::shared_mutex> lock(cli_mut_);
|
std::unique_lock<std::shared_mutex> lock(cli_mut_);
|
||||||
for (auto& item : client_map_) {
|
for (auto& item : client_map_) {
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
auto duration =
|
auto duration = std::chrono::duration_cast<std::chrono::seconds>(now - item.second->last_active_time_).count();
|
||||||
std::chrono::duration_cast<std::chrono::seconds>(now - item.second->last_active_time_)
|
|
||||||
.count();
|
|
||||||
if (duration >= remove_after_time) {
|
if (duration >= remove_after_time) {
|
||||||
TLOGW("OnLine Time [{}] sec, Proactively disconnect:{}", duration, item.first);
|
TLOGW("OnLine Time [{}] sec, Proactively disconnect:{}", duration, item.first);
|
||||||
remove_vec.push_back(item.first);
|
remove_vec.push_back(item.first);
|
||||||
|
@ -13,12 +13,12 @@ using namespace ofen;
|
|||||||
using high_c = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
using high_c = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
||||||
struct ClientCache {
|
struct ClientCache {
|
||||||
std::shared_ptr<asio::ip::tcp::socket> socket_;
|
std::shared_ptr<asio::ip::tcp::socket> socket_;
|
||||||
CMutBuffer buffer_{};
|
CMutBuffer buffer_;
|
||||||
std::array<char, g_BuffSize> tmp_buf_{};
|
std::array<char, g_BuffSize> tmp_buf_{};
|
||||||
std::string task_{};
|
std::string task_;
|
||||||
std::string uuid{};
|
std::string uuid;
|
||||||
std::string task_time_{};
|
std::string task_time_;
|
||||||
std::string online_time_{};
|
std::string online_time_;
|
||||||
uint64_t timestamp{};
|
uint64_t timestamp{};
|
||||||
high_c last_active_time_;
|
high_c last_active_time_;
|
||||||
FrameType cur_type_{TYPE_DEFAULT};
|
FrameType cur_type_{TYPE_DEFAULT};
|
||||||
@ -27,7 +27,7 @@ struct ClientCache {
|
|||||||
class TransmServer
|
class TransmServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TransmServer(asio::io_context& io_context);
|
explicit TransmServer(asio::io_context& io_context);
|
||||||
~TransmServer();
|
~TransmServer();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -39,8 +39,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void trans_data(CFrameBuffer* buf);
|
void trans_data(CFrameBuffer* buf);
|
||||||
bool check_double(CFrameBuffer* buf, std::shared_ptr<ClientCache>& fcli,
|
bool check_double(CFrameBuffer* buf, std::shared_ptr<ClientCache>& fcli, std::shared_ptr<ClientCache>& tcli);
|
||||||
std::shared_ptr<ClientCache>& tcli);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void accept_client();
|
void accept_client();
|
||||||
|
@ -340,7 +340,7 @@ bool encrypt(const uint8_t* k, uint8_t* m, size_t len)
|
|||||||
rdm(nonce, sizeof(nonce) - 4);
|
rdm(nonce, sizeof(nonce) - 4);
|
||||||
memcpy(m, nonce, kz);
|
memcpy(m, nonce, kz);
|
||||||
|
|
||||||
struct AES_ctx ctx;
|
struct AES_ctx ctx{};
|
||||||
AES_init_ctx_iv(&ctx, k, nonce);
|
AES_init_ctx_iv(&ctx, k, nonce);
|
||||||
AES_CTR_xcrypt_buffer(&ctx, m + kz, len - kz);
|
AES_CTR_xcrypt_buffer(&ctx, m + kz, len - kz);
|
||||||
return true;
|
return true;
|
||||||
@ -355,7 +355,7 @@ bool decrypt(const uint8_t* k, uint8_t* m, size_t len)
|
|||||||
uint8_t nonce[kz]{};
|
uint8_t nonce[kz]{};
|
||||||
memcpy(nonce, m, kz);
|
memcpy(nonce, m, kz);
|
||||||
|
|
||||||
struct AES_ctx ctx;
|
struct AES_ctx ctx{};
|
||||||
AES_init_ctx_iv(&ctx, k, nonce);
|
AES_init_ctx_iv(&ctx, k, nonce);
|
||||||
AES_CTR_xcrypt_buffer(&ctx, m + kz, len - kz);
|
AES_CTR_xcrypt_buffer(&ctx, m + kz, len - kz);
|
||||||
return true;
|
return true;
|
||||||
|
22
util/util.h
22
util/util.h
@ -44,7 +44,7 @@ enum FrameType : int16_t {
|
|||||||
|
|
||||||
// 此结构体成员顺序不可变动,涉及到序列化反序列化。
|
// 此结构体成员顺序不可变动,涉及到序列化反序列化。
|
||||||
struct CMessageInfo {
|
struct CMessageInfo {
|
||||||
CMessageInfo(const std::string& id);
|
explicit CMessageInfo(const std::string& id);
|
||||||
CMessageInfo(const CMessageInfo& info);
|
CMessageInfo(const CMessageInfo& info);
|
||||||
CMessageInfo& operator=(const CMessageInfo& info);
|
CMessageInfo& operator=(const CMessageInfo& info);
|
||||||
std::string id;
|
std::string id;
|
||||||
@ -72,8 +72,8 @@ public:
|
|||||||
~CFrameBuffer();
|
~CFrameBuffer();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string fid_{};
|
std::string fid_;
|
||||||
std::string tid_{};
|
std::string tid_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FrameType type_{};
|
FrameType type_{};
|
||||||
@ -113,8 +113,8 @@ inline std::string now_str()
|
|||||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
||||||
|
|
||||||
std::ostringstream timestamp;
|
std::ostringstream timestamp;
|
||||||
timestamp << std::put_time(std::localtime(&time_t_now), "[%m-%d %H:%M:%S") << "." << std::setfill('0')
|
timestamp << std::put_time(std::localtime(&time_t_now), "[%m-%d %H:%M:%S") << "." << std::setfill('0') << std::setw(3)
|
||||||
<< std::setw(3) << milliseconds.count() << "] ";
|
<< milliseconds.count() << "] ";
|
||||||
|
|
||||||
return timestamp.str();
|
return timestamp.str();
|
||||||
}
|
}
|
||||||
@ -122,31 +122,27 @@ inline std::string now_str()
|
|||||||
template <typename... Args> void TLOGI(const std::string& format, Args&&... args)
|
template <typename... Args> void TLOGI(const std::string& format, Args&&... args)
|
||||||
{
|
{
|
||||||
fc_lock_print();
|
fc_lock_print();
|
||||||
std::cout << ConsoleColor::Green << fmt::format(now_str() + format, std::forward<Args>(args)...)
|
std::cout << ConsoleColor::Green << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
||||||
<< std::endl;
|
|
||||||
fc_unlock_print();
|
fc_unlock_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args> void TLOGW(const std::string& format, Args&&... args)
|
template <typename... Args> void TLOGW(const std::string& format, Args&&... args)
|
||||||
{
|
{
|
||||||
fc_lock_print();
|
fc_lock_print();
|
||||||
std::cout << ConsoleColor::Yellow << fmt::format(now_str() + format, std::forward<Args>(args)...)
|
std::cout << ConsoleColor::Yellow << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
||||||
<< std::endl;
|
|
||||||
fc_unlock_print();
|
fc_unlock_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args> void TLOGE(const std::string& format, Args&&... args)
|
template <typename... Args> void TLOGE(const std::string& format, Args&&... args)
|
||||||
{
|
{
|
||||||
fc_lock_print();
|
fc_lock_print();
|
||||||
std::cout << ConsoleColor::Red << fmt::format(now_str() + format, std::forward<Args>(args)...)
|
std::cout << ConsoleColor::Red << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
||||||
<< std::endl;
|
|
||||||
fc_unlock_print();
|
fc_unlock_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args> void TLOGD(const std::string& format, Args&&... args)
|
template <typename... Args> void TLOGD(const std::string& format, Args&&... args)
|
||||||
{
|
{
|
||||||
fc_lock_print();
|
fc_lock_print();
|
||||||
std::cout << ConsoleColor::Cyan << fmt::format(now_str() + format, std::forward<Args>(args)...)
|
std::cout << ConsoleColor::Cyan << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
||||||
<< std::endl;
|
|
||||||
fc_unlock_print();
|
fc_unlock_print();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user