[Boost-bugs] [Boost C++ Libraries] #13477: Initializing boost::asio socket after constructor failed

Subject: [Boost-bugs] [Boost C++ Libraries] #13477: Initializing boost::asio socket after constructor failed
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-03-13 07:24:42


#13477: Initializing boost::asio socket after constructor failed
-------------------------------------------------+-------------------------
 Reporter: nguyen.tnhoang@… | Owner:
                                                 | chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.66.0 | Severity: Showstopper
 Keywords: c++ asio boost shared_ptr |
  boost::ref |
-------------------------------------------------+-------------------------
 I create a class to broadcast UDP messages as in the attached socket.cpp
 file. It works fine.
 Then, I wish to initialize the socket after the class constructor is
 initialized (to allow user input). So, I change from using socket to a
 socket pointer as in the socketPtr.cpp.

 It is a solution suggested by this post
 (https://stackoverflow.com/questions/31371214/initializing-boostasio-
 sockets-after-constructor).

 The replacements are as follows, where io_service is wrapped as
 boost::ref(io_service):

 //boost::asio::ip::udp::socket socket;
 boost::shared_ptr<udp::socket> socketPtr;

 //boost::asio::ip::udp::socket socket(io_service, endpoint.protocol());
 //socket.set_option(boost::asio::ip::udp::socket::reuse_address(true));
 socketPtr = boost::make_shared<udp::socket>(boost::ref(io_service),
 endpoint.protocol());
 socketPtr->set_option(boost::asio::ip::udp::socket::reuse_address(true));

 //socket.async_send_to(boost::asio::buffer(message), endpoint,
 [this](boost::system::error_code ec, std::size_t /*length*/)
 socketPtr->async_send_to(boost::asio::buffer(message), endpoint,
 [this](boost::system::error_code ec, std::size_t /*length*/)

 Just one thing with the modification: it doesn't work. I keep poring over
 the code, and could not find the reason why it shouldn't work. Could
 someone please help?

-- 
Ticket URL: <https://svn.boost.org/trac10/ticket/13477>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2018-03-13 07:28:52 UTC