5

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

我可能做错了什么?

4

1 回答 1

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;
}

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

于 2010-06-24T00:12:42.173 回答