• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TcpConnectionPtr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: acceptedCallBack_

	/// <summary>
	/// Handle_accepts the specified error.
	/// </summary>
	/// <param name="error">The error.</param>
	/// <param name="conn">The conn.</param>
	void TcpServer::handle_accept( const boost::system::error_code& error, const TcpConnectionPtr conn)
	{
		if (!error)	/// ´¦Àí¼àÌýʼþ
		{
			conn->SetMessageCallBack(messageCallBack_);
			conn->SetErrorCallBack(errorCallBack_);
			conn->SetWriteCompleteCallBack(writecompleteCallBack_);
			if (acceptedCallBack_)
			{
				acceptedCallBack_(conn);
			}

			boost::weak_ptr<WheelEntry<TcpConnection> > weak_ptr = timing_wheel_.Register(conn, 
				TimeOutCallBackT<TcpConnection>(boost::bind(&TcpServer::handle_timeout, this, _1)));

			conn->SetContent(boost::any(weak_ptr));

			conn->Start();
			TcpConnectionPtr tcpconnPtr(new TcpConnection(ioservicepool_.get_io_service(), messageCallBack_, &timing_wheel_));
			acceptor_.async_accept(tcpconnPtr->socket(),
				boost::bind(&TcpServer::handle_accept, this,
				boost::asio::placeholders::error,tcpconnPtr));
		}
		else
		{
			if (errorCallBack_)
			{
				errorCallBack_(conn, error);
			}
		}

	}
开发者ID:guker,项目名称:utility,代码行数:37,代码来源:TcpServer.cpp


示例2: OnConnection

	void OnConnection(const TcpConnectionPtr& conn)
	{
		LOG_INFO << conn->localAddress().toIpPort() << " -> "
             << conn->peerAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");
             	
    if(conn->connected())
    {
    	m_connection = conn;
    	if(g_aliveConnections.incrementAndGet() == g_connections)
    	{
    		LOG_INFO << "all connected";
    	}
    	else
    	{
    		m_connection.reset();
    		
    		if(g_aliveConnections.incrementAndGet() == g_connections)
    		{
    			LOG_INFO << "all disconnected";
    			g_loop->quit();
    		}
    	}
    }
	}
开发者ID:adan830,项目名称:kimgbo,代码行数:25,代码来源:filetransfer.cpp


示例3: OnMessage

 void OnMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp time_)
 {
     LOG_DEBUG << conn->name();
     size_t len = buf->readableBytes();
     while (len >= kCells + 2)
     {
         const char* crlf = buf->findCRLF();
         if (crlf)
         {
             kimgbo::string request(buf->peek(), crlf);
             buf->retrieveUntil(crlf + 2);
             len = buf->readableBytes();
             if (!processRequest(conn, request))
             {
                 conn->send("Bad Request!\r\n");
                 conn->shutdown();
                 break;
             }
         }
         else if (len > 100) // id + ":" + kCells + "\r\n"
         {
             conn->send("Id too long!\r\n");
             conn->shutdown();
             break;
         }
         else
         {
             break;
         }
     }
 }
开发者ID:kimg-bo,项目名称:kimgbo,代码行数:31,代码来源:sever_multiloop.cpp


示例4: onConnect

void EchoServer::onConnect(const TcpConnectionPtr &conn)
{
	cout << "client : " << conn->getPeerAddr().toIp() << " : "
		 << conn->getPeerAddr().toPort() << " on" << endl;
	conn->send("hello, welcome to Echo Server!\r\nenter word to look for, or q to quit: ");

}
开发者ID:souldong1591,项目名称:project,代码行数:7,代码来源:EchoServer.cpp


示例5: defaultConnectionCallback

NAMESPACE_ZL_NET_START

void defaultConnectionCallback(const TcpConnectionPtr& conn)
{
  LOG_INFO("defaultConnectionCallback : [%s]<->[%s] [%s]\n", conn->localAddress().ipPort().c_str(),
        conn->peerAddress().ipPort().c_str(), conn->connected() ? "UP" : "DOWN");
}
开发者ID:YuuFish,项目名称:zl_reactor,代码行数:7,代码来源:TcpConnection.cpp


示例6: queue_task

