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

前端 未结 3 1312
梦谈多话
梦谈多话 2020-11-27 03:43

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 fa

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 04:06

    A drawback is that you'll make a busy loop.

    while(true) {
        myIoService.poll()
    }
    

    will use 100% cpu. myIoService.run() will use 0% cpu.

    myIoService.run_one() might do what you want but it will block if there is nothing for it to do.

提交回复
热议问题