1
This commit is contained in:
parent
efbfca944a
commit
ea3d340cd1
@ -13,7 +13,7 @@ enum InnerMesssage_e
|
||||
IM_PlayerOffline,
|
||||
IM_ExecGM,
|
||||
IM_UpStreamDisconnect,
|
||||
IM_MasterSvrDisconnect,
|
||||
IM_MasterDisconnect,
|
||||
IM_UpStreamConnect,
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
const int PACK_MAX = 1024 * 64;
|
||||
|
||||
void MasterSvr::Init(int instance_id, const std::string& remote_ip, int remote_port)
|
||||
void Master::Init(int instance_id, const std::string& remote_ip, int remote_port)
|
||||
{
|
||||
this->instance_id = instance_id;
|
||||
this->remote_ip = remote_ip;
|
||||
@ -27,22 +27,22 @@ void MasterSvr::Init(int instance_id, const std::string& remote_ip, int remote_p
|
||||
tcp_client_ = new a8::TcpClient();
|
||||
tcp_client_->remote_address = remote_ip;
|
||||
tcp_client_->remote_port = remote_port;
|
||||
tcp_client_->on_error = std::bind(&MasterSvr::on_error, this, std::placeholders::_1, std::placeholders::_2);
|
||||
tcp_client_->on_connect = std::bind(&MasterSvr::on_connect, this, std::placeholders::_1);
|
||||
tcp_client_->on_disconnect = std::bind(&MasterSvr::on_disconnect, this, std::placeholders::_1);
|
||||
tcp_client_->on_socketread = std::bind(&MasterSvr::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
tcp_client_->on_error = std::bind(&Master::on_error, this, std::placeholders::_1, std::placeholders::_2);
|
||||
tcp_client_->on_connect = std::bind(&Master::on_connect, this, std::placeholders::_1);
|
||||
tcp_client_->on_disconnect = std::bind(&Master::on_disconnect, this, std::placeholders::_1);
|
||||
tcp_client_->on_socketread = std::bind(&Master::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
#if 0
|
||||
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
||||
a8::XParams().SetSender(this),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
MasterSvr* conn = (MasterSvr*)param.sender.GetUserData();
|
||||
Master* conn = (Master*)param.sender.GetUserData();
|
||||
conn->CheckAlive();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void MasterSvr::UnInit()
|
||||
void Master::UnInit()
|
||||
{
|
||||
#if 0
|
||||
a8::Timer::Instance()->DeleteTimer(timer_);
|
||||
@ -56,24 +56,24 @@ void MasterSvr::UnInit()
|
||||
recv_buff_ = nullptr;
|
||||
}
|
||||
|
||||
void MasterSvr::Open()
|
||||
void Master::Open()
|
||||
{
|
||||
tcp_client_->Open();
|
||||
}
|
||||
|
||||
void MasterSvr::Close()
|
||||
void Master::Close()
|
||||
{
|
||||
tcp_client_->Close();
|
||||
}
|
||||
|
||||
bool MasterSvr::Connected()
|
||||
bool Master::Connected()
|
||||
{
|
||||
return tcp_client_->Connected();
|
||||
}
|
||||
|
||||
void MasterSvr::on_error(a8::TcpClient* sender, int errorId)
|
||||
void Master::on_error(a8::TcpClient* sender, int errorId)
|
||||
{
|
||||
f8::UdpLog::Instance()->Error("MasterSvr errorid=%d remote_ip:%s remote_port:%d",
|
||||
f8::UdpLog::Instance()->Error("Master errorid=%d remote_ip:%s remote_port:%d",
|
||||
{
|
||||
errorId,
|
||||
sender->remote_address,
|
||||
@ -81,25 +81,25 @@ void MasterSvr::on_error(a8::TcpClient* sender, int errorId)
|
||||
});
|
||||
}
|
||||
|
||||
void MasterSvr::on_connect(a8::TcpClient* sender)
|
||||
void Master::on_connect(a8::TcpClient* sender)
|
||||
{
|
||||
recv_bufflen_ = 0;
|
||||
f8::UdpLog::Instance()->Info("masterserver connected", {});
|
||||
}
|
||||
|
||||
void MasterSvr::on_disconnect(a8::TcpClient* sender)
|
||||
void Master::on_disconnect(a8::TcpClient* sender)
|
||||
{
|
||||
recv_bufflen_ = 0;
|
||||
f8::UdpLog::Instance()->Info("masterserver %d disconnected after 10s later reconnect", {instance_id});
|
||||
#if 0
|
||||
App::Instance()->AddIMMsg(IM_MasterSvrDisconnect,
|
||||
App::Instance()->AddIMMsg(IM_MasterDisconnect,
|
||||
a8::XParams()
|
||||
.SetSender(instance_id)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
|
||||
void Master::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
|
||||
{
|
||||
#if 0
|
||||
++App::Instance()->perf.read_count;
|
||||
@ -148,7 +148,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
|
||||
#endif
|
||||
}
|
||||
|
||||
void MasterSvr::CheckAlive()
|
||||
void Master::CheckAlive()
|
||||
{
|
||||
if (!Connected()) {
|
||||
Open();
|
||||
|
@ -9,7 +9,7 @@ namespace a8
|
||||
}
|
||||
|
||||
struct timer_list;
|
||||
class MasterSvr
|
||||
class Master
|
||||
{
|
||||
public:
|
||||
int instance_id = 0;
|
||||
|
@ -27,7 +27,7 @@ void MasterMgr::Init()
|
||||
std::string remote_ip = master_svr_conf->At("ip")->AsXValue();
|
||||
int remote_port = master_svr_conf->At("port")->AsXValue();
|
||||
{
|
||||
MasterSvr* conn = new MasterSvr();
|
||||
Master* conn = new Master();
|
||||
conn->Init(instance_id, remote_ip, remote_port);
|
||||
mastersvr_hash_[conn->instance_id] = conn;
|
||||
conn->Open();
|
||||
@ -60,7 +60,7 @@ void MasterMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_Res
|
||||
}
|
||||
}
|
||||
|
||||
MasterSvr* MasterMgr::GetConnById(int instance_id)
|
||||
Master* MasterMgr::GetConnById(int instance_id)
|
||||
{
|
||||
auto itr = mastersvr_hash_.find(instance_id);
|
||||
return itr != mastersvr_hash_.end() ? itr->second : nullptr;
|
||||
@ -108,7 +108,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
|
||||
team_uuid = data;
|
||||
code = a8::openssl::Crc32((unsigned char*)data.data(), data.size());
|
||||
}
|
||||
MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1);
|
||||
Master* svr = GetConnById(code % mastersvr_hash_.size() + 1);
|
||||
if (svr) {
|
||||
++curr_context_id_;
|
||||
#if 0
|
||||
|
@ -10,7 +10,7 @@ namespace ss
|
||||
class SS_MS_ResponseTargetServer;
|
||||
}
|
||||
|
||||
class MasterSvr;
|
||||
class Master;
|
||||
class MasterMgr : public a8::Singleton<MasterMgr>
|
||||
{
|
||||
public:
|
||||
@ -37,12 +37,12 @@ class MasterMgr : public a8::Singleton<MasterMgr>
|
||||
private:
|
||||
long long GetContextIdBySocket(int socket_handle);
|
||||
f8::MsgHdr* GetHdrByContextId(long long context_id);
|
||||
MasterSvr* GetConnById(int instance_id);
|
||||
Master* GetConnById(int instance_id);
|
||||
|
||||
private:
|
||||
int target_conn_id_ = 100;
|
||||
long long curr_context_id_ = 0;
|
||||
std::map<int, MasterSvr*> mastersvr_hash_;
|
||||
std::map<int, Master*> mastersvr_hash_;
|
||||
std::map<int, long long> pending_socket_hash_;
|
||||
std::map<long long, f8::MsgHdr*> pending_request_hash_;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user