Boost logo

Boost Users :

Subject: [Boost-users] [asio]remote_endpoint throws exception
From: higashiyama_at_[hidden]
Date: 2014-06-12 07:18:48


Hi,

I wrote TCP client program using boost::asio.

OS: Debian GNU/Linux (x86_64)
Boost: 1.49

I use asio::ip::tcp::socket::async_conect function and I called ip::tcp::socket::remote_endpoint at async_connect callback.
Like this:

// async_resolve handler
void my_class::handle_resolve(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
{
   if (!error) {
       socket_.async_connect(endpoint, strand_.wrap(...));
   }
}

void my_class::handle_connect(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
{
   if (!error) {
       // socket_ is my_class member.
       socket_.remote_endpoint(); // throw exception !
   }
   ...
}

ip::tcp::socket::remote_endpoint sometime throws boost::system::system_error exception (error message is "remote_endpoint: Transport endpoint is not connected").
But async_connect is successfully completed.
Why does remote_endpoint function throw exception?

Thank you,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net