c++ - 在不使用 Epoll 的 Linux 上 boost Asio

标签 c++ linux boost boost-asio epoll

我的印象是 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/

相关文章:

c++ - 如何覆盖静态二进制文件的 C++ 启动函数?

c++ - 将文件加载到 vector <unsigned char>中

linux - 运行系统中pthread_mutex的数量

c++ - 使用键属性 vector boost 多索引

c++ - 由于更改cpp目录导致的链接问题

c++ - 如何在全局范围内添加包含路径到 clang

c++ - 如果其中没有任何内容,循环会更快吗?

c - 如何模拟内存分配错误

java - 通过java代码登录Linuxbox

c++ - 在 darwin 上静态 boost 包括 libstdc++?