void ProxyServer::queue_task(const std::string& task,std::string& result)
{

	dataserver::SetUsrStkCfg stkcfg;
	stkcfg.set_taskid("1000001");
   	stkcfg.set_usrid("zhangqi");
    dataserver::UserStockCfg* pUserscfg = stkcfg.add_stkcfg();
    pUserscfg->set_stockcode("600123");
    pUserscfg->set_bulletin(1);
    pUserscfg->set_max_price(12.11);
    pUserscfg->set_run(1);
    pUserscfg->set_incrementid(12345);

    dataserver::UserStockCfg* pUserscfg1 = stkcfg.add_stkcfg();
    pUserscfg1->set_stockcode("600223");
    pUserscfg1->set_bulletin(1);
    pUserscfg1->set_max_price(42.85);
    pUserscfg1->set_run(1);
    pUserscfg1->set_incrementid(9812);

	google::protobuf::Message* protomsg = NULL;
	protomsg = &stkcfg;
	std::string connname = m_taskconns[task];
	for(ConnectionMap::iterator it(m_conns.begin()); it != m_conns.end(); ++it)
	{
		TcpConnectionPtr conn = it->second;
		if(connname == std::string(conn->name().c_str()))
		{
			m_codec.send(conn,*protomsg);
			break;
		}
	}
}
开发者ID:7zkeeper,项目名称:emcds,代码行数:33,代码来源:proxyserver.cpp


示例7: processRequest

        bool processRequest(const TcpConnectionPtr& conn, const string& request){
            string id;
            string puzzle;
            bool goodRequest = true;

            string::const_iterator colon = find(request.begin(), request.end(), ':');
            if(colon != request.end()){
                id.assign(request.begin(), colon);
                puzzle.assign(colon+1, request.end());
            }else{
                puzzle = request;
            }

            if(puzzle.size() == implicit_cast<size_t>(kCells)){
                LOG_DEBUG << conn->name();
                string result = solveSudoku(puzzle);
                if(id.empty()){
                    conn->send(result+"\r\n");
                }else{
                    conn->send(id +":"+ result+"\r\n" );
                }
            }else
                goodRequest = false;
            return goodRequest;
        }
开发者ID:xujie-nm,项目名称:learnMuduo,代码行数:25,代码来源:server_multiloop.cpp


示例8: onConnection

 void onConnection(const TcpConnectionPtr& conn){
     LOG_INFO << conn->localAddress().toIpPort() << " -> "
              << conn->peerAddress().toIpPort() << " is "
              << (conn->connected() ? "UP" : "DOWN");
     if(!conn->connected())
         loop_->quit();
 }
开发者ID:xujie-nm,项目名称:learnMuduo,代码行数:7,代码来源:chargenclient.cpp


示例9: onConnection

void Sender::onConnection(const TcpConnectionPtr& conn)
{
	  LOG_INFO << "EchoServer - " << conn->peerAddress().toIpPort() << " -> "
           << conn->localAddress().toIpPort() << " is "
           << (conn->connected() ? "UP" : "DOWN");
	  
}
开发者ID:crspecter,项目名称:network_ydxlib,代码行数:7,代码来源:ydx_sender.cpp


示例10: zmq_msg_size

void ZGWServer::responseMsg(zmq_msg_t& msg_t)
{
    size_t msg_size = zmq_msg_size(&msg_t);
    assert( msg_size > 0 );

    std::string str_msg(static_cast<char*>(zmq_msg_data(&msg_t)), msg_size);

    ZMSG msg;
    int rc = msg.deserialize(str_msg);
    if( rc != 0 )
    {
        LOG_ERROR << "PULL线程反序列化消息失败, ret: " << rc;
        return;
    }

    //LOG_INFO << "PULL线程反序列化消息成功, msg[id]: " << msg.flow_id << ", msg[type]: "
    //         << msg.msg_type << ", msg[body size]:" << msg.msg_body.size();

    std::map<uint32_t, TcpConnectionPtr>::iterator iter = id2conn_.find(msg.flow_id);
    if( iter == id2conn_.end() )
    {
        LOG_ERROR << "PULL线程查找flow_id: " << msg.flow_id << "对应的连接失败";
        return;
    }
    TcpConnectionPtr conn = iter->second;

    muduo::net::Buffer buf;
    buf.prependInt8(msg.msg_type);
    buf.prependInt32(static_cast<int32_t>(msg.msg_body.size()));
    buf.append(msg.msg_body.c_str(), msg.msg_body.size());
    conn->send(&buf);

    stat_.msg_recv_cnt.increment();
    stat_.msg_recv_bytes.addAndGet(msg_size);
}
开发者ID:zhangnian,项目名称:zgw,代码行数:35,代码来源:zgw.cpp


示例11: onClose

