Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost Asio On Linux Not Using Epoll

I was under the impression that boost::asio would use an epoll setup by default instead of a select implementation, but after running some tests it looks like my setup is using select.

OS: RHEL 4
Kernel:2.6
GCC:3.4.6

I wrote a little test program to verify which reactor header was being used, and it looks like its using the select reactor rather than the epoll reactor.

#include <boost/asio.hpp>

#include <string>
#include <iostream>

std::string output;

#if defined(BOOST_ASIO_EPOLL_REACTOR_HPP)

int main(void)
{
    std::cout << "you have epoll enabled." << std::endl;
}

#elif defined(BOOST_ASIO_DETAIL_SELECT_REACTOR_HPP)

int main(void)
{
    std::cout << "you have select enabled." << std::endl;
}

#else

int main(void)
{
    std::cout << "this shit is confusing." << std::endl;
}


#endif

What could I be doing wrong?

like image 946
Scott Lawson Avatar asked Jun 23 '10 23:06

Scott Lawson


1 Answers

Your program says "select" for me too, yet asio is using epoll_wait(), as ps -Teo tid,wchan:25,comm reports.

How about

#include <iostream>
#include <string>
#include <boost/asio.hpp>
int main()
{
std::string output;
#if defined(BOOST_ASIO_HAS_IOCP)
  output = "iocp" ;
#elif defined(BOOST_ASIO_HAS_EPOLL)
  output = "epoll" ;
#elif defined(BOOST_ASIO_HAS_KQUEUE)
  output = "kqueue" ;
#elif defined(BOOST_ASIO_HAS_DEV_POLL)
  output = "/dev/poll" ;
#else
  output = "select" ;
#endif
    std::cout << output << std::endl;
}

(the ladder of ifdefs grabbed from /usr/include/boost/asio/serial_port_service.hpp)

like image 136
Cubbi Avatar answered Nov 03 '22 18:11

Cubbi