Boost::Asio : io_service.run() vs poll() or how do I integrate boost::asio in mainloop

Posted by user300713 on Stack Overflow See other posts from Stack Overflow or by user300713
Published on 2011-01-16T12:46:50Z Indexed on 2011/01/16 12:53 UTC
Read the original article Hit count: 430

Filed under:
|
|
|

Hi,

I am currently trying to use boost::asio for some simple tcp networking for the first time, and I allready came across something I am not really sure how to deal with. As far as I understand io_service.run() method is basically a loop which runs until there is nothing more left to do, which means it will run until I release my little server object. Since I allready got some sort of mainloop set up, I would rather like tp update the networking loop manually from there just for the sake of simplicity, and I think io_service.poll() would do what I want, sort of like this:

void myApplication::update()
{
     myIoService.poll();
     //do other stuff
}

This seems to work, but I am still wondering if there is a drawback from this method since that does not seem to be the common way to deal with boost::asios io services. Is this a valid approach or should I rather use io_service.run() in a non blocking extra thread?

© Stack Overflow or respective owner

Related posts about c++

Related posts about networking