本文整理汇总了C++中boost::asio::ip::tcp::acceptor类的典型用法代码示例。如果您正苦于以下问题:C++ acceptor类的具体用法?C++ acceptor怎么用?C++ acceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了acceptor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: start_listening
void start_listening() {
using boost::asio::ip::tcp;
system::error_code error;
tcp::resolver resolver(service_);
tcp::resolver::query query(address_, port_);
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error);
if (error) {
NETWORK_MESSAGE("Error resolving address: " << address_ << ':' << port_);
return;
}
tcp::endpoint endpoint = *endpoint_iterator;
acceptor_.open(endpoint.protocol(), error);
if (error) {
NETWORK_MESSAGE("Error opening socket: " << address_ << ':' << port_ << " -- reason: '" << error << '\'');
return;
}
socket_options_base::acceptor_options(acceptor_);
acceptor_.bind(endpoint, error);
if (error) {
NETWORK_MESSAGE("Error binding to socket: " << address_ << ':' << port_ << " -- reason: '" << error << '\'');
return;
}
acceptor_.listen(tcp::socket::max_connections, error);
if (error) {
NETWORK_MESSAGE("Error listening on socket: " << address_ << ':' << port_ << " -- reason: '" << error << '\'');
return;
}
new_connection.reset(new sync_connection<Tag,Handler>(service_, handler_));
acceptor_.async_accept(new_connection->socket(),
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
this, boost::asio::placeholders::error));
listening_ = true;
}
开发者ID:Mingun,项目名称:cpp-netlib,代码行数:33,代码来源:sync_server.hpp
示例2:
~PrivateData()
{
if ( m_success )
{
m_acceptor.cancel();
m_acceptor.close();
m_thread.join();
}
}
开发者ID:Alwnikrotikz,项目名称:cortex-vfx,代码行数:9,代码来源:DisplayDriverServer.cpp
示例3: InitTCPServer
void InitTCPServer(boost::asio::ip::tcp::acceptor& server, int server_port) {
boost::system::error_code server_ec;
boost::asio::ip::tcp::endpoint server_ep(boost::asio::ip::tcp::v4(),
server_port);
server.open(boost::asio::ip::tcp::v4(), server_ec);
ASSERT_EQ(0, server_ec.value()) << "Could not open server acceptor";
server.bind(server_ep, server_ec);
ASSERT_EQ(0, server_ec.value()) << "Could not bind server acceptor";
server.listen(boost::asio::socket_base::max_connections, server_ec);
ASSERT_EQ(0, server_ec.value()) << "Server acceptor could not listen";
}
开发者ID:securesocketfunneling,项目名称:ssf,代码行数:11,代码来源:ssf_client_tests.cpp
示例4:
void
on_accept(error_code ec)
{
if(! acceptor_.is_open())
return;
maybe_throw(ec, "accept");
static int id_ = 0;
std::thread{lambda{++id_, *this, std::move(sock_)}}.detach();
acceptor_.async_accept(sock_,
std::bind(&http_sync_server::on_accept, this,
asio::placeholders::error));
}
开发者ID:andyzhshg,项目名称:rippled,代码行数:12,代码来源:http_sync_server.hpp
示例5: PrivateData
PrivateData( int portNumber ) :
m_success(false),
m_endpoint(tcp::v4(), portNumber),
m_service(),
m_acceptor( m_service ),
m_thread()
{
m_acceptor.open( m_endpoint.protocol() );
m_acceptor.set_option( boost::asio::ip::tcp::acceptor::reuse_address(true));
m_acceptor.bind( m_endpoint );
m_acceptor.listen();
m_success = true;
}
开发者ID:Alwnikrotikz,项目名称:cortex-vfx,代码行数:13,代码来源:DisplayDriverServer.cpp
示例6: assert
inline accepting_source::element_type *
accepting_source::copy_next(iterator_range<element_type *> destination)
{
assert(m_acceptor);
assert(m_yield);
for (auto &client : destination)
{
assert(m_acceptor);
client = std::make_shared<boost::asio::ip::tcp::socket>(
m_acceptor->get_io_service());
assert(m_yield);
m_acceptor->async_accept(*client, *m_yield);
}
return destination.end();
}
开发者ID:TyRoXx,项目名称:silicium,代码行数:15,代码来源:accepting_source.hpp
示例7: handle_stop
/// Handle a request to stop the server.
virtual void handle_stop() {
// The server is stopped by cancelling all outstanding asynchronous
// operations. Once all operations have finished the io_service::run() call
// will exit.
m_acceptor.close();
base_t::handle_stop();
}
开发者ID:erlanger,项目名称:eixx,代码行数:8,代码来源:server.hpp
示例8: start_accept
void start_accept()
{
using namespace std;
using namespace boost::asio::ip;
auto connection = make_shared<tcp_connection>(_acceptor.get_io_service());
_acceptor.async_accept(connection->socket(), [connection, this](const boost::system::error_code &ec)
{
if (!ec)
{
connection->send_string();
}
this->start_accept();
});
}
开发者ID:Chhabi,项目名称:cppexamples,代码行数:16,代码来源:AsioAsyncServer.cpp
示例9: Release
void Release() {
acceptor->close();
delete acceptor;
(*socket_pptr)->close();
delete *socket_pptr;
delete socket_pptr;
}
开发者ID:0xec,项目名称:server1,代码行数:7,代码来源:server.hpp
示例10: start
void start()
{
session * new_session( new session( io_service_) );
acceptor_.async_accept(
new_session->socket(),
boost::bind( & server::handle_accept_, this->shared_from_this(),
new_session, boost::asio::placeholders::error) );
}
开发者ID:BwRy,项目名称:core-android-market,代码行数:8,代码来源:stream_server.cpp
示例11: fail
/** Open a listening port.
@param ep The address and port to bind to.
@param ec Set to the error, if any occurred.
*/
void
open(tcp::endpoint const& ep, error_code& ec)
{
acceptor_.open(ep.protocol(), ec);
if(ec)
return fail("open", ec);
acceptor_.set_option(
boost::asio::socket_base::reuse_address{true});
acceptor_.bind(ep, ec);
if(ec)
return fail("bind", ec);
acceptor_.listen(
boost::asio::socket_base::max_connections, ec);
if(ec)
return fail("listen", ec);
do_accept();
}
开发者ID:vinniefalco,项目名称:Beast,代码行数:23,代码来源:websocket_server_async.cpp
示例12: handle_accept
inline void server::handle_accept(const boost::system::error_code& e) {
if (!e) {
new_connection_->start();
new_connection_.reset(new connection(io_service_, request_handler_));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this,
boost::asio::placeholders::error));
}
}
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:9,代码来源:WEBserver_asio.hpp
示例13: start_accept
void start_accept()
{
boost::shared_ptr<session> new_session =
boost::make_shared<session>(boost::ref(io_service_));
acceptor_.async_accept(new_session->socket_,
boost::bind(&server::handle_accept, this,
boost::asio::placeholders::error,
new_session));
}
开发者ID:mpapierski,项目名称:simpledaemon,代码行数:9,代码来源:main.cpp
示例14: start_accept
sock_handle_t start_accept()
{
sock_handle_t handle = next_unused_tcp();
if (!socket_handle_valid(handle))
return handle;
ip::tcp::socket& sock = tcp_from(handle);
acceptor.accept(sock);
return handle;
}
开发者ID:MagicSmokeFireworks,项目名称:magic-smoke-firmware,代码行数:10,代码来源:socket_hal.cpp
示例15: handle_accept
void handle_accept(boost::system::error_code const & ec) {
if (!ec) {
socket_options_base::socket_options(new_connection->socket());
new_connection->start();
new_connection.reset(new sync_connection<Tag,Handler>(service_, handler_));
acceptor_.async_accept(new_connection->socket(),
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
this, boost::asio::placeholders::error));
}
}
开发者ID:Mingun,项目名称:cpp-netlib,代码行数:10,代码来源:sync_server.hpp
示例16: accept
sock_handle_t accept()
{
sock_handle_t handle = next_unused_tcp();
if (!socket_handle_valid(handle))
return handle;
ip::tcp::socket& sock = tcp_from(handle);
acceptor.accept(sock, ec);
return !ec ? handle : socket_handle_invalid();
}
开发者ID:MagicSmokeFireworks,项目名称:magic-smoke-firmware,代码行数:11,代码来源:socket_hal.cpp
示例17: handle_accept
void handle_accept(boost::system::error_code const& ec) {
if (ec) {
}
socket_options_base::socket_options(new_connection->socket());
new_connection->start();
new_connection.reset(new sync_connection<Tag, Handler>(service_, handler_));
auto self = this->shared_from_this();
acceptor_.async_accept(
new_connection->socket(),
[=] (boost::system::error_code const &ec) { self->handle_accept(); });
}
开发者ID:adan830,项目名称:cpp-netlib,代码行数:11,代码来源:sync_server.hpp
示例18:
/// Destructor.
~server()
{
work_ = boost::none;
ios_.dispatch([&]
{
error_code ec;
acceptor_.close(ec);
});
for(auto& t : thread_)
t.join();
}
开发者ID:vinniefalco,项目名称:Beast,代码行数:12,代码来源:websocket_server_async.cpp
示例19: startAccept
void startAccept()
{
if (mAvailableConnections > 0) {
--mAvailableConnections;
SC_TcpConnection::pointer newConnection (new SC_TcpConnection(mWorld, ioService, this));
acceptor.async_accept(newConnection->socket,
boost::bind(&SC_TcpInPort::handleAccept, this, newConnection,
boost::asio::placeholders::error));
}
}
开发者ID:dailypips,项目名称:supercollider,代码行数:11,代码来源:SC_ComPort.cpp
示例20: handle_accept
/// Handle completion of an asynchronous accept operation.
void handle_accept(const boost::system::error_code& e) {
if (handle_accept_internal(e, m_new_channel)) {
m_new_channel =
tcp_channel<Handler>::create(this->m_io_service,
m_new_channel->handler(), channel<Handler>::TCP);
m_acceptor.async_accept(
static_cast<tcp_channel<Handler>&>(*m_new_channel).socket(),
std::bind(&tcp_server<Handler>::handle_accept,
this, boost::asio::placeholders::error));
}
}
开发者ID:erlanger,项目名称:eixx,代码行数:12,代码来源:server.hpp
注:本文中的boost::asio::ip::tcp::acceptor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论