本文整理汇总了C++中TcpConnectionPtr::getMutableContext方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnectionPtr::getMutableContext方法的具体用法?C++ TcpConnectionPtr::getMutableContext怎么用?C++ TcpConnectionPtr::getMutableContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpConnectionPtr
的用法示例。
在下文中一共展示了TcpConnectionPtr::getMutableContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doUnsubscribe
void doUnsubscribe(const TcpConnectionPtr& conn, const string& topic)
{
LOG_OK << conn->name() << " unsub " << topic;
getTopic(topic).remove(conn);
// topic could be the one to be destroyed, so don't use it after erasing.
//客户端不订阅某个topic,就销毁
ConnectionSubscription* connSub = boost::any_cast<ConnectionSubscription>(conn->getMutableContext());
connSub->erase(topic);
}
示例2: doSubscribe
//TODO:这个函数没有处理客户端sub的topic不存在的情况
void doSubscribe(const TcpConnectionPtr& conn, const string& topic)
{
//getMutableContext返回的是:boost::any*
//为什么any_cast用的是ConnectionSubscripton,而不是指针???看boost:any_cast原型
/*
template<typename ValueType>
ValueType * any_cast(any * operand)
*/
LOG_OK << conn->name() << " sub " << topic;
ConnectionSubscription* connSub =
boost::any_cast<ConnectionSubscription>(conn->getMutableContext());
connSub->insert(topic);//保存这个客户端订阅的主题
getTopic(topic).add(conn);
}
示例3: onMessage
void HttpServer::onMessage(const TcpConnectionPtr& conn, ByteBuffer *buf, Timestamp receiveTime)
{
LOG_INFO("HttpServer::onConnection recv data [%d][%s]", conn->fd(), buf->toString().c_str());
HttpContext *context = zl::stl::any_cast<HttpContext>(conn->getMutableContext());
assert(context);
if(!context->parseRequest(buf, receiveTime))
{
conn->send("HTTP/1.1 400 Bad Request\r\n\r\n");
conn->send("HTTP/1.1 400 Bad Request\r\n\r\n");
conn->shutdown();
}
if (context->gotAll())
{
LOG_INFO("HttpServer::onMessage parse request over.");
response(conn, context->request());
context->reset(); // process request and return response, then reset, for long-connection
}
}
示例4: 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++);
}
}
}
示例5: doUnsubscribe
void doUnsubscribe(const TcpConnectionPtr& conn, const string& topic) {
getTopic(topic).remove(conn);
ConnectionContext* connectionContext
= boost::any_cast<ConnectionContext>(conn->getMutableContext());
connectionContext->subscription_.erase(topic);
}
示例6: doSubscribe
void doSubscribe(const TcpConnectionPtr& conn, const string& topic) {
ConnectionContext* connectionContext
= boost::any_cast<ConnectionContext>(conn->getMutableContext());
connectionContext->subscription_.insert(topic);
getTopic(topic).add(conn);
}