本文整理汇总了C++中tcp::socket::close方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::close方法的具体用法?C++ socket::close怎么用?C++ socket::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcp::socket
的用法示例。
在下文中一共展示了socket::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connectSocket
void connectSocket(boost::asio::io_service& io_service, tcp::socket& socket, const std::string& url, const std::string &port) {
boost::system::error_code error = boost::asio::error::host_not_found;
// connect
if (isIpAddress(url.c_str())) {
boost::asio::ip::address addr = boost::asio::ip::address::from_string(url);
boost::asio::ip::tcp::endpoint endpoint = boost::asio::ip::tcp::endpoint(addr, lexical_cast<int>(port));
socket.close();
socket.connect(endpoint);
}
else {
tcp::resolver::query query(url, "http");
tcp::resolver resolver(io_service);
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;
while (error && endpoint_iterator != end)
{
socket.close();
socket.connect(*endpoint_iterator++, error);
}
if (error)
throw boost::system::system_error(error);
}
}
示例2: handle_connect
// Conexion al servidor
void handle_connect(const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator){
debugOUT("handle_connect");
if (!error){
connected = true;
debugOUT("Connected");
boost::asio::async_read(socket_,
boost::asio::buffer(receiveBuffer, transferAtLeast),
boost::asio::transfer_at_least(transferAtLeast),
boost::bind(&TCPClient::handle_read, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
debugOUT("async_read dispatched");
}
else if (endpoint_iterator != tcp::resolver::iterator()){
debugOUT("Next Endpoint");
// Conexion fallida, intentemos con el siguiente endpoint
socket_.close();
tcp::endpoint endpoint = *endpoint_iterator;
socket_.async_connect( endpoint,
boost::bind(&TCPClient::handle_connect, this,
boost::asio::placeholders::error, ++endpoint_iterator));
}
else{
debugOUT("Error: " << error.message());
}
}
示例3: acceptor
void
controller::listen_for_command()
{
LOG(INFO) << "Listening for commands...";
boost::system::error_code error;
asio::streambuf buffer;
try
{
uint16_t port = global::config()->get("controller.port", 3103);
tcp::acceptor acceptor(this->io_service_,
tcp::endpoint(tcp::v4(), port));
while (true)
{
acceptor.accept(controll_socket_);
while (true)
{
asio::read_until(controll_socket_, buffer, regex("\n"), error);
if (error)
break;
std::istream is(&buffer);
string line;
std::getline(is, line);
process_command(line);
}
controll_socket_.close();
}
}
catch (std::exception& e)
{
LOG(ERROR) << e.what();
}
}
示例4: accept
void accept()
{
// Clean up any previous connection.
boost::beast::error_code ec;
socket_.close(ec);
buffer_.consume(buffer_.size());
acceptor_.async_accept(
socket_,
[this](boost::beast::error_code ec)
{
if (ec)
{
accept();
}
else
{
// Request must be fully processed within 60 seconds.
request_deadline_.expires_after(
std::chrono::seconds(60));
read_request();
}
});
}
示例5: catch
~Client()
{
try {
tcp_socket->close();
} catch (bs::system_error e) {}
delete tcp_socket;
}
示例6: 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();
}
}
示例7: really_disconnect
static void really_disconnect(tcp::socket& socket, Logger* logger)
{
try {
socket.shutdown(socket_base::shutdown_both);
socket.close();
} catch(const system::system_error& e) {
// This might be totally okay. Depends on the error.
logger->warning(format("Failed to shut down the socket. This shouldn't happen! (%1%)") % e.what());
}
}
示例8: reply
void CMD::reply(tcp::socket& s, std::string message)
{
try {
boost::asio::write(s, boost::asio::buffer(
str(boost::format("%1% %2%\r\n") % id % message)
)
);
s.close();
} catch (boost::system::system_error &e) {
std::cerr << "Exception:" << e.what() << std::endl;
}
}
示例9: Close
inline bool TCPServerSession::Close()
{
try
{
if (!mSocket.is_open()) return false;
mSocket.shutdown(socket_base::shutdown_both);
mSocket.close();
return true;
}
catch (...)
{
return false;
}
}
示例10: check_deadline
void check_deadline()
{
// The deadline may have moved, so check it has really passed.
if (request_deadline_.expiry() <= std::chrono::steady_clock::now())
{
// Close socket to cancel any outstanding operation.
boost::beast::error_code ec;
socket_.close();
// Sleep indefinitely until we're given a new deadline.
request_deadline_.expires_at(
std::chrono::steady_clock::time_point::max());
}
request_deadline_.async_wait(
[this](boost::beast::error_code)
{
check_deadline();
});
}
示例11: find
void L2Socket::Disconnect(tcp::socket& _socket,size_t _agentOID)
{
//return;
if( _agentOID != -1 )
{
UIntAry::iterator _it = find( agentOIDAry.begin(),agentOIDAry.end(),_agentOID );
if( _it != agentOIDAry.end() )
{
shared_ptr<L2Agent> agt = L2_FIND_OBJ(L2Agent, _agentOID);
agt->Disconnect();
agentOIDAry.erase( _it );
LOG( "Disconnect !!! ip: "+_socket.remote_endpoint().address().to_string()+" port: "+ _socket.remote_endpoint().port() );
}
}
else
LOG( "Disconnect !!!" );
_socket.close();
SocketAry::iterator _it = find( sockAry.begin(),sockAry.end(),&_socket );
if( _it != sockAry.end() ) sockAry.erase( _it );
}
示例12: resolver
NetworkDevice(Stats &stats, const char *address)
: Device(stats), socket(io_service)
{
stringstream portstr;
portstr << SERVER_PORT;
tcp::resolver resolver(io_service);
tcp::resolver::query query(address, portstr.str());
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;
boost::system::error_code error = boost::asio::error::host_not_found;
while(error && endpoint_iterator != end)
{
socket.close();
socket.connect(*endpoint_iterator++, error);
}
if(error)
throw boost::system::system_error(error);
mem_counter = 0;
}
示例13: do_close
void do_close() {
clientSocket.close();
};
示例14: do_close
void do_close()
{
socket_.close();
}
示例15:
void
session::perform(tcp::socket& s, asio::yield_context) {
s.close();
}