void EchoServer::onClose(const TcpConnectionPtr &conn)
{
	cout << "client : " << conn->getPeerAddr().toIp() << " : "
		 << conn->getPeerAddr().toPort() << " close" << endl;
	conn->shutdown();
	
}
开发者ID:souldong1591,项目名称:project,代码行数:7,代码来源:EchoServer.cpp


示例12: onMessage

void EchoServer::onMessage(const TcpConnectionPtr& conn,
                           Buffer* buf,
                           Timestamp time){
    string msg(buf->retrieveAllAsString());
    LOG_INFO << conn->name() << " echo " << msg.size() << " bytes at " << time.toString();
    conn->send(msg);
}
开发者ID:xujie-nm,项目名称:learnMuduo,代码行数:7,代码来源:echo.cpp


示例13:

void P2PServer::onConnection(const TcpConnectionPtr& conn)
{
  cout << conn->localAddress().toIpPort() << " -> "
       << conn->peerAddress().toIpPort() << " is "
       << (conn->connected() ? "UP" : "DOWN") 
       << endl;

}
开发者ID:albus2012,项目名称:HUAWEIP2P,代码行数:8,代码来源:p2pserver.cpp


示例14: onConnection

void HttpServer::onConnection(const TcpConnectionPtr& conn)
{
     LOG_INFO("HttpServer::onConnection get one client %d", conn->fd());
     if (conn->connected())
     {
         conn->setContext(HttpContext());
     }
}
开发者ID:lizhenghn123,项目名称:zl_reactor,代码行数:8,代码来源:HttpServer.cpp


示例15: onTcpConnected

void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection)
{
    logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)",
        connection->getPeerAddr().getDisplayStr().c_str(),
        connection->getServerConnCount());

    connection->recv();
}
开发者ID:Elvins,项目名称:ise,代码行数:8,代码来源:chargen_client.cpp


示例16: onClose

void TcpServer::onClose(const TcpConnectionPtr& conn)
{
    if (closeCallback_) closeCallback_(conn);
//    EventLoop* ioLoop = conn->getLoop();
  //  ioLoop->removeInLoop(conn->connfd());
    LOG_TRACE("client close|ip=%s|port=%u", conn->peerAddr().ip().c_str(), conn->peerAddr().port());
    connectionManager_->Remove(conn->id());
}
开发者ID:jettyu,项目名称:simcode,代码行数:8,代码来源:TcpServer.cpp


示例17: onTcpRecvComplete

void ServerModule_Chargen::onTcpRecvComplete(const TcpConnectionPtr& connection, void *packetBuffer,
    int packetSize, const Context& context)
{
    logger().writeFmt("[%s] Discarded %u bytes.",
        connection->getConnectionName().c_str(), packetSize);

    connection->recv();
}
开发者ID:mfc10001,项目名称:baoluo,代码行数:8,代码来源:svr_mod_chargen.cpp


示例18: onJsonConnection

/***************************************************
Description:    处理新的json连接或者连接断开情况
Input:          conn:TCP连接
Output:         无
Return:         无
***************************************************/
void TCPServer::onJsonConnection(const TcpConnectionPtr &conn)
{
    LOG_DEBUG <<"JSONConnection: " << conn->peerAddress().toIpPort() << " -> "
             << conn->localAddress().toIpPort() << " is "
             << (conn->connected() ? "UP" : "DOWN");

    if(!conn->connected())
        jsonCodec_.cleanup(conn);
}
开发者ID:zcdoyle,项目名称:RemoteControl,代码行数:15,代码来源:server.cpp


示例19: onTcpConnected

//-----------------------------------------------------------------------------
// 描述: 接受了一个新的TCP连接
//-----------------------------------------------------------------------------
void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection)
{
    logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)",
                      connection->getPeerAddr().getDisplayStr().c_str(),
                      connection->getServerConnCount());

    string msg = "Welcome to the simple echo server, type 'quit' to exit.\r\n";
    connection->send(msg.c_str(), msg.length());
}
开发者ID:joydit,项目名称:ise,代码行数:12,代码来源:echo_server.cpp


示例20: newConnection

void LServer::newConnection( const TcpConnectionPtr& session )
{
	if ( 1 )
	{
		ScopedLock lock(lock_);
		connections_[session->name()] = session;
		LOGD("Hello-%s", session->name().c_str());
	}
}
开发者ID:imace,项目名称:kkS,代码行数:9,代码来源:LServer.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TcpServer类代码示例发布时间:2022-05-31
下一篇:
C++ TcpConnection类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap