关于ACE程序员指南上的一个示例程序
#include <ace/Reactor.h>
#include <ace/Event_Handler.h>
#include <ace/Synch_T.h>
#include <ace/Thread_Manager.h>
class My_Handler: public ACE_Event_Handler
{
public:
//Start the event handling process.
My_Handler()
{
ACE_DEBUG((LM_DEBUG,"Got open\n"));
activate_threads();
ACE_Reactor::instance()->max_notify_iterations(10);
}
//Spawn a separate thread so that it notifies the reactor
void activate_threads()
{
ACE_Thread_Manager::instance()->spawn((ACE_THR_FUNC)svc_start,(void*)this);
}
//Notify the Reactor 10 times.
void svc()
{
for(int i=0;i<10;i++)
ACE_Reactor::instance()->notify(this, ACE_Event_Handler::READ_MASK);
}
//The actual handler which in this case will handle the notifications
int handle_input(int)
{
ACE_DEBUG((LM_DEBUG, "Got notification # %d\n", no));
no++;
return 0;
}
//The entry point for the new thread that is to be created.
static int svc_start(void* arg);
private:
static int no;
};
//Static members
int My_Handler::no=1;
int My_Handler::svc_start(void* arg)
{
My_Handler *eh= (My_Handler*)arg;
eh->svc();
return -1; //de-register from the reactor
}
int main(int argc, char *argv[])
{
ACE_DEBUG((LM_DEBUG,"Starting test \n"));
My_Handler handler;
while(1)
{
ACE_Reactor::instance()->handle_events(ACE_Time_Value(3));
}
}
win32平台下不能正常运行,有调试过的吗?ACE5.5版本,编译器是vc6,c++库用的stlport4.6.2 书上具体哪个示例程序我没有找到,但是,错误应该出在handle_input()上,把"int handle_input(int)"改成"virtual int handle_input(ACE_HANDLE)"就可以了,因为handle_input()是个挂钩方法,所以,上面的例子那样写是的不到结果的
页:
[1]