bua
bua

Reputation: 4880

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

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

Upvotes: 2

Views: 2333

Answers (1)

Dan
Dan

Reputation: 3635

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.

Upvotes: 2

Related Questions