I see... I gave for granted that asio was using its own thread do everything... I've been using other libraries and they were working like this.... Sorry, I've been very quick in jumping around the docs... RTFM!


2009/7/27 Igor R <boost.lists@gmail.com>
The message title a bit missleading: it's not asio that doesn't work,
but your application :).
Please see the comments below.

> msgSrv::msgSrv(int listenPort) {
>    // TODO Auto-generated constructor stub
>    this->listenPort = listenPort;
>    try {
>        asioIoService = new asio::io_service();
>        asioSocket = new asio::ip::udp::socket(*asioIoService,
>                asio::ip::udp::endpoint(asio::ip::udp::v4(),
> listenPort)); //new asio::ip::udp::socket_(*asioIoService,
> udp::endpoint(udp::v4(), listenPort));
>    } catch (std::exception &e) {
>        std::cerr << "Error initializing ioservice or socket:" <<
> e.what();
>    }
>    asioIoService->run();

You run() io_service that doesn't have any work, so run() exits
immediately. Then you enqueue some async.request, and your applciation
exits, freeing "msgSrv" object and deleting the io_service and the
socket. The request you enqueued is still alive, but an attempt to
process it causes crash, because you already deleted all the asio
stuff...
Note that if io_service had some work (eg, pending async_XXX requests,
or asio::work object) before you called run(), it would block until
all the work is processed.
Please see asio tutorial and examples for more information.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users