本文整理汇总了C++中tcp::socket::async_connect方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::async_connect方法的具体用法?C++ socket::async_connect怎么用?C++ socket::async_connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcp::socket
的用法示例。
在下文中一共展示了socket::async_connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
}
示例2: handle_resolve
// Resolucion de la direccion del servidor
void handle_resolve(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator){
debugOUT("handle_resolve");
if (!err){
// Intentamos conectarnos al primer endpoint en la lista
tcp::endpoint endpoint = *endpoint_iterator;
socket_.async_connect( endpoint,
boost::bind(&TCPClient::handle_connect, this,
boost::asio::placeholders::error, ++endpoint_iterator));
}
else{
debugOUT("Error: " << err.message());
}
}
示例3: connectTo
void TCPMethod::connectTo(boost::asio::ip::address_v4 address, tcp::socket & socket)
{
uint64_t startTime = getMicroTime();
socket.async_connect(
tcp::endpoint(address, 22),
[address, startTime] (const boost::system::error_code & error) {
if(error == operation_aborted)
;
else if(error)
connectionerr << "TCPMethod::connectTo(" << address << "): " << error.message() << "\n";
else
{
uint64_t endTime = getMicroTime();
if(startTime < endTime)
Measurement::addMeasurement(address, "tcp", endTime - startTime);
}
}
);
}
示例4: resolve_handler
void resolve_handler(const boost::system::error_code &ec,
tcp::resolver::iterator it)
{
if (!ec)
tcp_socket.async_connect(*it, connect_handler);
}