tags:

views:

188

answers:

1

I have code that looks like the following:

//unrelated code snipped
resolver.reset(new tcp::resolver(iosvc));
tcp::resolver::query query(host, port);
resolver->async_resolve(query,
    boost::bind(&TCPTransport::handle_resolve, this,
      boost::asio::placeholders::error,
      boost::asio::placeholders::iterator));

LOG4CXX_INFO(logger, "Attempting connection to at " << host << ":" << port);
//unrelated code snipped



void TCPTransport::handle_resolve(const boost::system::error_code& err,
  tcp::resolver::iterator endpoint_iterator)
{
  if (err)
  {
    LOG4CXX_ERROR(logger, "Error: " << err.message());
  }
  else
  {
    tcp::endpoint endpoint = *endpoint_iterator;
    if (!socket)
    {
      socket.reset(new tcp::socket(iosvc));
    }
    socket->async_connect(endpoint,
      boost::bind(&TCPTransport::handle_connect, this,
        boost::asio::placeholders::error, ++endpoint_iterator));
  }
}

When I run this code, with the appropriate gate and port of the server I know is up an running, I get the following text in my log file: Error: Service not found

Can anyone provide some insight into what this error actually means?

+1  A: 

In Boost it looks like that error can only happen as a result of a call to getaddrinfo(). In MSDN (for what it's worth), it sounds like the service name (or port) isn't supported for the types of socket that the caller (ASIO?) supports.

In other words, it seems like you're attempting a TCP connection on either a non-TCP socket (not likely, since you're using TCP classes for your DNS resolution) or to a non-TCP port (not sure what to do about that).

I recommend stepping into the code using a debugger to see what is going wrong, though that will be a lot easier if you use a synchronous call to resolve(). Otherwise you'll have to set multiple breakpoints on the various internal handlers that ASIO uses (not that bad, but still a nuisance). Hope that helps...

Brian