Boost logo

Boost Users :

Subject: Re: [Boost-users] Why boost::asio doesn't work???
From: Alex Black (alex_at_[hidden])
Date: 2009-07-27 12:29:51


Igor, that doesn't seem correct to me, from what I can tell (by reading the docs, and using it) is that io_service::run() will not return immediately if there is no work.

http://eckhart.stderr.org/doc/libasio-doc/reference/a00032.html#c84bed0d1dd061bc71010ba1228439da

"The run() function blocks until all work has finished and there are no more handlers to be dispatched, or until the io_service has been stopped."

> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Igor R
> Sent: Monday, July 27, 2009 6:31 AM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Why boost::asio doesn't work???
>
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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