From a66c5a3b7a87c1b4c2d8a5a7048a07fdf5d33984 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 29 Apr 2024 20:52:04 +0800 Subject: [PATCH] feat update --- CMakeLists.txt | 8 +++++- src/sled/network/kcp/kcp.h | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/sled/network/kcp/kcp.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c3a6264..d727f48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,13 @@ target_sources( target_link_libraries( sled - PUBLIC rpc_core fmt marl Async++ minilua protobuf::libprotobuf + PUBLIC rpc_core + fmt + marl + Async++ + minilua + protobuf::libprotobuf + tcmalloc_and_profiler_static # protobuf::libprotoc PRIVATE dl # protobuf::libprotobuf ${WHOLE_ARCHIVE_WRAPPER_START} diff --git a/src/sled/network/kcp/kcp.h b/src/sled/network/kcp/kcp.h new file mode 100644 index 0000000..a329eec --- /dev/null +++ b/src/sled/network/kcp/kcp.h @@ -0,0 +1,52 @@ +#ifndef SLED_NETWORK_KCP_KCP_H +#define SLED_NETWORK_KCP_KCP_H + +#pragma once + +#include +#include + +/** + kcp header +0 4 5 6 8 (BYTE) ++---------------+---+---+-------+ +| conv |cmd|frg| wnd | ++---------------+---+---+-------+ 8 +| ts | sn | ++---------------+---------------+ 16 +| una | len | ++---------------+---------------+ 24 +| | +| DATA (optional) | +| | ++-------------------------------+ +*/ +namespace sled { + +enum class KCPCommand { + kPush, + kAck, + kWask, + kWins, +}; + +struct KCPHeader { + uint32_t conv;// conv id + uint8_t cmd; // Command + uint8_t frg; // fragment number + uint16_t wnd; // my available window size + + uint32_t ts; // timestamp + uint32_t sn; // sequence number + uint32_t una;// sender unacknowledged (min) number + uint32_t len;// data len +}; + +struct KCPPacket { + KCPHeader header; + char data[1]; +}; + +}// namespace sled + +#endif// SLED_NETWORK_KCP_KCP_H