本文整理汇总了C++中socket_ptr::close方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_ptr::close方法的具体用法?C++ socket_ptr::close怎么用?C++ socket_ptr::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket_ptr
的用法示例。
在下文中一共展示了socket_ptr::close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connection
void Server::connection(socket_ptr _sock) {
try {
CLOG_INFO << "Connection, peer IP: " << _sock->remote_endpoint().address().to_string() << endl;
Operation op;
receive(_sock, op);
if ( op == Operation::CREATE ) {
Counter(_sock, this);
}
else if ( op == Operation::INFO_DEVICE ||
op == Operation::LIST_DEVICES ||
op == Operation::CMD_STATUS ||
op == Operation::READ_DEVICE ) {
Info(_sock, op, this);
}
else {
send<int>(_sock, (int)Retval::ERROR);
}
_sock->close();
}
catch (exception& e) {
CLOG_ERROR << "Exception in thread: " << e.what() << endl;
}
}
示例2: async_connect_handler
/// 连接回调
void tcp_connector::async_connect_handler( boost::system::error_code const& ec
, socket_ptr pSock, FactoryFunc fact_func, ConnectHandler const& handler
, options_ptr opts, tcp::resolver::iterator resolver_it )
{
tcp_session_ptr ptr;
boost::system::error_code remote_ec, local_ec;
if (!ec && pSock->remote_endpoint(remote_ec) != pSock->local_endpoint(local_ec)
&& !remote_ec && !local_ec)
ptr = fact_func(pSock, session_initialized(session_id(), group_id(), opts));
else if (tcp::resolver::iterator() != resolver_it)
{
boost::system::error_code close_ec;
pSock->close(close_ec);
if (close_ec)
pSock.reset(new socket(m_ios));
tcp::endpoint endpoint = *resolver_it++;
pSock->async_connect(endpoint
, boost::bind(&tcp_connector::async_connect_handler, this, placeholders::error
, pSock, fact_func, handler, opts, resolver_it ));
return ;
}
handler(ptr, ec);
}
示例3: closeSocket
void closeSocket()
{
//threads.interrupt_all();
sock->shutdown(tcp::socket::shutdown_both);
sock->close();
boost::system::error_code ec;
if(ec)
{
cerr << ec.message().c_str();
}
}
示例4: disconnectClient
void disconnectClient(socket_ptr clientSock)
{
auto position = find(clientList->begin(), clientList->end(), clientSock);
clientSock->shutdown(tcp::socket::shutdown_both);
clientSock->close();
clientList->erase(position);
cout << "Client Disconnected! " << clientList->size() << " total clients" << endl;
}
示例5: handle_io
void handle_io(orchid::coroutine_handle co,socket_ptr sock) {
orchid::reader<orchid::socket> reader(*sock,co);
std::size_t n = 0;
char buf[409600] = {0};
try {
for(;;) {
n = reader.read(buf,409600);
ORCHID_DEBUG("id %lu n:%d",co->id(),n);
}
} catch (const orchid::io_error& e) {
ORCHID_ERROR("id %lu msg:%s",co->id(),e.what());
sock->close();
}
}