2010-06-23 40 views
5

我的印象是boost :: asio会默认使用epoll设置,而不是选择实现,但在运行一些测试后,它看起来像我的设置使用select。在不使用Epoll的Linux上增强Asio

OS: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

您的程序也会为我选择“select”,但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; 
} 

(的ifd​​ef的梯子从/usr/include/boost/asio/serial_port_service.hpp抢下)

+0

此代码印有 “选择” 对我来说。 在epoll_reactor_fwd.hpp进行了一些挖掘以及更多测试之后,LINUX_VERSION_CODE返回的版本小于2.4.45(这显然是使用epoll所必需的)。 使用uname -r返回如下: $使用uname -r 2.6.9-78.0.13.ELsmp 如果傻瓜在epoll_reactor_fwd.hpp我可以让你的程序输出“epoll的”所需的内核。这是某种服务器配置错误? – 2010-06-24 00:44:28

+0

确实如此。我的开发系统输出LINUX_VERSION_CODE为132639或KERNEL_VERSION(2,6,31)(并且与2.6.31.5一起发货 - 这是一个OpenSUSE)。如果你从源码重建boost,会发生什么? – Cubbi 2010-06-24 01:55:04

+0

Boost.Asio只是头部,我怀疑重建助力会有帮助。 – 2010-06-24 03:01:42