Saturday, February 5, 2011

how to implemet POSIX select() based behaviour, within boost::asio

Hello, I've already wasted two days reading documentation of boost::asio And I still don't know how could I implement blocking select() like function for several sockets using only one thread (using boost framework). Asynchronous functions of boost::asio returns immediately, so there would be a need to put some wait function in main thread untill one of the async_read's finishes. I suspect that this would time consuming, but I'm really restricted by performace requirements.

  • The io_service object is an abstraction of the select function. Set up your sockets and then call the io_service::run member function from your main thread. The io_service::run function will block until all of the work associated with the io_service instance is completed. You can schedule more work in your asynchronous handlers.

    You can also use io_service::run_one, io_service::poll, or io_service::poll_one in place of io_service::run.

    From Dan

0 comments:

Post a Comment