Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select functionality in boost::asio

I am going to use boost::asio lib for my project. But it's not quite obvious which function is corresponding to select() from native socket C lib. Is that available in asio? Or does boost provide an alternative to find out if a socket is ready?

like image 384
eltonsky Avatar asked Jan 20 '13 08:01

eltonsky


2 Answers

The high-level design of Boost.Asio is based on the Proactor desing pattern. Thus, you don't need to poll on select. Instead, submit your completion handler for an asynchronous operation, and when the operation gets completed - the completion handler gets called.

like image 155
Igor R. Avatar answered Sep 19 '22 05:09

Igor R.


The documentation has a specific section for mapping the BSD socket API calls into their respective Asio equivalent

poll(), select(), pselect()

io_service::run(), io_service::run_one(), io_service::poll(), io_service::poll_one()

Note: in conjunction with asynchronous operations.

Note that there are subtle differences between each of these io_service methods, picking the correct one will depend on your application design.

like image 29
Sam Miller Avatar answered Sep 22 '22 05:09

Sam Miller