Boost :: system :: error_code :: message () access violation exception for access with boost :: asio socket

I am implementing a client application that needs to make a small number of socket connections to hardware devices. I broke the problem into the following small subset of code

boost::system::error_code ec;
std::string str_message = ec.message();  // no access violation before connect()
std::string str_port = "502";
std::string str_ip = "192.168.12.198";

boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(),str_ip,str_port);
boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
boost::asio::ip::tcp::socket s(io_service);

ec = s.connect(*iterator,ec);
if (ec)
{
    // connection error of some kind.
    std::string str_debug = ec.message();  // BANG!!!!

}

Embarcadero RAD studio XE4 ++ Builder, VCL, . , , TThread, . , error_code connect, m_cat error_code NULL, , message(), . , .

, , ? , , .

, , 1,50, , 64- RAD.

- ( Embarcadero ), , ? ?

+4
3

, , , :

system::error_code : . - int, Singleton. , (.. , ).

, Singleton . Asio system_category, boost/libs/system/src/error_code.cpp. 1.50 :

BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
{
  static const system_error_category  system_category_const;
  return system_category_const;
}

++ 11 , - stat-scope statics, . , , .

+5
+1

, iterator != boost::asio::ip::tcp::resolver::iterator().

:

.

I am sure the problem is connect()simply breaking the stack due to an invalid endpoint iterator.

+1
source

Source: https://habr.com/ru/post/1524360/


All Articles