本文整理汇总了C++中tcp::endpoint::protocol方法的典型用法代码示例。如果您正苦于以下问题:C++ endpoint::protocol方法的具体用法?C++ endpoint::protocol怎么用?C++ endpoint::protocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcp::endpoint
的用法示例。
在下文中一共展示了endpoint::protocol方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listener
listener(
boost::asio::io_context& ioc,
tcp::endpoint endpoint)
: acceptor_(ioc)
, socket_(ioc)
{
boost::system::error_code ec;
// Open the acceptor
acceptor_.open(endpoint.protocol(), ec);
if(ec)
{
fail(ec, "open");
return;
}
// Bind to the server address
acceptor_.bind(endpoint, ec);
if(ec)
{
fail(ec, "bind");
return;
}
// Start listening for connections
acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec);
if(ec)
{
fail(ec, "listen");
return;
}
}
示例2: connect
bool TajoSyncClient::connect(const tcp::endpoint &endpoint,
std::string &errmsg)
{
boost::system::error_code ec;
pImpl_->socket_.open(endpoint.protocol(), ec);
if( !ec )
{
pImpl_->socket_.set_option(tcp::no_delay(true), ec);
if( !ec )
{
pImpl_->socket_.connect(endpoint, ec);
}
}
if( !ec )
{
pImpl_->state_ = TajoClientState::CONNECTED;
return true;
}
else
{
errmsg = ec.message();
return false;
}
}
示例3: Start
void Server::Start(tcp::endpoint endpoint)
{
_acceptor.open(endpoint.protocol());
_acceptor.set_option(tcp::acceptor::reuse_address(true));
_acceptor.bind(endpoint);
_acceptor.listen();
_StartAccept();
sLog.Info(LOG_STRATUM, "Stratum server started");
}
示例4: acceptWait
void seedArm_service_impl::acceptWait(const std::string& addr, const std::string& port
, size_t workerThreadsCount
, const size_t keepAliveMilliseconds_GlobalValue)
{
if (0 == workerThreadsCount){
workerThreadsCount = boost::thread::hardware_concurrency();
}
////////////////////////////////////////////////
// set common keepAliveTime
connection_impl::KEEP_ALIVE_TIME_MS = keepAliveMilliseconds_GlobalValue;
using TCP = boost::asio::ip::tcp;
////////////////////////////////////////////////
// ready accpetor
TCP::resolver resolver(_ios);
TCP::resolver::query quary(addr, port);
TCP::endpoint endpoint = *resolver.resolve(quary);
_acceptor.open(endpoint.protocol());
_acceptor.set_option(TCP::no_delay(true));
_acceptor.set_option(TCP::acceptor::reuse_address(true));
_acceptor.bind(endpoint);
_acceptor.listen();
_acceptConn = connection::ptr(new connection_impl(this, _ios), connection_impl::destruct);
_acceptor.async_accept(_acceptConn->socket(), _strand.wrap(
boost::bind(&seedArm_service_impl::accept, this, boost::asio::placeholders::error)));
////////////////////////////////////////////////
// ready worker
for (size_t i = 0; i < workerThreadsCount; ++i)
{
boost::shared_ptr<boost::thread> thread(new boost::thread(
boost::bind(&boost::asio::io_service::run, &_ios)));
s_threads.push_back(thread);
}
////////////////////////////////////////////////
// ready expireTimer
_prevTime = boost::chrono::system_clock::now();
_updater.expires_from_now(boost::posix_time::milliseconds(UPDATE_TIME_MS));
_updater.async_wait(_strand.wrap(
boost::bind(&seedArm_service_impl::update, this, boost::asio::placeholders::error)));
}
示例5: add_endpoint
void worker::add_endpoint(tcp::endpoint& ep, bs::error_code& ec) {
try {
auto acceptor = tcp::acceptor(m_iosvc);
acceptor.open(ep.protocol());
acceptor.set_option(tcp::acceptor::reuse_address(true));
acceptor.bind(ep);
int backlog = options::opts["server.backlog"].as<int>();
if (backlog == 0) {
backlog = ba::socket_base::max_connections;
}
acceptor.listen(backlog);
m_acceptors.push_back(std::move(acceptor));
} catch (bs::system_error& e) {
ec = e.code();
}
}
示例6: 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();
}
示例7: listener
listener(
boost::asio::io_context& ioc,
ssl::context& ctx,
tcp::endpoint endpoint)
: ctx_(ctx)
, acceptor_(ioc)
, socket_(ioc)
{
boost::system::error_code ec;
// Open the acceptor
acceptor_.open(endpoint.protocol(), ec);
if(ec)
{
fail(ec, "open");
return;
}
// Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec);
if(ec)
{
fail(ec, "set_option");
return;
}
// Bind to the server address
acceptor_.bind(endpoint, ec);
if(ec)
{
fail(ec, "bind");
return;
}
// Start listening for connections
acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec);
if(ec)
{
fail(ec, "listen");
return;
}
}