wsproxy/server/wsproxy/mastersvr.h
2019-06-05 14:40:11 +08:00

48 lines
1002 B
C++

#pragma once
#include "framework/cpp/protoutils.h"
namespace a8
{
class TcpClient;
}
struct timer_list;
class MasterSvr
{
public:
int instance_id = 0;
std::string remote_ip;
int remote_port = 0;
a8::tick_t last_pong_tick = 0;
public:
void Init(int instance_id, const std::string& remote_ip, int remote_port);
void UnInit();
void Open();
void Close();
bool Connected();
template <typename T>
void SendMsg(T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
}
private:
void on_error(a8::TcpClient* sender, int errorId);
void on_connect(a8::TcpClient* sender);
void on_disconnect(a8::TcpClient* sender);
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
void CheckAlive();
private:
char *recv_buff_ = nullptr;
unsigned int recv_bufflen_ = 0;
a8::TcpClient* tcp_client_ = nullptr;
timer_list* timer_ = nullptr;
};