本文整理汇总了C++中TcpSessionPtr::attatch方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSessionPtr::attatch方法的具体用法?C++ TcpSessionPtr::attatch怎么用?C++ TcpSessionPtr::attatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSessionPtr
的用法示例。
在下文中一共展示了TcpSessionPtr::attatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onAcceptNewClient
void SessionManager::onAcceptNewClient(zsummer::network::NetErrorCode ec, const TcpSocketPtr& s, const TcpAcceptPtr &accepter, AccepterID aID)
{
if (!_running || _stopAccept)
{
LCI("shutdown accepter. aID=" << aID);
return;
}
auto founder = _mapAccepterOptions.find(aID);
if (founder == _mapAccepterOptions.end())
{
LCE("Unknown AccepterID aID=" << aID);
return;
}
if (ec)
{
LCE("doAccept Result Error. ec=" << ec << ", extend=" << founder->second);
auto &&handler = std::bind(&SessionManager::onAcceptNewClient, this, std::placeholders::_1, std::placeholders::_2, accepter, aID);
auto timer = [accepter, handler]()
{
accepter->doAccept(std::make_shared<TcpSocket>(), std::move(handler));
};
createTimer(5000, std::move(timer));
return;
}
std::string remoteIP;
unsigned short remotePort = 0;
s->getPeerInfo(remoteIP, remotePort);
//! check white list
//! ---------------------
if (!founder->second._whitelistIP.empty())
{
bool checkSucess = false;
for (auto white : founder->second._whitelistIP)
{
if (remoteIP.size() >= white.size())
{
if (remoteIP.compare(0,white.size(), white) == 0)
{
checkSucess = true;
break;
}
}
}
if (!checkSucess)
{
LCW("Accept New Client Check Whitelist Failed remoteAdress=" << remoteIP << ":" << remotePort
<< ", extend=" << founder->second);
accepter->doAccept(std::make_shared<TcpSocket>(), std::bind(&SessionManager::onAcceptNewClient, this, std::placeholders::_1, std::placeholders::_2, accepter, aID));
return;
}
else
{
LCI("Accept New Client Check Whitelist Success remoteAdress=" << remoteIP << ":" << remotePort
<< ", extend=" << founder->second);
}
}
//! check Max Sessions
if (founder->second._currentLinked >= founder->second._maxSessions)
{
LCW("Accept New Client. Too Many Sessions And The new socket will closed. extend=" << founder->second );
}
else
{
LCD("Accept New Client. Accept new Sessions. The new socket remoteAddress=" << remoteIP << ":" << remotePort
<< ", Aready linked sessions = " << founder->second._currentLinked << ", extend=" << founder->second);
founder->second._currentLinked++;
founder->second._totalAcceptCount++;
_lastSessionID = nextSessionID(_lastSessionID);
s->initialize(_summer);
TcpSessionPtr session = std::make_shared<TcpSession>();
session->getOptions() = founder->second._sessionOptions;
session->setEventLoop(_summer);
if (session->attatch(s, aID, _lastSessionID))
{
_mapTcpSessionPtr[_lastSessionID] = session;
}
}
//! accept next socket.
accepter->doAccept(std::make_shared<TcpSocket>(), std::bind(&SessionManager::onAcceptNewClient, this, std::placeholders::_1, std::placeholders::_2, accepter, aID));
}