本文整理汇总了C++中TcpConnectionPtr::setContext方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnectionPtr::setContext方法的具体用法?C++ TcpConnectionPtr::setContext怎么用?C++ TcpConnectionPtr::setContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpConnectionPtr
的用法示例。
在下文中一共展示了TcpConnectionPtr::setContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onConnection
void HttpServer::onConnection(const TcpConnectionPtr& conn)
{
LOG_INFO("HttpServer::onConnection get one client %d", conn->fd());
if (conn->connected())
{
conn->setContext(HttpContext());
}
}
示例2: onConnection
void onConnection(const TcpConnectionPtr& conn) {
if (conn->connected()) {
connectionCount_.increment();
conn->setContext(ConnectionContext());
ConnectionContext* connectionContext
= boost::any_cast<ConnectionContext>(conn->getMutableContext());
EntryPtr entry(new Entry(conn));
localConnectionBuckets_.get()->back().insert(entry);
WeakEntryPtr weakEntry(entry);
connectionContext->weakEntry_ = weakEntry;
} else {
connectionCount_.decrement();
const ConnectionContext& connectionContext
= boost::any_cast<const ConnectionContext&>(conn->getContext());
const ConnectionSubscription& connSub = connectionContext.subscription_;
// subtle: doUnsubscribe will erase *it, so increase before calling.
for (auto it = connSub.begin(); it != connSub.end();) {
doUnsubscribe(conn, *it++);
}
}
}
示例3: onClientConnection
void ZGWServer::onClientConnection(const TcpConnectionPtr& conn)
{
LOG_INFO << "Client " << conn->peerAddress().toIpPort() << " -> "
<< conn->localAddress().toIpPort() << " is "
<< (conn->connected() ? "UP" : "DOWN");
if( conn->connected() )
{
int id = -1;
if( !idQueue_.empty() )
{
id = idQueue_.front();
idQueue_.pop();
id2conn_[id] = conn;
}
if( -1 == id )
{
LOG_ERROR << "[过载保护]系统到达最大连接数,拒绝连接";
conn->shutdown();
}
else
{
conn->setContext(id);
LOG_INFO << "新连接[" << conn->peerAddress().toIpPort() << "]流水ID: " << id;
}
}
else
{
if(!conn->getContext().empty())
{
int id = boost::any_cast<int>(conn->getContext());
assert(id > 0 && id <= static_cast<int>(kMaxConns));
// 回收连接的key
idQueue_.push(id);
id2conn_.erase(id);
}
}
}
示例4: onConnection
void onConnection(const TcpConnectionPtr& conn)
{
//不管客户端连上来的是sub还是pub,都首先创建一个ConnectionSubscription,虽然对sub来说,没有必要
if (conn->connected())
{
conn->setContext(ConnectionSubscription()); //保存一个clinet订阅的主题
}
else
{
//连接断开,把这个client订阅的topic里面都取消
const ConnectionSubscription& connSub
= boost::any_cast<const ConnectionSubscription&>(conn->getContext());
// subtle: doUnsubscribe will erase *it, so increase before calling.
for (ConnectionSubscription::const_iterator it = connSub.begin();
it != connSub.end();)
{
doUnsubscribe(conn, *it++);
}
}
}