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

C++ connection_ptr类代码示例

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

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



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

示例1: start

void connection_manager::start(connection_ptr c)
{
	connections_.insert(c);

	boost::system::error_code ec;
	boost::asio::ip::tcp::endpoint endpoint = c->socket().remote_endpoint(ec);
	if (ec) {
		// Prevent the exception to be thrown to run to avoid the server to be locked (still listening but no more connection or stop).
		// If the exception returns to WebServer to also create a exception loop.
		_log.Log(LOG_ERROR,"Getting error '%s' while getting remote_endpoint in connection_manager::start", ec.message().c_str());
		stop(c);
		return;
	}

	std::string s = endpoint.address().to_string();
	if (s.substr(0, 7) == "::ffff:") {
		s = s.substr(7);
	}
	if (connectedips_.find(s) == connectedips_.end())
	{
		//ok, this could get a very long list when running for years
		connectedips_.insert(s);
		_log.Log(LOG_STATUS,"Incoming connection from: %s", s.c_str());
	}

	c->start();
}
开发者ID:fscoelho,项目名称:domoticz,代码行数:27,代码来源:connection_manager.cpp


示例2: send_messages

 void send_messages(
     connection_ptr connection
 )
 {
     // Check if sending has been completed....
     if (connection->send())
     {
         error_code ec;
         util::unique_function_nonser<
             void(
                 error_code const&
               , parcelset::locality const&
               , connection_ptr
             )
         > postprocess_handler;
         std::swap(postprocess_handler, connection->postprocess_handler_);
         postprocess_handler(
             ec, connection->destination(), connection);
     }
     else
     {
         std::unique_lock<mutex_type> l(connections_mtx_);
         connections_.push_back(std::move(connection));
     }
 }
开发者ID:K-ballo,项目名称:hpx,代码行数:25,代码来源:sender.hpp


示例3: handle_accept

    /// Handler callback for start_accept
    void handle_accept(connection_ptr con, lib::error_code const & ec) {
        if (ec) {
            con->terminate(ec);

            if (ec == error::operation_canceled) {
                endpoint_type::m_elog.write(log::elevel::info,
                    "handle_accept error: "+ec.message());
            } else {
                endpoint_type::m_elog.write(log::elevel::rerror,
                    "handle_accept error: "+ec.message());
            }
        } else {
            con->start();
        }

        lib::error_code start_ec;
        start_accept(start_ec);
        if (start_ec == error::async_accept_not_listening) {
            endpoint_type::m_elog.write(log::elevel::info,
                "Stopping acceptance of new connections because the underlying transport is no longer listening.");
        } else if (start_ec) {
            endpoint_type::m_elog.write(log::elevel::rerror,
                "Restarting async_accept loop failed: "+ec.message());
        }
    }
开发者ID:4ker,项目名称:CamFiQt,代码行数:26,代码来源:server_endpoint.hpp


示例4: on_close

	void on_close(connection_ptr con) {
		m_con = connection_ptr();
		con->stop_heartbeat();

		con->alog().at(log::alevel::DEVEL)<<"client was disconnected sid "<<  con->m_endpoint.m_strSid <<log::endl;

	}
开发者ID:artzub,项目名称:socket.io-client-cpp,代码行数:7,代码来源:sio_client_handler.hpp


示例5: on_open

 void on_open(connection_ptr connection) {
     if (connection->get_resource() == "/admin") {
         connection->set_handler(m_admin_handler);
     } else {
         connection->set_handler(m_broadcast_handler);
     }
 }
开发者ID:moorecoin,项目名称:MooreCoinService,代码行数:7,代码来源:broadcast_server_handler.hpp


示例6: validate

 void validate(connection_ptr con)
 {
   // The key validation step we need to do is on the subprotocols the
   // client requested.  This should include "sip", in which case we'll
   // select "sip" too.  If "sip" was not offered, we offer nothing and the
   // connection will probably fail.
   LOG_DEBUG("Validating incoming web socket connection");
   const std::vector<std::string>& subprotocols = con->get_subprotocols();
   if (std::find(subprotocols.begin(), subprotocols.end(), SUBPROTOCOL) != subprotocols.end())
   {
     LOG_DEBUG("Client requested subprotocol sip - agreeing");
     con->select_subprotocol("sip");
   }
   else
   {
     // Build a comma-separated list of subprotocols ready to log.
     std::stringstream ss;
     std::copy(subprotocols.begin(), subprotocols.end(), std::ostream_iterator<std::string>(ss, ","));
     std::string str = ss.str();
     if (!str.empty())
     {
       // The above added a trailing comma.  Strip it.
       str = str.substr(0, str.length() - 1);
     }
     LOG_INFO("Client requested subprotocols %s - connection will probably fail", str.c_str());
   }
 }
