You want one io_service per endpoint, not per application.

On Monday, June 18, 2018, Richard Hodges via Boost-users <boost-users@lists.boost.org> wrote:
A note of caution.

In all but the most exceptional of cases, you will want one io_service per application. 

Rather than tie the entire application to one instance of a class, which might make testing difficult, you may want to consider providing the io_service to the Foo as a dependency injection, with its lifetime controlled by main().

Example (including the fixed constructor):

#include <boost/asio.hpp>

class foo
{
public:

    foo(boost::asio::io_service& ios); // Constructor.

private:

    boost::asio::io_service& ios;

    boost::asio::ip::udp::socket sock;
};

foo::foo(boost::asio::io_service& ios)
: ios(ios)
, sock(ios)
{
}


int main()
{
    boost::asio::io_service myios;
    
    foo f1(myios);  // note - io_service is injected
    foo f2(myios);
    
    //... generate events etc
    
    myios.run();
    
    // now destroy foos and lastly, myios
}


On Mon, 18 Jun 2018 at 15:46, Vinnie Falco via Boost-users <boost-users@lists.boost.org> wrote:
On Mon, Jun 18, 2018 at 6:13 AM Álvaro Cebrián Juan via Boost-users
<boost-users@lists.boost.org> wrote:
> Why doing sock(ios); doesn't work?

What is the complete error message from the compiler?

Thanks
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users