1
This commit is contained in:
parent
1c141d8817
commit
e6570ff2d3
@ -236,7 +236,8 @@ namespace f8
|
||||
unsigned short msgid,
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen)
|
||||
int bodylen,
|
||||
int tag)
|
||||
{
|
||||
char *p = (char*)malloc(sizeof(MsgHdr) + bodylen);
|
||||
MsgHdr* hdr = (MsgHdr*)p;
|
||||
@ -250,6 +251,7 @@ namespace f8
|
||||
hdr->offset = 0;
|
||||
hdr->hum = nullptr;
|
||||
hdr->user_data = nullptr;
|
||||
hdr->tag = tag;
|
||||
if (bodylen > 0) {
|
||||
memmove((void*)hdr->buf, msgbody, bodylen);
|
||||
}
|
||||
|
3
f8/app.h
3
f8/app.h
@ -55,7 +55,8 @@ namespace f8
|
||||
unsigned short msgid,
|
||||
unsigned int seqid,
|
||||
const char *msgbody,
|
||||
int bodylen);
|
||||
int bodylen,
|
||||
int tag);
|
||||
void FreeSocketMsg(MsgHdr* hdr);
|
||||
char** GetArgv() { return argv_; }
|
||||
int GetArgc() { return argc_; }
|
||||
|
@ -15,7 +15,7 @@ namespace f8
|
||||
const unsigned short MAX_MSG_ID = 2000;
|
||||
|
||||
struct MsgHdr;
|
||||
typedef bool (*CUSTOM_PARSER)(MsgHdr&, google::protobuf::Message*);
|
||||
typedef bool (*CUSTOM_PARSER)(MsgHdr*, google::protobuf::Message*);
|
||||
|
||||
struct NetMsgHandler
|
||||
{
|
||||
@ -45,21 +45,21 @@ namespace f8
|
||||
};
|
||||
|
||||
template<typename InstanceType, typename MsgType>
|
||||
static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr& hdr, NetMsgHandler* handler)
|
||||
static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr* hdr, NetMsgHandler* handler)
|
||||
{
|
||||
MsgType msg;
|
||||
bool ok = false;
|
||||
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(hdr->buf + hdr->offset, hdr->buflen - hdr->offset);
|
||||
}
|
||||
assert(ok);
|
||||
if (ok) {
|
||||
struct Invoker: public NetMsgHandler
|
||||
{
|
||||
void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*);
|
||||
void (InstanceType::*func)(MsgHdr&, const MsgType&);
|
||||
void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*);
|
||||
void (InstanceType::*func)(MsgHdr*, const MsgType&);
|
||||
};
|
||||
Invoker* invoker = (Invoker*)handler;
|
||||
auto ptr = invoker->func;
|
||||
@ -69,7 +69,7 @@ namespace f8
|
||||
|
||||
template<typename InstanceType, typename MsgType>
|
||||
static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler,
|
||||
void (InstanceType::*ptr)(MsgHdr&, const MsgType&),
|
||||
void (InstanceType::*ptr)(MsgHdr*, const MsgType&),
|
||||
CUSTOM_PARSER custom_parser = nullptr
|
||||
)
|
||||
{
|
||||
@ -81,8 +81,8 @@ namespace f8
|
||||
}
|
||||
struct Invoker: public NetMsgHandler
|
||||
{
|
||||
void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*);
|
||||
void (InstanceType::*func)(MsgHdr&, const MsgType&);
|
||||
void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*);
|
||||
void (InstanceType::*func)(MsgHdr*, const MsgType&);
|
||||
};
|
||||
Invoker *p = new Invoker();
|
||||
p->wrapper = &NetMsgHandlerWrapper<InstanceType, MsgType>;
|
||||
@ -96,12 +96,12 @@ namespace f8
|
||||
template<typename InstanceType>
|
||||
static bool ProcessNetMsg(NetMsgHandler* handler,
|
||||
InstanceType* instance,
|
||||
MsgHdr& hdr)
|
||||
MsgHdr* hdr)
|
||||
{
|
||||
if(handler){
|
||||
struct Invoker: public NetMsgHandler
|
||||
{
|
||||
void (*wrapper)(InstanceType*, MsgHdr&, NetMsgHandler*);
|
||||
void (*wrapper)(InstanceType*, MsgHdr*, NetMsgHandler*);
|
||||
void* func;
|
||||
};
|
||||
Invoker *p = (Invoker*)handler;
|
||||
@ -115,6 +115,6 @@ namespace f8
|
||||
NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers,
|
||||
unsigned short msgid);
|
||||
|
||||
void DumpMsgToLog(f8::MsgHdr& hdr, f8::NetMsgHandler* handler, const char* prefix);
|
||||
void DumpMsgToLog(f8::MsgHdr* hdr, f8::NetMsgHandler* handler, const char* prefix);
|
||||
void DumpMsgToLog(const ::google::protobuf::Message& msg, const char* prefix);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ namespace f8
|
||||
int offset;
|
||||
Player *hum = nullptr;
|
||||
const void* user_data = nullptr;
|
||||
int tag;
|
||||
list_head entry;
|
||||
|
||||
MsgHdr* Clone();
|
||||
|
Loading…
x
Reference in New Issue
Block a user