Linux 上的 Boost Asio 不使用 Epoll

2024-03-08

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

操作系统:RHEL 4
内核:2.6
海湾合作委员会:3.4.6

我编写了一个小测试程序来验证正在使用哪个反应器标头,看起来它使用的是 select 反应器而不是 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

我可能做错了什么?


你的程序也对我说“选择”,但 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;
}

(ifdefs的梯子是从/usr/include/boost/asio/serial_port_service.hpp)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux 上的 Boost Asio 不使用 Epoll 的相关文章

随机推荐