views:

108

answers:

1

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?

+1  A: 

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)

Cubbi
This code printed "select" for me.After some digging in epoll_reactor_fwd.hpp and some more testing, the LINUX_VERSION_CODE is returning a version less that 2.4.45 (which is required to use epoll, apparently).uname -r returns the following:$uname -r2.6.9-78.0.13.ELsmpIf fool with the required kernel in epoll_reactor_fwd.hpp I can get your program to output "epoll". Is this some sort of server configuration error?
Scott Lawson
Indeed seems so. My dev system outputs LINUX_VERSION_CODE as 132639 or KERNEL_VERSION (2,6,31) (and it was shipped with 2.6.31.5 - it's an OpenSUSE). What would happen if you rebuild boost from source?
Cubbi
@Cubbi Boost.Asio is header only, I doubt rebuilding boost will help.
Sam Miller
Took another look: LINUX_VERSION_CODE is defined in /usr/include/linux/version.h -- perhaps the server simply has wrong kernel headers installed.
Cubbi
After changing the appropriate values in /usr/include/linux/version.h asio appears to be using epoll. I'm a little worried that adjusting these values will have other side effects but its okay for the time being. I might rebuild boost despite asio being header-only. It does require the boost::system lib, and there may be something bad lurking as a result. Thanks all for help.
Scott Lawson