本文整理汇总了C++中tcp::acceptor::close方法的典型用法代码示例。如果您正苦于以下问题:C++ acceptor::close方法的具体用法?C++ acceptor::close怎么用?C++ acceptor::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcp::acceptor
的用法示例。
在下文中一共展示了acceptor::close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CloseConnection
static void CloseConnection(tcp::acceptor &_acceptor, tcp::socket &_socket) {
log_info(LOG_PREFIX, "disconnecting");
if (_acceptor.is_open()) {
_acceptor.close();
}
if (_socket.is_open()) {
_socket.close();
}
}
示例2: client
/*****************************************************************************
* fiber function per client
*****************************************************************************/
void client( boost::asio::io_service & io_svc, tcp::acceptor & a,
boost::fibers::barrier& barrier, unsigned iterations) {
print( tag(), ": echo-client started");
for (unsigned count = 0; count < iterations; ++count) {
tcp::resolver resolver( io_svc);
tcp::resolver::query query( tcp::v4(), "127.0.0.1", "9999");
tcp::resolver::iterator iterator = resolver.resolve( query);
tcp::socket s( io_svc);
boost::asio::connect( s, iterator);
for (unsigned msg = 0; msg < 1; ++msg) {
std::ostringstream msgbuf;
msgbuf << "from " << fiber_names.lookup() << " " << count << "." << msg;
std::string message(msgbuf.str());
print( tag(), ": Sending: ", message);
boost::system::error_code ec;
boost::asio::async_write(
s,
boost::asio::buffer( message),
boost::fibers::asio::yield[ec]);
if ( ec == boost::asio::error::eof) {
return; //connection closed cleanly by peer
} else if ( ec) {
throw boost::system::system_error( ec); //some other error
}
char reply[max_length];
size_t reply_length = s.async_read_some(
boost::asio::buffer( reply, max_length),
boost::fibers::asio::yield[ec]);
if ( ec == boost::asio::error::eof) {
return; //connection closed cleanly by peer
} else if ( ec) {
throw boost::system::system_error( ec); //some other error
}
print( tag(), ": Reply : ", std::string( reply, reply_length));
}
}
// done with all iterations, wait for rest of client fibers
if ( barrier.wait()) {
// exactly one barrier.wait() call returns true
// we're the lucky one
a.close();
print( tag(), ": acceptor stopped");
}
print( tag(), ": echo-client stopped");
}
示例3: run
void run(unsigned sleepMillis)
{
std::cout << "in GUIMessageSenderThread: run "
<< sleepMillis << "ms"
<< std::endl;
while (running_) {
if (!connected_) {
std::cout << "In GUIMessageSenderThread trying to connect to: " << host_ << " " << port_ << std::endl;
//tcp::endpoint endpoint_(boost::asio::ip::address::from_string(host_), port_);
//tcp::endpoint endpoint_(boost::asio::ip::address::from_string(host_), port_);
endpoint_.address(boost::asio::ip::address::from_string(host_));
endpoint_.port(port_);
tcp::acceptor acceptor(*io_service_, endpoint_);
getClientConnection(acceptor);
try {
sendMessages(sleepMillis);
acceptor.close();
stream_.clear();
stream_.close();
}
catch (std::exception& e)
{
std::cerr << "GUIMessageSenderThread Error in connection: " << e.what() << std::endl;
}
connected_ = false;
//boost::asio::deadline_timer timer(*io_service_,boost::posix_time::milliseconds(1000));
//timer.expires_from_now(boost::posix_time::milliseconds(1000));
//timer.wait();
}
}
std::cout << "done GUIMessageSenderThread: run "
<< sleepMillis << "ms"
<< std::endl;
}
示例4:
~peer_server()
{
m_acceptor.cancel();
m_acceptor.close();
if (m_thread) m_thread->join();
}
示例5:
~CServer()
{
DEBUG_MSG("Listener Destroyed");
acceptor_.close();
}