当前位置: 首页>>代码示例>>C++>>正文


C++ TcpConnectionPtr::getContext方法代码示例

本文整理汇总了C++中TcpConnectionPtr::getContext方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnectionPtr::getContext方法的具体用法?C++ TcpConnectionPtr::getContext怎么用?C++ TcpConnectionPtr::getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TcpConnectionPtr的用法示例。

在下文中一共展示了TcpConnectionPtr::getContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: onClientMessage

void ProxyServer::onClientMessage(const TcpConnectionPtr& conn,Buffer* buf,Timestamp)
{
	if(!conn->getContext().empty())
	{
		int id = boost::any_cast<int>(conn->getContext());
		sendRedisBuffer(id,buf);
	}
	else
	{
		buf->retrieveAll();
	}
}
开发者ID:7zkeeper,项目名称:emcds,代码行数:12,代码来源:proxyserver.cpp


示例2: 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);
        }
    }
}
开发者ID:zhangnian,项目名称:zgw,代码行数:40,代码来源:zgw.cpp


示例3: onMessage

 void onMessage(
     const TcpConnectionPtr& conn,
     Buffer* buf,
     Timestamp receiveTime) {
     const ConnectionContext& connectionContext
         = boost::any_cast<const ConnectionContext&>(conn->getContext());
     EntryPtr entry(connectionContext.weakEntry_.lock());
     if (entry) {
         localConnectionBuckets_.get()->back().insert(entry);
     }
     counters_.addInBoundTraffic(buf->readableBytes());
     codec_.onMessage(conn, buf, receiveTime);
 }
开发者ID:project-zerus,项目名称:sandbox,代码行数:13,代码来源:Hub.cpp


示例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++);
         }
     }
 }
开发者ID:project-zerus,项目名称:sandbox,代码行数:21,代码来源:Hub.cpp


示例5: 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++);
			}

		}
	}
开发者ID:1suming,项目名称:msmuduo,代码行数:23,代码来源:hub.cpp



注:本文中的TcpConnectionPtr::getContext方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。