This commit is contained in:
aozhiwei 2024-12-24 19:02:58 +08:00
parent fb6dd34caa
commit 4fa980a6d1
8 changed files with 87 additions and 74 deletions

View File

@ -21,6 +21,7 @@
#include <f8/userapp.h>
#include <f8/iomgr.h>
#include <f8/threadpool.h>
#include <f8/msghdr.h>
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;

50
third_party/f8/f8/msghdr.cc vendored Normal file
View File

@ -0,0 +1,50 @@
#include <f8/internal/pch.h>
#include <cstring>
#include <f8/msghdr.h>
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);
}
}

32
third_party/f8/f8/msghdr.h vendored Normal file
View File

@ -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;
};
}

View File

@ -5,6 +5,7 @@
#include <f8/udplog.h>
#include <f8/utils.h>
#include <f8/protoutils.h>
#include <f8/msghdr.h>
#include <f8/netmsghandler.h>
namespace f8

View File

@ -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);
}
}

View File

@ -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

View File

@ -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<void(Context*)> cb);

View File

@ -8,7 +8,6 @@ namespace google {
namespace f8
{
struct MsgHdr;
struct JsonHttpRequest;