本文整理汇总了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;
}
示例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");
}
示例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);
}
}
示例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();
});
}
示例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));
}
示例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));
}
示例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));
}
示例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));
};
示例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));
}
示例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));
}
}
示例11:
void
do_accept()
{
acceptor_.async_accept(
socket_,
std::bind(
&listener::on_accept,
shared_from_this(),
std::placeholders::_1));
}
示例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));
}
示例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();
});
}
示例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;
}
}
示例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();
}
}