本文整理汇总了C++中connection_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ connection_ptr类的具体用法?C++ connection_ptr怎么用?C++ connection_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了connection_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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));
}
}
示例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());
}
}
示例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;
}
示例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);
}
}
示例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());
}
}
示例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 /> /help - show this help<br /> /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,"&","&");
boost::algorithm::replace_all(alias,"<","<");
boost::algorithm::replace_all(alias,">",">");
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()));
}
示例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());
}
}
示例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();
}
示例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));
}
}
示例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));
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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) );
}