我的印象是 boost::asio 默认会使用 epoll 设置而不是 select 实现,但在运行一些测试后,我的设置似乎正在使用 select。
操作系统:RHEL 4
内核:2.6
海湾合作委员会:3.4.6
我写了一个小测试程序来验证正在使用哪个 react 堆头,看起来它使用的是 select react 堆而不是 epoll react 堆。
#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
抓取)
关于c++ - 在不使用 Epoll 的 Linux 上 boost Asio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3106304/