/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// This example is from the ACE Programmers Guide.
////  Chapter:  "The Reactor" (Event Management)
//// For details please see the guide at
//// http://www.cs.wustl.edu/~schmidt/ACE.html
////  AUTHOR: Umar Syyid (usyyid@hns.com)
//// and Ambreen Ilyas (ambreen@bitsmart.com)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Example 4
#include "ace/Reactor.h"
#include "ace/Event_Handler.h"
#include "ace/Synch_T.h"
#include "ace/Thread_Manager.h"
#define WAIT_TIME 1
#define SLEEP_TIME 2

class My_Handler: public ACE_Event_Handler{
 public:

 //Start the event handling process.
 My_Handler(){
  ACE_DEBUG((LM_DEBUG,"Event Handler created\n"));
  ACE_Reactor::instance()->max_notify_iterations(5);
  return 0;
  }

//Perform the notifications i.e., notify the reactor 10 times
 void perform_notifications(){
  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;
  }
private:
 static int no;
};

//Static members
int My_Handler::no=1;
 

int main(int argc, char *argv[]){
  //Instantiating the handler
 My_Handler handler;
 
 //The done flag is set to not done yet.
 int done=0;

while(1){
  //After WAIT_TIME the handle_events will fall through if no events arrive.
  ACE_Reactor::instance()->handle_events(ACE_Time_Value(WAIT_TIME));
  if(!done){
   handler.perform_notifications();
   done=1;
   }
  sleep(SLEEP_TIME);
 }
}

 Next Example