16

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?

brad
  • 930
  • 9
  • 22
eltonsky
  • 367
  • 2
  • 11
  • 1
    +1 this may seem like a basic question, but I've found new users to the asio library are often confused by this concept. – Sam Miller Jan 20 '13 at 15:35

3 Answers3

8

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.

Igor R.
  • 14,716
  • 2
  • 49
  • 83
8

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.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
5

Boost.Asio does provide a select like functionality using null_buffers. https://stackoverflow.com/a/4686523/1134207 explains more.

Community
  • 1
  • 1
Ishan Arora
  • 148
  • 3
  • 8