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


C++ acceptor::async_accept方法代码示例

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


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

示例1: accept

void conn_base::accept(tcp::acceptor& acceptor)
{
  if (_socket.is_open()) return;
  acceptor.async_accept(_socket,
      bind(&conn_base::_handle_init, this, _1));
  ++_op_cnt;
}
开发者ID:htc550605125,项目名称:network,代码行数:7,代码来源:connection.cpp

示例2: listen

	void listen()
	{
		DEBUG_MSG("!==============================================================!");

		////Critical Section
		static std::mutex m;
		std::lock_guard<std::mutex> lock(m);

		sessionPtr newSession = std::make_shared<CSerSession>(io_, mng_);

		try
		{
			acceptor_.async_accept(newSession->socket(), std::bind(&CServer::handle_accept, /*shared_from_this()*/ this, newSession,
				std::placeholders::_1));
			///*boost::system::error_code ec;
			//pSocket_->shutdown(asio::ip::tcp::socket::shutdown_send, ec);*/
		}
		catch (const std::bad_weak_ptr& e)
		{
			DEBUG_MSG(e.what());
			throw e;
		}

		DEBUG_MSG("Listen Activated");
	}
开发者ID:CCJY,项目名称:coliru,代码行数:25,代码来源:main.cpp

示例3: thread_fun

	void thread_fun()
	{
		for (;;)
		{
			error_code ec;
			tcp::endpoint from;
			tcp::socket socket(m_ios);
			condition_variable cond;
			bool done = false;
			m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
			while (!done)
			{
				m_ios.run_one();
				m_ios.reset();
			}

			if (ec == boost::asio::error::operation_aborted
				|| ec == boost::asio::error::bad_descriptor) return;

			if (ec)
			{
				fprintf(stderr, "Error accepting connection on peer socket: %s\n", ec.message().c_str());
				return;
			}

			fprintf(stderr, "%s: incoming peer connection\n", time_now_string());
			++m_peer_requests;
			socket.close(ec);
		}
	}
开发者ID:SergeyKrivohatskiy,项目名称:real_time_torrent,代码行数:30,代码来源:peer_server.cpp

示例4: accept_a_client

 void accept_a_client() {
     acceptor_.async_accept(socket_, peer_, [&](const asio::error_code& error) {
         if(!error) {
             std::make_shared<SimSession>(std::move(socket_), std::move(peer_))->start();
         }
         accept_a_client();
     });
 }
开发者ID:jimzshi,项目名称:fw,代码行数:8,代码来源:simproto.cpp

示例5: server

 server(boost::asio::io_service &io_service, short port, std::string str) :
         io_service_(io_service),
         acceptor_(io_service, tcp::endpoint(boost::asio::ip::address::from_string(str.c_str()), port)) {
     session *new_session = new session(io_service_);
     acceptor_.async_accept(new_session->scoket(),
                            boost::bind(&server::handle_accept, this, new_session,
                                        boost::asio::placeholders::error));
 }
开发者ID:nikitaband1t,项目名称:finalProject,代码行数:8,代码来源:main.cpp

示例6: start_accept

	void start_accept()
	{
		tcp_connection::pointer new_connection = tcp_connection::create(acceptor_.get_io_service());

		acceptor_.async_accept(new_connection->socket(),
			boost::bind(&tcp_server::handle_accept, this, new_connection,
			boost::asio::placeholders::error));
	}
开发者ID:Fimbulwinter,项目名称:Fimbulwinter,代码行数:8,代码来源:tcp_server.hpp

示例7: start_accept

 void start_accept()
 {
     fprintf(stderr, "server::start_accept()\n");
     session * new_session = new session(io_service_);
     acceptor_.async_accept(new_session->socket(),
             boost::bind(&server::handle_accept, this, new_session,
                 boost::asio::placeholders::error));
 }
开发者ID:mw-ding,项目名称:DMW-Chat,代码行数:8,代码来源:echo_server.cpp

示例8: ChannelServer

 ChannelServer(boost::asio::io_service& io_service, SocketPartyData me, SocketPartyData other) :
     io_service_server(io_service), io_service_client(io_service),
     acceptor_(io_service, tcp::endpoint(tcp::v4(), me.getPort()))
 {
     Logger::log("Craeting ChannelServer Between me (" + me.to_log_string() + ") and other (" + other.to_log_string() + ")");
     channel = new NativeChannel(io_service_server, io_service_client, me, other);
     acceptor_.async_accept(channel->getServerSocket(), boost::bind(&ChannelServer::handle_accept,
                            this, channel, boost::asio::placeholders::error));
 };
开发者ID:tim94114,项目名称:scapi,代码行数:9,代码来源:TwoPartyComm.hpp

示例9: start_accept

void server::start_accept()
{

	session* new_session = new session(io_service_);
	new_session->SetServer(this);
	acceptor_.async_accept(new_session->socket(),
		boost::bind(&server::handle_accept, this, new_session,
		boost::asio::placeholders::error));
	
}
开发者ID:luodaobin,项目名称:MiniEngine,代码行数:10,代码来源:srv.cpp

示例10: add_client

    void add_client(boost::system::error_code ec) {
        if (!ec) {
            boost::lock_guard<boost::mutex> lk(mx);
            connections.push_back(std::move(ss)); 
        }

        if (ec != boost::asio::error::operation_aborted) {
            acceptor.async_accept(ss, boost::bind(&Server::add_client, this, boost::asio::placeholders::error));
        }
    }
开发者ID:CCJY,项目名称:coliru,代码行数:10,代码来源:main.cpp

示例11:

 void
 do_accept()
 {
     acceptor_.async_accept(
         socket_,
         std::bind(
             &listener::on_accept,
             shared_from_this(),
             std::placeholders::_1));
 }
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:10,代码来源:websocket_server_async_ssl.cpp

示例12: Server

 Server(int serverPort = 6767) : 
     iosvc(),
     work(boost::asio::io_service::work(iosvc)),
     data_worker(&Server::generate_jobs, this),
     io_worker(boost::bind(&boost::asio::io_service::run, &iosvc)),
     acceptor(iosvc, tcp::endpoint(tcp::v4(), serverPort)),
     ss(iosvc)
 {
     acceptor.async_accept(ss, boost::bind(&Server::add_client, this, boost::asio::placeholders::error));
 }
开发者ID:CCJY,项目名称:coliru,代码行数:10,代码来源:main.cpp

示例13: accept

    void accept() {
        acceptor_.async_accept(socket_,
                               [this](const boost::system::error_code &ec)
        {
            if (!ec) {
                std::make_shared<session>(std::move(socket_))->start();
            }

            accept();
        });
    }
开发者ID:alexyoung91,项目名称:ws,代码行数:11,代码来源:timed_server.cpp

示例14: handle_accept

 void handle_accept(session *new_session,
                    const boost::system::error_code error) {
     if (!error) {
         new_session->start();
         new_session = new session(io_service_);
         acceptor_.async_accept(new_session->scoket(),
                                boost::bind(&server::handle_accept, this, new_session,
                                            boost::asio::placeholders::error));
     } else {
         delete new_session;
     }
 }
开发者ID:nikitaband1t,项目名称:finalProject,代码行数:12,代码来源:main.cpp

示例15: listener

awaitable<void> listener(tcp::acceptor acceptor)
{
  chat_room room;

  for (;;)
  {
    std::make_shared<chat_session>(
        co_await acceptor.async_accept(use_awaitable),
        room
      )->start();
  }
}
开发者ID:boostorg,项目名称:asio,代码行数:12,代码来源:chat_server.cpp


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