This commit is contained in:
aozhiwei 2024-12-23 14:30:54 +08:00
parent 8e1aa6c19b
commit 8d7062488f
9 changed files with 58 additions and 45 deletions

View File

@ -12,6 +12,11 @@ const std::string App::GetPkgName()
return "mangosd";
}
int App::GetPreprocessThreadNum()
{
return 1;
}
void App::Init()
{

View File

@ -8,6 +8,7 @@ class App : public f8::UserApp
public:
virtual const std::string GetPkgName() override;
virtual int GetPreprocessThreadNum() override;
virtual void Init() override;
virtual void UnInit() override;
virtual void Update(int delta_time) override;

View File

@ -206,8 +206,10 @@ namespace f8
int seqid,
const char *msgbody,
int bodylen,
unsigned short tag,
std::any* user_data)
const char *playload,
int playload_len,
unsigned short tag
)
{
char *p = (char*)malloc(sizeof(MsgHdr) + bodylen);
MsgHdr* hdr = (MsgHdr*)p;
@ -215,13 +217,10 @@ namespace f8
hdr->seqid = seqid;
hdr->msgid = msgid;
hdr->socket_handle = socket_handle;
hdr->buf = p + sizeof(MsgHdr);
hdr->buflen = bodylen;
hdr->offset = 0;
hdr->user_data = user_data;
hdr->tag = tag;
if (bodylen > 0) {
memmove((void*)hdr->buf, msgbody, bodylen);
memmove(p + sizeof(MsgHdr), msgbody, bodylen);
}
++msgnode_size_;
net_data_queue_.Push(&hdr->entry);
@ -405,6 +404,8 @@ namespace f8
int seqid,
const char *msgbody,
int bodylen,
const char *playload,
int playload_len,
unsigned short tag)
{
impl_->AddSocketMsg(sockfrom,
@ -413,27 +414,10 @@ namespace f8
seqid,
msgbody,
bodylen,
tag,
nullptr);
}
void App::AddSocketMsgAndUserData(unsigned short sockfrom,
long long socket_handle,
int msgid,
int seqid,
const char *msgbody,
int bodylen,
unsigned short tag,
std::any* user_data)
{
impl_->AddSocketMsg(sockfrom,
socket_handle,
msgid,
seqid,
msgbody,
bodylen,
tag,
user_data);
playload,
playload_len,
tag
);
}
}

View File

@ -29,15 +29,9 @@ namespace f8
int seqid,
const char *buf,
int buflen,
const char *playload,
int playload_len,
unsigned short tag);
void AddSocketMsgAndUserData(unsigned short sockfrom,
long long socket_handle,
int msgid,
int seqid,
const char *buf,
int buflen,
unsigned short tag,
std::any* user_data);
char** GetArgv();
int GetArgc();
long long GetMsgNodeSize();

View File

@ -20,7 +20,7 @@ namespace f8
{
return;
::google::protobuf::Message* msg = handler->prototype->New();
bool ok = msg->ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
bool ok = msg->ParseFromArray(hdr.GetBodyData(), hdr.GetBodyLen());
f8::UdpLog::Instance()->Debug
(
"%s%s:%d %s",

View File

@ -50,7 +50,7 @@ namespace f8
if (handler->custom_parser) {
ok = handler->custom_parser(hdr, &msg);
} else {
ok = msg.ParseFromArray(hdr->buf + hdr->offset, hdr->buflen - hdr->offset);
ok = msg.ParseFromArray((char*)hdr + sizeof(MsgHdr), hdr->buflen);
}
assert(ok);
if (ok) {

View File

@ -303,11 +303,30 @@ 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);
hdr->buf = ((char*)hdr) + sizeof(MsgHdr);
if (user_data) {
hdr->user_data = new(std::any);
*hdr->user_data = *user_data;

View File

@ -10,21 +10,30 @@ namespace a8
namespace f8
{
class AppImpl;
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;
const char* buf;
int buflen;
int offset;
list_head entry;
std::any* user_data = nullptr;
MsgHdr* Clone();
static void Destroy(MsgHdr* hdr);
int buflen;
int payload_buflen;
std::any* user_data;
friend class f8::AppImpl;
};
//普通消息头部

View File

@ -8,6 +8,7 @@ namespace f8
{
public:
virtual const std::string GetPkgName() = 0;
virtual int GetPreprocessThreadNum() = 0;
virtual void Init() = 0;
virtual void UnInit() = 0;
virtual void Update(int delta_time) = 0;