From 4fa980a6d17281ff7efe96ba83dabf2b0fa1ef27 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 24 Dec 2024 19:02:58 +0800 Subject: [PATCH] 1 --- third_party/f8/f8/app.cc | 3 +- third_party/f8/f8/msghdr.cc | 50 ++++++++++++++++++++++++++++++ third_party/f8/f8/msghdr.h | 32 +++++++++++++++++++ third_party/f8/f8/netmsghandler.cc | 1 + third_party/f8/f8/protoutils.cc | 40 ------------------------ third_party/f8/f8/protoutils.h | 30 ------------------ third_party/f8/f8/threadpool.h | 4 +-- third_party/f8/f8/types.h | 1 - 8 files changed, 87 insertions(+), 74 deletions(-) create mode 100644 third_party/f8/f8/msghdr.cc create mode 100644 third_party/f8/f8/msghdr.h diff --git a/third_party/f8/f8/app.cc b/third_party/f8/f8/app.cc index 25f1abe..52f7eff 100644 --- a/third_party/f8/f8/app.cc +++ b/third_party/f8/f8/app.cc @@ -21,6 +21,7 @@ #include #include #include +#include static const int MAX_ZONE_ID = 100; static const int MAX_NODE_ID = 8; @@ -100,7 +101,7 @@ namespace f8 net_msg_queue_.Push(&hdr->entry); NotifyLoopCond(); } - ctx->Wait(1000); + ctx->Sleep(1000); } }); return true; diff --git a/third_party/f8/f8/msghdr.cc b/third_party/f8/f8/msghdr.cc new file mode 100644 index 0000000..ffe1eb5 --- /dev/null +++ b/third_party/f8/f8/msghdr.cc @@ -0,0 +1,50 @@ +#include + +#include + +#include + +namespace f8 +{ + + char* MsgHdr::GetBodyData() const + { + return (char*)this + sizeof(MsgHdr); + } + + int MsgHdr::GetBodyLen() const + { + return buflen; + } + + char* MsgHdr::GetPlayloadData() const + { + return (char*)this + sizeof(MsgHdr) + GetBodyLen(); + } + + int MsgHdr::GetPlayloadLen() const + { + return payload_buflen; + } + + MsgHdr* MsgHdr::Clone() + { + MsgHdr* hdr = (MsgHdr*)malloc(sizeof(MsgHdr) + buflen); + memmove((void*)hdr, (void*)this, sizeof(MsgHdr) + buflen); + if (processed_data) { + hdr->processed_data = new(std::any); + *hdr->processed_data = *processed_data; + } + return hdr; + } + + void MsgHdr::Destroy(MsgHdr* hdr) + { + if (hdr->processed_data) { + delete hdr->processed_data; + hdr->processed_data = nullptr; + } + free((void*)hdr); + } + +} diff --git a/third_party/f8/f8/msghdr.h b/third_party/f8/f8/msghdr.h new file mode 100644 index 0000000..318178c --- /dev/null +++ b/third_party/f8/f8/msghdr.h @@ -0,0 +1,32 @@ +#pragma once + +namespace f8 +{ + + class App; + struct MsgHdr + { + public: + char* GetBodyData() const; + int GetBodyLen() const; + char* GetPlayloadData() const; + int GetPlayloadLen() const; + + MsgHdr* Clone(); + static void Destroy(MsgHdr* hdr); + + private: + list_head entry; + unsigned short sockfrom; + unsigned short tag; + int seqid; + int msgid; + long long socket_handle; + + int buflen; + int payload_buflen; + std::any* processed_data; + friend class f8::App; + }; + +} diff --git a/third_party/f8/f8/netmsghandler.cc b/third_party/f8/f8/netmsghandler.cc index 958eb86..d4f2772 100644 --- a/third_party/f8/f8/netmsghandler.cc +++ b/third_party/f8/f8/netmsghandler.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace f8 diff --git a/third_party/f8/f8/protoutils.cc b/third_party/f8/f8/protoutils.cc index 9ee2563..24cebac 100644 --- a/third_party/f8/f8/protoutils.cc +++ b/third_party/f8/f8/protoutils.cc @@ -303,44 +303,4 @@ namespace f8 return sizeof(WSProxyPackHead_S) + packlen; } - char* MsgHdr::GetBodyData() const - { - return (char*)this + sizeof(MsgHdr); - } - - int MsgHdr::GetBodyLen() const - { - return buflen; - } - - char* MsgHdr::GetPlayloadData() const - { - return (char*)this + sizeof(MsgHdr) + GetBodyLen(); - } - - int MsgHdr::GetPlayloadLen() const - { - return payload_buflen; - } - - MsgHdr* MsgHdr::Clone() - { - MsgHdr* hdr = (MsgHdr*)malloc(sizeof(MsgHdr) + buflen); - memmove((void*)hdr, (void*)this, sizeof(MsgHdr) + buflen); - if (processed_data) { - hdr->processed_data = new(std::any); - *hdr->processed_data = *processed_data; - } - return hdr; - } - - void MsgHdr::Destroy(MsgHdr* hdr) - { - if (hdr->processed_data) { - delete hdr->processed_data; - hdr->processed_data = nullptr; - } - free((void*)hdr); - } - } diff --git a/third_party/f8/f8/protoutils.h b/third_party/f8/f8/protoutils.h index 85fe2d3..8bc2849 100644 --- a/third_party/f8/f8/protoutils.h +++ b/third_party/f8/f8/protoutils.h @@ -9,36 +9,6 @@ namespace a8 namespace f8 { - class App; -} - -namespace f8 -{ - - struct MsgHdr - { - public: - char* GetBodyData() const; - int GetBodyLen() const; - char* GetPlayloadData() const; - int GetPlayloadLen() const; - - MsgHdr* Clone(); - static void Destroy(MsgHdr* hdr); - - private: - list_head entry; - unsigned short sockfrom; - unsigned short tag; - int seqid; - int msgid; - long long socket_handle; - - int buflen; - int payload_buflen; - std::any* processed_data; - friend class f8::App; - }; //普通消息头部 struct PackHead diff --git a/third_party/f8/f8/threadpool.h b/third_party/f8/f8/threadpool.h index 557d8a2..270db18 100644 --- a/third_party/f8/f8/threadpool.h +++ b/third_party/f8/f8/threadpool.h @@ -9,9 +9,9 @@ namespace f8 class Context { public: - virtual bool* Terminated() = 0; + virtual bool Terminated() = 0; virtual list_head* GetWorkList() = 0; - virtual void Wait(int ms) = 0; + virtual void Sleep(int ms) = 0; }; void Init(int thread_num, std::function cb); diff --git a/third_party/f8/f8/types.h b/third_party/f8/f8/types.h index b1dbb3e..2576da1 100644 --- a/third_party/f8/f8/types.h +++ b/third_party/f8/f8/types.h @@ -8,7 +8,6 @@ namespace google { namespace f8 { - struct MsgHdr; struct JsonHttpRequest;