From 9ba2696e52664c9f5b7a1e09a4a5516359d330b0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 9 Jan 2020 18:44:17 +0800 Subject: [PATCH] 1 --- cpp/protoutils.cc | 24 ++++++++++++++++++++++++ cpp/protoutils.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/cpp/protoutils.cc b/cpp/protoutils.cc index 2bb059c..5459715 100644 --- a/cpp/protoutils.cc +++ b/cpp/protoutils.cc @@ -281,6 +281,30 @@ namespace f8 return sizeof(WSProxyPackHead_C) + packlen; } + int Net_SendProxyCMsg(a8::AsyncTcpClient* tcp_client, unsigned short socket_handle, + unsigned short msgid, ::google::protobuf::Message& msg) + { + int packlen = msg.ByteSize(); + assert(packlen < 1024 * 60); + + char* buff = (char*)malloc(sizeof(WSProxyPackHead_C) + packlen); + memset(buff, 0, sizeof(WSProxyPackHead_C)); + WSProxyPackHead_C* head = (WSProxyPackHead_C*)buff; + head->packlen = packlen; + head->msgid = msgid; + head->seqid = 0; + head->magic_code = MAGIC_CODE; + head->ip_saddr = 0; + head->socket_handle = socket_handle; + + if (packlen > 0) { + msg.SerializeToArray(buff + sizeof(WSProxyPackHead_C), packlen); + } + tcp_client->SendBuff(buff, sizeof(WSProxyPackHead_C) + packlen); + free(buff); + return sizeof(WSProxyPackHead_C) + packlen; + } + int Net_SendProxyMsg(a8::TcpListener* tcp_listener, int socket_handle, unsigned int seqid, unsigned short error_code, unsigned short msgid, ::google::protobuf::Message& msg) diff --git a/cpp/protoutils.h b/cpp/protoutils.h index aaa75f4..859e578 100644 --- a/cpp/protoutils.h +++ b/cpp/protoutils.h @@ -129,6 +129,8 @@ namespace f8 int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short socket_handle, unsigned short msgid, ::google::protobuf::Message& msg); + int Net_SendProxyCMsg(a8::AsyncTcpClient* tcp_client, unsigned short socket_handle, + unsigned short msgid, ::google::protobuf::Message& msg); int Net_SendProxyMsg(a8::TcpListener* tcp_tlistener, int socket_handle, unsigned int seqid, unsigned short error_code,