Beispiel #1
0
inline boost::system::error_code connect(
    boost::asio::ip::tcp::socket::lowest_layer_type& socket,
    boost::asio::ip::tcp::resolver& resolver,
    const url& u, boost::system::error_code& ec)
{
  // Create a query that corresponds to the url.
  std::ostringstream port_string;
  port_string << u.port();

  // Get a list of endpoints corresponding to the query.
  boost::asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(u.host(), port_string.str(), ec);
  if (ec)
    return ec;

  // Try each endpoint until we successfully establish a connection.
  ec = boost::asio::error::host_not_found;
  boost::asio::connect(socket, endpoints, ec);
  if (ec)
    return ec;

  // Disable the Nagle algorithm on all sockets.
  ec = boost::system::error_code();
  socket.set_option(boost::asio::ip::tcp::no_delay(true), ec);
  return ec;
}
Beispiel #2
0
boost::asio::ip::tcp::resolver::iterator WrapResolve(
		boost::asio::ip::tcp::resolver& resolver,
		boost::asio::ip::tcp::resolver::query& query,
		boost::system::error_code* err)
{
	boost::asio::ip::tcp::resolver::iterator resolveIt;

	if (err == NULL) {
		resolveIt = resolver.resolve(query);
	} else {
		resolveIt = resolver.resolve(query, *err);
	}
//#ifdef STREFLOP_H
	// (date of note: 08/22/10)
	// something in resolve() is invalidating the FPU flags
	streflop::streflop_init<streflop::Simple>();
//#endif

	return resolveIt;
}
	void connect(const std::string& host, const std::string& port){
		auto endpoint_it = _resolver.resolve({host, port});
		boost::asio::async_connect(_socket, endpoint_it,
				[this](boost::system::error_code ec, boost::asio::ip::tcp::resolver::iterator)
				{
			if (!ec)
			{
				doReadHeader();
			}
				});
	}
Beispiel #4
0
std::vector < std::string > asio_bindings::single_hostname_to_dns(std::string hostname,
                                                                  boost::asio::ip::tcp::resolver& resolver_ptr){
  std::vector < std::string > output;

  try{
    boost::asio::ip::tcp::resolver::query query(hostname, "");
    boost::asio::ip::tcp::resolver::iterator destination = resolver_ptr.resolve(query);
    boost::asio::ip::tcp::resolver::iterator end;
    boost::asio::ip::tcp::endpoint endpoint;

    while (destination != end){
      endpoint = *destination++;
      output.push_back(endpoint.address().to_string());
    }
  } catch(...){
    output.push_back("Not resolved");
  }

  return output;
}
Beispiel #5
0
std::vector < std::string > asio_bindings::single_ip_to_dns(std::string ip_address,
                                                          boost::asio::ip::tcp::resolver& resolver_ptr){
  std::vector < std::string > output;
  boost::asio::ip::tcp::endpoint endpoint;

  try{

    boost::asio::ip::address ip = boost::asio::ip::address::from_string(ip_address);
    endpoint.address(ip);
    boost::asio::ip::tcp::resolver::iterator destination = resolver_ptr.resolve(endpoint);
    boost::asio::ip::tcp::resolver::iterator end;
    for (int i=1; destination != end; destination++, i++) {
      output.push_back(destination->host_name());
    }

  } catch(...){
    output.push_back("Invalid IP address");
  }

  return output;
}