Boost Asio On Linux Not Using Epoll

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

I was under the impression that boost::asio would use an epoll setup by default instead of a select implementation, but after running some tests it looks like my setup is using select.

OS: RHEL 4
Kernel:2.6
GCC:3.4.6

I wrote a little test program to verify which reactor header was being used, and it looks like its using the select reactor rather than the epoll reactor.

#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 

What could I be doing wrong?

回答1:

Your program says "select" for me too, yet asio is using epoll_wait(), as ps -Teo tid,wchan:25,comm reports.

How about

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

(the ladder of ifdefs grabbed from /usr/include/boost/asio/serial_port_service.hpp)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!