开发者ID:oldurecu,项目名称:sprout,代码行数:27,代码来源:websockets.cpp


示例7: on_message

void chat_server_handler::on_message(connection_ptr con, message_ptr msg) {
    if (msg->get_opcode() != websocketpp::frame::opcode::text) {
        return;
    }
    
    std::cout << "message from client " << con << ": " << msg->get_payload() << std::endl;
    
    
    
    // check for special command messages
    if (msg->get_payload() == "/help") {
        // print command list
        con->send(encode_message("server","avaliable commands:<br />&nbsp;&nbsp;&nbsp;&nbsp;/help - show this help<br />&nbsp;&nbsp;&nbsp;&nbsp;/alias foo - set alias to foo",false));
        return;
    }
    
    if (msg->get_payload().substr(0,7) == "/alias ") {
        std::string response;
        std::string alias;
        
        if (msg->get_payload().size() == 7) {
            response = "you must enter an alias.";
            con->send(encode_message("server",response));
            return;
        } else {
            alias = msg->get_payload().substr(7);
        }
        
        response = m_connections[con] + " is now known as "+alias;

        // store alias pre-escaped so we don't have to do this replacing every time this
        // user sends a message
        
        // escape json characters
        boost::algorithm::replace_all(alias,"\\","\\\\");
        boost::algorithm::replace_all(alias,"\"","\\\"");
        
        // escape html characters
        boost::algorithm::replace_all(alias,"&","&amp;");
        boost::algorithm::replace_all(alias,"<","&lt;");
        boost::algorithm::replace_all(alias,">","&gt;");
        
        m_connections[con] = alias;
        
        // set alias
        send_to_all(serialize_state());
        send_to_all(encode_message("server",response));
        return;
    }
    
    // catch other slash commands
    if ((msg->get_payload())[0] == '/') {
        con->send(encode_message("server","unrecognized command"));
        return;
    }
    
    // create json message to send based on msg
    send_to_all(encode_message(m_connections[con],msg->get_payload()));
}
开发者ID:moorecoin,项目名称:MooreCoinService,代码行数:59,代码来源:chat.cpp


示例8: on_message

 void on_message(connection_ptr con, message_ptr msg) {        
     if (con->get_resource() == "/getcasecount") {
         std::cout << "detected " << msg->get_payload() << " test cases." << std::endl;
         m_case_count = atoi(msg->get_payload().c_str());
     } else {
         con->send(msg->get_payload(),msg->get_opcode());
     }
 }
开发者ID:moorecoin,项目名称:MooreCoinService,代码行数:8,代码来源:echo_client.cpp


示例9: remove_connection

void RecordServer::remove_connection(connection_ptr conn)
{
	context_ptr context(boost::any_cast<context_ptr>(conn->get_context()));
	//sub_conns_.erase(context->id());
	conn->set_context(context_ptr(nullptr));

	connections_.erase(conn->get_id());
	LOG(INFO)<<__func__<<",conn size"<<connections_.size()<<", connid="<<conn->get_id();
}
开发者ID:ifzz,项目名称:loki,代码行数:9,代码来源:RecordServer.cpp


示例10: validate

void socketio_server_handler::validate(connection_ptr con) {
    std::stringstream err;

    // We only know about the chat resource
    if (con->get_resource() != resource_name_) {
        err << "Request for unknown resource " << con->get_resource();
        throw(websocketpp::http::exception(err.str(),websocketpp::http::status_code::NOT_FOUND));
    }

}
开发者ID:casmacat,项目名称:casmacat-thot-server,代码行数:10,代码来源:socketio-handler.cpp


示例11: validate

