Exemplo n.º 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;
}
Exemplo n.º 2
0
 void do_stop (CompletionCounter)
 {
     m_journal.debug << "Stopped";
     m_stopped = true;
     m_work.clear ();
     m_resolver.cancel ();
     removeReference ();
 }
Exemplo n.º 3
0
auto dns(Func handler,
	boost::asio::ip::tcp::resolver& resolver,
	std::string address,
	std::string port)
{
	boost::asio::ip::tcp::resolver::query query(address, port);
	return resolver.async_resolve(query, handler);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
	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();
			}
				});
	}
Exemplo n.º 6
0
    //-------------------------------------------------------------------------
    // Resolver
    void do_stop (CompletionCounter)
    {
        assert (m_stop_called == true);

        if (m_stopped.exchange (true) == false)
        {
            m_work.clear ();
            m_resolver.cancel ();

            removeReference ();
        }
    }
Exemplo n.º 7
0
    void do_work (CompletionCounter)
    {
        if (m_called_stop.load () == 1)
            return;

        // We don't have any work to do at this time
        if (m_work.empty())
        {
            m_idle = true;
            m_journal.trace << "Sleeping";
            return;
        }

        if (m_work.front().names.empty())
            m_work.pop_front();

        std::string const name (m_work.front().names.back());
        HandlerType handler (m_work.front().handler);

        m_work.front().names.pop_back();

        HostAndPort const hp (parseName(name));

        if (hp.first.empty())
        {
            m_journal.error <<
                "Unable to parse '" << name << "'";

            m_io_service.post (m_strand.wrap (boost::bind (
                &NameResolverImpl::do_work, this,
                CompletionCounter(this))));

            return;
        }

        boost::asio::ip::tcp::resolver::query query (
            hp.first, hp.second);

        m_resolver.async_resolve (query, boost::bind (
            &NameResolverImpl::do_finish, this, name,
            boost::asio::placeholders::error, handler,
            boost::asio::placeholders::iterator,
            CompletionCounter(this)));
    }
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
    void do_work (CompletionCounter)
    {
        if (m_stop_called == true)
            return;

        // We don't have any work to do at this time
        if (m_work.empty ())
            return;

        std::string const name (m_work.front ().names.back());
        HandlerType handler (m_work.front ().handler);

        m_work.front ().names.pop_back ();

        if (m_work.front ().names.empty ())
            m_work.pop_front();

        HostAndPort const hp (parseName (name));

        if (hp.first.empty ())
        {
            JLOG(m_journal.error()) <<
                "Unable to parse '" << name << "'";

            m_io_service.post (m_strand.wrap (std::bind (
                &ResolverAsioImpl::do_work, this,
                CompletionCounter (this))));

            return;
        }

        boost::asio::ip::tcp::resolver::query query (
            hp.first, hp.second);

        m_resolver.async_resolve (query, std::bind (
            &ResolverAsioImpl::do_finish, this, name,
                std::placeholders::_1, handler,
                    std::placeholders::_2,
                        CompletionCounter (this)));
    }
Exemplo n.º 11
0
	void start() {
		if (!_cancelled)
			_resolver.async_resolve(_q, boost::bind(&FriendConnector::hostResolved, shared_from_this(), asio::placeholders::error, asio::placeholders::iterator));
	}