2024-12-11 22:51:43 +08:00
|
|
|
#pragma once
|
2024-12-12 22:43:24 +08:00
|
|
|
#include "of_util.h"
|
|
|
|
#include <cstdint>
|
2024-12-12 23:11:55 +08:00
|
|
|
#include <functional>
|
2024-12-11 10:22:14 +08:00
|
|
|
#include <spdlog/sinks/rotating_file_sink.h>
|
|
|
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
2024-12-12 22:43:24 +08:00
|
|
|
|
2024-12-14 23:59:13 +08:00
|
|
|
constexpr int g_BuffSize = 102400;
|
2024-12-14 11:57:33 +08:00
|
|
|
enum FrameType : int16_t {
|
|
|
|
TYPE_DEFAULT = 0,
|
|
|
|
TYPE_GET_LIST,
|
|
|
|
TYPE_DOWN_LIST,
|
|
|
|
TYPE_UP_LIST,
|
|
|
|
TYPE_CANCEL_LIST,
|
|
|
|
TYPE_OPEN_FILE,
|
|
|
|
TYPE_TRANS_FILE,
|
2024-12-14 16:20:25 +08:00
|
|
|
TYPE_TRANS_DONE,
|
2024-12-14 11:57:33 +08:00
|
|
|
TYPE_READY_TRANS,
|
|
|
|
TYPE_INTERRUPT,
|
|
|
|
TYPE_NO_HIT_TASK,
|
2024-12-18 13:55:56 +08:00
|
|
|
TYPE_WAITTING,
|
|
|
|
TYPE_HEARTS
|
2024-12-14 11:57:33 +08:00
|
|
|
};
|
2024-12-11 10:22:14 +08:00
|
|
|
|
2024-12-11 17:00:59 +08:00
|
|
|
using namespace ofen;
|
2024-12-11 10:22:14 +08:00
|
|
|
std::shared_ptr<spdlog::logger> get_logger(const std::string& mark, const std::string& log_file);
|
2024-12-11 17:00:59 +08:00
|
|
|
class CFrameBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CFrameBuffer();
|
|
|
|
~CFrameBuffer();
|
2024-12-13 12:35:08 +08:00
|
|
|
|
2024-12-12 23:11:55 +08:00
|
|
|
public:
|
2024-12-14 11:57:33 +08:00
|
|
|
std::string fid_{};
|
|
|
|
std::string tid_{};
|
2024-12-12 22:43:24 +08:00
|
|
|
|
2024-12-11 22:51:43 +08:00
|
|
|
public:
|
2024-12-14 11:57:33 +08:00
|
|
|
FrameType type_{};
|
2024-12-11 22:51:43 +08:00
|
|
|
char* data_{};
|
|
|
|
int len_{};
|
2024-12-12 22:43:24 +08:00
|
|
|
char mark_{};
|
2024-12-11 17:00:59 +08:00
|
|
|
};
|
2024-12-13 12:35:08 +08:00
|
|
|
|
2024-12-12 23:11:55 +08:00
|
|
|
using ExFun_t = std::function<void(CFrameBuffer* buf)>;
|
2024-12-11 17:00:59 +08:00
|
|
|
/*
|
|
|
|
【 transm TCP 数据协议 】
|
|
|
|
header 2 char: 0xFF 0xFE
|
2024-12-12 22:43:24 +08:00
|
|
|
type 2 char:
|
|
|
|
mark 1 char:
|
2024-12-14 16:20:25 +08:00
|
|
|
from 32 char:
|
|
|
|
to 32 char:
|
2024-12-11 17:00:59 +08:00
|
|
|
len 4 char:
|
|
|
|
data xxxxx:
|
|
|
|
tail 2 char: 0xFF 0xFF
|
|
|
|
*/
|
|
|
|
class CTransProtocal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTransProtocal();
|
|
|
|
~CTransProtocal();
|
2024-12-12 22:43:24 +08:00
|
|
|
|
2024-12-11 17:00:59 +08:00
|
|
|
public:
|
2024-12-11 22:51:43 +08:00
|
|
|
static CFrameBuffer* parse(CMutBuffer& buffer);
|
|
|
|
static bool pack(CFrameBuffer* buf, char** out_buf, int& len);
|
2024-12-13 16:59:31 +08:00
|
|
|
};
|