void chat_server_handler::validate(connection_ptr con) {
    std::stringstream err;
    
    // we only know about the chat resource
    if (con->get_resource() != "/chat") {
        err << "request for unknown resource " << con->get_resource();
        throw(websocketpp::http::exception(err.str(),websocketpp::http::status_code::not_found));
    }
    
    // require specific origin example
    if (con->get_origin() != "http://zaphoyd.com") {
        err << "request from unrecognized origin: " << con->get_origin();
        throw(websocketpp::http::exception(err.str(),websocketpp::http::status_code::forbidden));
    }
}
开发者ID:moorecoin,项目名称:MooreCoinService,代码行数:15,代码来源:chat.cpp


示例12: handle_read

	// handle appelé après lecture
	void handle_read(const boost::system::error_code& e, connection_ptr conn)	{
		if (!e)	{	// lecture des informations
			db::DataBaseType<MySQL> dbMySQL("root", "", "mycloud") ;
			string idMySQL;

			for(model::info i : infos)	{
				idMySQL = dbMySQL.getUser(i.getAddressMail(), i.getPwd());
			}
			if(idMySQL == "1"){
				cout << "Connexion réussi" << endl;

				File file("/home/steven/server/",idMySQL);

				std::string path="/home/steven/server/" + idMySQL + "referencement.xml";
				std::ifstream input(path.c_str());
				std::stringstream data_in;
				data_in << input.rdbuf();
				input.close();

				conn->socket().send(boost::asio::buffer(data_in.str()));
			}else{
				cout << "Connexion échoué" << endl;
			}



		} else {
			std::cerr << e.message() << std::endl;
		}
	}
开发者ID:Droopy06,项目名称:MyCloud,代码行数:31,代码来源:server.hpp


示例13: handle_accept

  /// Handle completion of a accept operation.
  void handle_accept(const asio::error_code& e, connection_ptr conn)
  {
    if (!e)
    {
      // Successfully accepted a new connection. Send the list of stocks to the
      // client. The connection::async_write() function will automatically
      // serialize the data structure for us.
      conn->async_write(stocks_,
          boost::bind(&server::handle_write, this,
            asio::placeholders::error, conn));

      // Start an accept operation for a new connection.
      connection_ptr new_conn(new connection(acceptor_.io_service()));
      acceptor_.async_accept(new_conn->socket(),
          boost::bind(&server::handle_accept, this,
            asio::placeholders::error, new_conn));
    }
    else
    {
      // An error occurred. Log it and return. Since we are not starting a new
      // accept operation the io_service will run out of work to do and the
      // server will exit.
      std::cerr << e.message() << std::endl;
    }
  }
开发者ID:HunterChen,项目名称:hanb-boost-asio-sample,代码行数:26,代码来源:server.cpp


示例14: async_connect

