在不使用Epoll的Linux上增强Asio

Sco*_*son 5 c++ linux boost epoll boost-asio

我的印象是boost :: asio默认使用epoll设置而不是select实现,但是在运行一些测试之后看起来我的设置是使用select.

操作系统:RHEL 4
内核:2.6
GCC:3.4.6

我写了一个小测试程序,以验证正在使用哪个反应器头,看起来它使用选择反应器而不是epoll反应器.

#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
Run Code Online (Sandbox Code Playgroud)

我能做错什么?

Cub*_*bbi 5

您的程序也对我说“选择”,但 asio 正在使用 epoll_wait() 作为ps -Teo tid,wchan:25,comm报告。

怎么样

#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;
}
Run Code Online (Sandbox Code Playgroud)

(ifdefs 的梯子从 抓起/usr/include/boost/asio/serial_port_service.hpp