很显Ӟ文章的标题决定了我们是在linux下用ACE。我们知道ACE在linux下缺省是用select来实现Reactor的,epoll相对于select的好处这里就不再啰嗦了,我们直接讲操作步?
W一Q重新编译ACE?br> ACE库中通过ACE_Dev_Poll_ReactorcL支持epoll,但是ACE库缺省的安装是没有编译这个类的,我们要做的就是将ACE_Dev_Poll_Reactor~译q接到ACE库中(faint,又要重新~译ACEQ在我那台破服务器上~译一ơ需要一个多时).我的操作pȝ是Redhat linux AS4.0,ACE的版本是5.4.10。根据ACE压羃包中的ACE-INSTALL.htmlQ我是用”Building ACE with GNU Autoconf“q种方式来安装的Q安装步骤如?很简?׃译?:
1 cd to the top-level ACE_wrappers directory.
2.Create a subdirectory to hold your build’s configuration and built ACE version, and then change to the new directory:
mkdir build
cd build
3.Note that you do not run the create_ace_build.pl utility mentioned in the Cloning the Source Tree section. The configure script takes care of creating all files and links that are needed.
Configure ACE for your platform by issuing the following command: c
../configure [options]
4.Build ACE by typing make.
5. Install ACE by typing make install.
好,现在l于可以讲如何将ACE_Dev_Poll_Reactor~译到ACE库中M。在上述的第一步和W二步之间修改ACE_wrappers/ace/config-linux.h,增加一行:(x)#define ACE_HAS_EVENT_POLLQ然后执行第2?步,W??./configure执行完之后,build目录下会(x)生成一些文件和目录Q打开ACE_wrappers/build/ace/config.h,增加一行:(x)#define ACE_HAS_EVENT_POLL。然后执行第4步make和第5步make install.OKQ在漫长的编译以后,支持epoll的ACE库ȝ完成了?/p>
W二Q修改应用程?br> 应用E序修改很简单,两行代码搞掂,在应用程序初始化?必须是在W一ơ用ACE_Reactor::instance()之间)加入:
m_pDevPollReactor=new ACE_Dev_Poll_Reactor;
ACE_Reactor::instance(new ACE_Reactor(m_pDevPollReactor));
那么在后l的对ACE_Reactor::instance()的调用就是用ACE_Dev_Poll_Reactor的实C?br>
W三Q重新编译应用程?br>
在应用程序的makefile中加?nbsp;-DACE_HAS_EVENT_POLL,重新make应用E序。OK,打完收工?br>