void http_client::handle_connect(const boost::system::error_code& error, connection_ptr conn, tcp::resolver::iterator resolve_itor)
{
	if(error) {
		std::cerr << "HANDLE_CONNECT_ERROR: " << error << std::endl;
		if(endpoint_iterator_ == resolve_itor) {
			++endpoint_iterator_;
		}
		//ASSERT_LOG(endpoint_iterator_ != tcp::resolver::iterator(), "COULD NOT RESOLVE TBS SERVER: " << resolve_itor->endpoint().address().to_string() << ":" << resolve_itor->endpoint().port());
		if(endpoint_iterator_ == tcp::resolver::iterator()) {
			resolution_state_ = RESOLUTION_NOT_STARTED;
			--in_flight_;
			conn->error_handler("Error establishing connection");
			return;
		}

		async_connect(conn);

		return;
	}
#if defined(_MSC_VER)
	conn->socket.set_option(boost::asio::ip::tcp::no_delay(true));
#endif

	//we've connected okay, mark DNS resolution as good.
	if(resolution_state_ != RESOLUTION_DONE) {
		resolution_state_ = RESOLUTION_DONE;

		//all those connections waiting on DNS resolution can now connect.
		foreach(const connection_ptr conn, connections_waiting_on_dns_) {
			async_connect(conn);
		}
开发者ID:LungTakumi,项目名称:anura,代码行数:31,代码来源:http_client.cpp


示例15: handle_get_name_inv

 /* ===================================================== */   
 void handle_get_name_inv( const connection_ptr& con,  chan_data& cdat, const get_name_inv_message& msg )
 {
     name_inv_message reply;
     reply.name_trxs = _trx_broadcast_mgr.get_inventory( cdat.trxs_mgr );
     cdat.trxs_mgr.update_known( reply.name_trxs );
     con->send( network::message(reply,_chan_id) );
 }
开发者ID:1manStartup,项目名称:BitShares,代码行数:8,代码来源:bitname_channel.cpp


示例16: handle_get_trx_block

 void handle_get_trx_block( const connection_ptr& c, chan_data& cdat, get_trx_block_message msg )
 { try {
     // TODO: throttle attempts to query blocks by a single connection
     uint32_t blk_num = _db->fetch_block_num( msg.block_id );
     trx_block blk    = _db->fetch_trx_block( blk_num );
     c->send( network::message(trx_block_message( blk ), _chan_id ) );
 } FC_RETHROW_EXCEPTIONS( warn, "", ("msg",msg) ) } // provide stack trace for errors
开发者ID:coinxchangeco,项目名称:BitShares,代码行数:7,代码来源:blockchain_channel.cpp


示例17: on_close

 void on_close(connection_ptr con)
 {
     const QString reason = QString::fromStdString(con->get_remote_close_reason());
     pimpl->onClose(reason);
     qDebug() << "Connection Closed";
     m_con = connection_ptr();
 }
开发者ID:lfranchi,项目名称:websocketpp,代码行数:7,代码来源:WebSocketWrapper.cpp


示例18: handle_message

void protobuf_codec::handle_message(connection_ptr& conn) const
{
	loki::buffer* buffer = conn->get_buffer();
	while (buffer->data_size() >= MSG_NAME_LENGTH_SIZE + MIN_MSG_NAME_SIZE + MSG_HEADER_LENGTH)	
	{
		const uint32_t flag = buffer->get<uint32_t>();
		const uint32_t msg_len = flag & 0x0000ffff;
		if (msg_len + MSG_HEADER_LENGTH > buffer->data_size())
		{
			//message not enough, wait
			break;
		}
		if (msg_len > MAX_MSG_LENGTH || msg_len < MSG_NAME_LENGTH_SIZE + MIN_MSG_NAME_SIZE)
		{
			LOG(ERROR)<<"message length error "<<msg_len<<",readable="<<buffer->data_size();
			conn->close();
			break;
		}

		char buff[MAX_MSG_LENGTH];
		size_t len = sizeof(buff);
		LOG(INFO)<<__func__<<", flag="<<flag;
		bool ret = conn->restore_msg((const char*)buffer->data_ptr() + MSG_HEADER_LENGTH, flag, buff, len);
		if (!ret)
		{
			LOG(ERROR)<<"restore msg error";
			conn->close();
			break;
		}

		uint32_t errorcode = 0;
		MessagePtr message = parse(buff, len, errorcode);
		if (errorcode == 0 && message)
		{
			callback_(conn, message);
			buffer->consume(MSG_HEADER_LENGTH + msg_len);
		}
		else
		{
			LOG(ERROR)<<"Parse message error ,errorcode="<<errorcode;
			conn->close();
			break;
		}
	}
}
开发者ID:ifzz,项目名称:loki,代码行数:45,代码来源:protobuf_codec.cpp


示例19: on_open

 void on_open(connection_ptr connection) {
     if (!m_timer) {
         m_timer.reset(new boost::asio::deadline_timer(connection->get_io_service(),boost::posix_time::seconds(0)));
         m_timer->expires_from_now(boost::posix_time::milliseconds(250));
         m_timer->async_wait(boost::bind(&type::on_timer,this,boost::asio::placeholders::error));
     }
 
     m_connections.insert(connection);
 }
开发者ID:12w21,项目名称:rippled,代码行数:9,代码来源:broadcast_admin_handler.hpp


示例20: on_open

void chat_server_handler::on_open(connection_ptr con) {
    std::cout << "client " << con << " joined the lobby." << std::endl;
    m_connections.insert(std::pair<connection_ptr,std::string>(con,get_con_id(con)));

    // send user list and signon message to all clients
    send_to_all(serialize_state());
    con->send(encode_message("server","welcome, use the /alias command to set a name, /help for a list of other commands."));
    send_to_all(encode_message("server",m_connections[con]+" has joined the chat."));
}
开发者ID:moorecoin,项目名称:MooreCoinService,代码行数:9,代码来源:chat.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ const_Vector类代码示例发布时间:2022-05-31
下一篇:
C++ config_writer类代码示例发布时间: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