1
This commit is contained in:
parent
fb6dd34caa
commit
4fa980a6d1
3
third_party/f8/f8/app.cc
vendored
3
third_party/f8/f8/app.cc
vendored
@ -21,6 +21,7 @@
|
|||||||
#include <f8/userapp.h>
|
#include <f8/userapp.h>
|
||||||
#include <f8/iomgr.h>
|
#include <f8/iomgr.h>
|
||||||
#include <f8/threadpool.h>
|
#include <f8/threadpool.h>
|
||||||
|
#include <f8/msghdr.h>
|
||||||
|
|
||||||
static const int MAX_ZONE_ID = 100;
|
static const int MAX_ZONE_ID = 100;
|
||||||
static const int MAX_NODE_ID = 8;
|
static const int MAX_NODE_ID = 8;
|
||||||
@ -100,7 +101,7 @@ namespace f8
|
|||||||
net_msg_queue_.Push(&hdr->entry);
|
net_msg_queue_.Push(&hdr->entry);
|
||||||
NotifyLoopCond();
|
NotifyLoopCond();
|
||||||
}
|
}
|
||||||
ctx->Wait(1000);
|
ctx->Sleep(1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
50
third_party/f8/f8/msghdr.cc
vendored
Normal file
50
third_party/f8/f8/msghdr.cc
vendored
Normal 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
32
third_party/f8/f8/msghdr.h
vendored
Normal 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
1
third_party/f8/f8/netmsghandler.cc
vendored
1
third_party/f8/f8/netmsghandler.cc
vendored
@ -5,6 +5,7 @@
|
|||||||
#include <f8/udplog.h>
|
#include <f8/udplog.h>
|
||||||
#include <f8/utils.h>
|
#include <f8/utils.h>
|
||||||
#include <f8/protoutils.h>
|
#include <f8/protoutils.h>
|
||||||
|
#include <f8/msghdr.h>
|
||||||
#include <f8/netmsghandler.h>
|
#include <f8/netmsghandler.h>
|
||||||
|
|
||||||
namespace f8
|
namespace f8
|
||||||
|
40
third_party/f8/f8/protoutils.cc
vendored
40
third_party/f8/f8/protoutils.cc
vendored
@ -303,44 +303,4 @@ namespace f8
|
|||||||
return sizeof(WSProxyPackHead_S) + packlen;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
30
third_party/f8/f8/protoutils.h
vendored
30
third_party/f8/f8/protoutils.h
vendored
@ -9,36 +9,6 @@ namespace a8
|
|||||||
|
|
||||||
namespace f8
|
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
|
struct PackHead
|
||||||
|
4
third_party/f8/f8/threadpool.h
vendored
4
third_party/f8/f8/threadpool.h
vendored
@ -9,9 +9,9 @@ namespace f8
|
|||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool* Terminated() = 0;
|
virtual bool Terminated() = 0;
|
||||||
virtual list_head* GetWorkList() = 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);
|
void Init(int thread_num, std::function<void(Context*)> cb);
|
||||||
|
1
third_party/f8/f8/types.h
vendored
1
third_party/f8/f8/types.h
vendored
@ -8,7 +8,6 @@ namespace google {
|
|||||||
|
|
||||||
namespace f8
|
namespace f8
|
||||||
{
|
{
|
||||||
|
|
||||||
struct MsgHdr;
|
struct MsgHdr;
|
||||||
struct JsonHttpRequest;
|
struct JsonHttpRequest;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user