This commit is contained in:
aozhiwei 2022-12-26 18:12:54 +08:00
parent e04f8dd6ae
commit 558c4343d3
4 changed files with 37 additions and 44 deletions

View File

@ -254,4 +254,23 @@ namespace f8
return sizeof(WSProxyPackHead_S) + packlen;
}
MsgHdr* MsgHdr::Clone()
{
MsgHdr* hdr = (MsgHdr*)malloc(sizeof(MsgHdr));
*hdr = *this;
if (hdr->buflen > 0) {
hdr->buf = (char*)malloc(hdr->buflen);
memmove((void*)hdr->buf, (void*)buf, buflen);
}
return hdr;
}
void MsgHdr::Destroy(MsgHdr* hdr)
{
if (hdr->buf) {
free((void*)hdr->buf);
}
free((void*)hdr);
}
}

View File

@ -1,23 +1,31 @@
#pragma once
class Player;
namespace google
{
namespace protobuf
{
class Message;
}
}
namespace a8
{
class TcpClient;
class TcpListener;
}
class Player;
namespace f8
{
struct MsgHdr
{
unsigned int seqid;
unsigned short msgid;
int socket_handle;
unsigned long ip_saddr;
const char* buf;
int buflen;
int offset;
Player *hum = nullptr;
const void* user_data = nullptr;
MsgHdr* Clone();
static void Destroy(MsgHdr* hdr);
};
//普通消息头部
struct PackHead
{

View File

@ -27,23 +27,4 @@ namespace f8
return a8::HttpResponse(response);
}
MsgHdr* MsgHdr::Clone()
{
MsgHdr* hdr = (MsgHdr*)malloc(sizeof(MsgHdr));
*hdr = *this;
if (hdr->buflen > 0) {
hdr->buf = (char*)malloc(hdr->buflen);
memmove((void*)hdr->buf, (void*)buf, buflen);
}
return hdr;
}
void MsgHdr::Destroy(MsgHdr* hdr)
{
if (hdr->buf) {
free((void*)hdr->buf);
}
free((void*)hdr);
}
}

View File

@ -5,7 +5,6 @@ namespace a8
class MutableXObject;
}
class Player;
namespace f8
{
struct JsonHttpRequest
@ -36,20 +35,6 @@ namespace f8
IM_SysEnd = 99,
};
struct MsgHdr
{
unsigned int seqid;
unsigned short msgid;
int socket_handle;
unsigned long ip_saddr;
const char* buf;
int buflen;
int offset;
Player *hum = nullptr;
const void* user_data = nullptr;
MsgHdr* Clone();
static void Destroy(MsgHdr* hdr);
};
struct MsgHdr;
}