relation/server/imserver/IMConnMgr.cc
aozhiwei 3901bc6433 1
2020-06-17 11:34:41 +08:00

68 lines
1.3 KiB
C++

#include "precompile.h"
#include "IMConnMgr.h"
#include "IMConn.h"
#include "jsondatamgr.h"
#include "app.h"
#include "ss_proto.pb.h"
void IMConnMgr::Init()
{
}
void IMConnMgr::UnInit()
{
for (auto& pair : id_hash_) {
pair.second->UnInit();
delete pair.second;
}
}
IMConn* IMConnMgr::GetConnByKey(const std::string& key)
{
auto itr = key_hash_.find(key);
return itr != key_hash_.end() ? itr->second : nullptr;
}
IMConn* IMConnMgr::RecreateIMConn(const std::string& host, int port)
{
std::string key = host + ":" + a8::XValue(port).GetString();
IMConn* conn = GetConnByKey(key);
#if 0
if (conn) {
return conn;
}
while (GetConnById(++curr_id_)) {};
int instance_id = curr_id_;
std::string remote_ip = host;
int remote_port = port;
conn = new IMConn();
conn->Init(instance_id, remote_ip, remote_port);
id_hash_[conn->instance_id] = conn;
key_hash_[key] = conn;
#endif
conn->Open();
return conn;
}
void IMConnMgr::_SS_Pong(f8::MsgHdr& hdr, const ss::SS_Pong& msg)
{
}
void IMConnMgr::_SS_MS_IMServerList(f8::MsgHdr& hdr, const ss::SS_MS_IMServerList& msg)
{
}
void IMConnMgr::TraverseIMConn(std::function<bool (IMConn*)> func)
{
for (auto& pair : key_hash_) {
if (!func(pair.second)) {
return;
}
}
}