Ejemplo n.º 1
1
  void
  Sender_exec_i::start (void)
  {
    ACE_Reactor* reactor = 0;

    ::CORBA::Object_var ccm_object = this->ciao_context_->get_CCM_object();
    if (!::CORBA::is_nil (ccm_object.in ()))
      {
        ::CORBA::ORB_var orb = ccm_object->_get_orb ();
        if (!::CORBA::is_nil (orb.in ()))
          {
            reactor = orb->orb_core ()->reactor ();
          }
      }

    if (reactor)
      {
        // calculate the interval time
        long const usec = 1000000 / this->rate_;
        if (reactor->schedule_timer (
                    this->ticker_,
                    0,
                    ACE_Time_Value (3, usec),
                    ACE_Time_Value (0, usec)) == -1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Sender_exec_i::start : ")
                                ACE_TEXT ("Error scheduling timer")));
        }
      }
    else
      {
        throw ::CORBA::INTERNAL ();
      }
  }
Ejemplo n.º 2
0
int
ImR_Activator_i::handle_exit (ACE_Process * process)
{
  if (debug_ > 0)
    {
      ORBSVCS_DEBUG
        ((LM_DEBUG,
          ACE_TEXT ("Process %d exited with exit code %d, delay = %d\n"),
          process->getpid (), process->return_value (), this->induce_delay_));
    }

  if (this->induce_delay_ > 0 && this->active_check_pid_ == ACE_INVALID_PID)
    {
      ACE_Reactor *r = this->orb_->orb_core()->reactor();
      ACE_Time_Value dtv (0, this->induce_delay_ * 1000);
      pid_t pid = process->getpid();
      Act_token_type token = static_cast<Act_token_type>(pid);
      r->schedule_timer (this, reinterpret_cast<void *>(token), dtv );
    }
  else
    {
      this->handle_exit_i (process->getpid());
    }
  return 0;
}
Ejemplo n.º 3
0
void
device_averager::activate()
{
    doit( device_state::command_initialize );
    ACE_Reactor * reactor = acewrapper::singleton::ReactorThread::instance()->get_reactor();
    reactor->schedule_timer( this, 0, ACE_Time_Value(1), ACE_Time_Value(1) );
}
Ejemplo n.º 4
0
int
ImR_Activator_i::handle_exit (ACE_Process * process)
{
  if (debug_ > 0)
    {
      ORBSVCS_DEBUG
        ((LM_DEBUG,
        ACE_TEXT ("Process %d exited with exit code %d\n"),
        process->getpid (), process->return_value ()));
    }

  if (this->induce_delay_ > 0)
    {
      ACE_Reactor *r = this->orb_->orb_core()->reactor();
      ACE_Time_Value dtv (0, this->induce_delay_ * 1000);
      pid_t pid = process->getpid();
#if (ACE_SIZEOF_VOID_P == 8)
      ACE_INT64 token = static_cast<ACE_INT64>(pid);
#else
      ACE_INT32 token = static_cast<ACE_INT32>(pid);
#endif

      r->schedule_timer (this, reinterpret_cast<void *>(token), dtv );
    }
  else
    {
      this->handle_exit_i (process->getpid());
    }
  return 0;
}
Ejemplo n.º 5
0
void
Time_Handler::setup (void)
{
  ACE_Reactor *r = ACE_Reactor::instance ();

  this->timer_id_[2] = r->schedule_timer (this,
                                          (const void *) 2,
                                          ACE_Time_Value (3));
  this->timer_id_[3] = r->schedule_timer (this,
                                          (const void *) 3,
                                          ACE_Time_Value (4));
  this->timer_id_[4] = r->schedule_timer (this,
                                          (const void *) 4,
                                          ACE_Time_Value (5));
  return;
}
Ejemplo n.º 6
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Timer_Cancellation_Test"));

  ACE_Reactor reactor (new ACE_TP_Reactor,
                       1);

  Deadlock deadlock;
  deadlock.reactor (&reactor);

  Event_Handler handler (deadlock);

  // Scheduler a timer to kick things off.
  reactor.schedule_timer (&handler,
                          0,
                          ACE_Time_Value (1));

  // Run the event loop for a while.
  ACE_Time_Value timeout (4);
  reactor.run_reactor_event_loop (timeout);

  ACE_END_TEST;

  return 0;
}
Ejemplo n.º 7
0
void
Client_Peer::crash(void)
{
  Crasher * crasher = new Crasher;

  ACE_Time_Value clk_tck (0, Clock_Ticks::get_usecs_per_tick ());
  ACE_Reactor * reactor = this->orb_->orb_core()->reactor();
  reactor->schedule_timer(crasher, 0, clk_tck);
}
Ejemplo n.º 8
0
CORBA::Boolean
ImR_Activator_i::kill_server (const char* name, CORBA::Long lastpid, CORBA::Short signum)
{
  if (debug_ > 1)
    ORBSVCS_DEBUG((LM_DEBUG,
                   "ImR Activator: Killing server <%C>, lastpid = %d\n",
                   name, lastpid));
  pid_t lpid = static_cast<pid_t>(lastpid);
  pid_t pid = 0;
  bool found = false;
  int result = -1;
  for (ProcessMap::iterator iter = process_map_.begin();
       !found && iter != process_map_.end (); iter++)
    {
      if (iter->item () == name)
        {
          pid = iter->key ();
          found = pid == lpid;
        }
    }
  if (!found && pid == 0)
    {
      pid = lpid;
    }

#if defined (ACE_WIN32)
  found = false; // sigchild apparently doesn't work on windows
#endif
  if (pid != 0)
    {
      result =
#if !defined (ACE_WIN32)
        (signum != 9) ? ACE_OS::kill (pid, signum) :
#endif
        ACE::terminate_process (pid);

      if (this->running_server_list_.remove (name) == 0)
        {
          this->dying_server_list_.insert (name);
        }

      if (debug_ > 1)
        ORBSVCS_DEBUG((LM_DEBUG,
                       "ImR Activator: Killing server <%C> "
                       "signal %d to pid %d, found %d, this->notify_imr_ %d,  result = %d\n",
                       name, signum, static_cast<int> (pid), found, this->notify_imr_, result));
      if (!found && result == 0 && this->notify_imr_)
        {
          this->process_map_.bind (pid, name);
          ACE_Reactor *r = this->orb_->orb_core()->reactor();
          Act_token_type token = static_cast<Act_token_type>(pid);
          r->schedule_timer (this, reinterpret_cast<void *>(token), ACE_Time_Value ());
        }
    }
  return result == 0;
}
Ejemplo n.º 9
0
int
main (int argc, char**argv)
{
    // The worlds most useless user interface
    Widget top_level = XtVaAppInitialize (NULL,
                                          "buttontest",
                                          NULL,
                                          0,
                                          &argc,
                                          argv,
                                          NULL,
                                          NULL);
    Widget button = XmCreatePushButton (top_level,
                                        "change",
                                        0,
                                        0);
    XtManageChild (button);
    XtAddCallback (button,
                   XmNactivateCallback,
                   ActivateCB,
                   NULL);

    // A reactor beastie.
    ACE_XtReactor xreactor (XtWidgetToApplicationContext (top_level));
    ACE_Reactor reactor (&xreactor);

    // Print a message when data is recv'd on stdin...
    ACE_Event_Handler *stdin_;
    ACE_NEW_RETURN (stdin_,
                    Stdin (new Stdout (&reactor)),
                    -1);
    reactor.register_handler (stdin_,
                              ACE_Event_Handler::READ_MASK);

    // Print a message every 10 seconds.
    if (reactor.schedule_timer (stdin_, 0,
                                ACE_Time_Value (10),
                                ACE_Time_Value (10)) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "schedule_timer"),
                          -1);

    // Show the top_level widget.
    XtRealizeWidget (top_level);

    // Demonstrate Reactor/Xt event loop unification.
    XtAppMainLoop (XtWidgetToApplicationContext (top_level));

    return 0;
}
Ejemplo n.º 10
0
int
Time_Handler::svc (void)
{
  ACE_Reactor *r = ACE_Reactor::instance ();

  ACE_TEST_ASSERT (r->cancel_timer (this->timer_id_[2]) == 1);
  this->timer_id_[2] = Time_Handler::TIMER_CANCELLED;

  this->timer_id_[1] = r->schedule_timer(this,
                                         (const void *) 1,
                                         ACE_Time_Value (2));
  // This one may get the callback before we return, so serialize.
  this->lock_.acquire ();
  this->timer_id_[0] = r->schedule_timer(this,
                                         (const void *) 0,
                                         ACE_Time_Value (0, -5));
  this->lock_.release ();
  ACE_OS::sleep(3);

  this->timer_id_[5] = r->schedule_timer(this,
                                         (const void *)5,
                                         ACE_Time_Value (10));
  this->timer_id_[6] = r->schedule_timer(this,
                                         (const void *)6,
                                         ACE_Time_Value (12));

  ACE_TEST_ASSERT (r->cancel_timer (this->timer_id_[4]) == 1);
  this->timer_id_[4] = Time_Handler::TIMER_CANCELLED;

  // Test that cancelling a timers through a nill ACE_Event_Handler
  // pointer just does nothing instead of crash
  ACE_Event_Handler_var timer_var;
  ACE_TEST_ASSERT (r->cancel_timer (timer_var.handler()) == 0);

  return 0;
}
Ejemplo n.º 11
0
  void pause()
  {
    // get the reactor and set the timer.
    CORBA::ORB_var orb = TheServiceParticipant->get_ORB ();

    ACE_Reactor* reactor ;
    reactor = orb->orb_core()->reactor();

    if (reactor->schedule_timer(this,
                                0,
                                ACE_Time_Value(0,1)) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                 ACE_TEXT("(%P|%t) ERROR: PauseReactor, ")
                 ACE_TEXT(" %p. \n"), "schedule_timer"));
    }
  }
Ejemplo n.º 12
0
bool
iTaskManager::manager_initialize()
{
    if ( timerHandler_ == 0 ) {
	acewrapper::scoped_mutex_t<> lock( mutex_ );
	if ( timerHandler_ == 0 ) {
	    // initialize timer
	    timerHandler_ = new acewrapper::EventHandler< acewrapper::TimerReceiver<internal::TimeReceiver> >();
	    ACE_Reactor * reactor = iTaskManager::instance()->reactor();
	    reactor->schedule_timer( timerHandler_, 0, ACE_Time_Value(3), ACE_Time_Value(3) );
	}
	// activate task
	pTask_->open();
	return true;
    }
    return false;
}
Ejemplo n.º 13
0
CORBA::Boolean
ImR_Activator_i::kill_server (const char* name, CORBA::Long lastpid, CORBA::Short signum)
{
  if (debug_ > 1)
    ORBSVCS_DEBUG((LM_DEBUG,
                   "ImR Activator: Killing server <%s>...\n",
                   name));
  pid_t pid = static_cast<pid_t>(lastpid);
  bool found = false;
  int result = -1;
  for (ProcessMap::iterator iter = process_map_.begin();
       !found && iter != process_map_.end (); iter++)
    {
      if (iter->item () == name)
        {
          pid = iter->key ();
          found = true;
        }
    }
#if defined (ACE_WIN32)
  found = false; // sigchild apparently doesn't work on windows
#endif
  if (pid != 0)
    {
      result = (signum != 9) ? ACE_OS::kill (pid, signum)
        : ACE::terminate_process (pid);
      if (debug_ > 1)
        ORBSVCS_DEBUG((LM_DEBUG,
                       "ImR Activator: Killing server <%s> "
                       "signal %d to pid %d, result = %d\n",
                       name, signum, pid, result));
      if (!found && result == 0 && this->notify_imr_)
        {
          this->process_map_.bind (pid, name);
#if (ACE_SIZEOF_VOID_P == 8)
          ACE_INT64 token = static_cast<ACE_INT64>(pid);
#else
          ACE_INT32 token = static_cast<ACE_INT32>(pid);
#endif
          ACE_Reactor *r = this->orb_->orb_core()->reactor();
          r->schedule_timer (this, reinterpret_cast<void *>(token), ACE_Time_Value ());
        }
    }
  return result == 0;
}
Ejemplo n.º 14
0
int
Heartbeat_Application::register_for_timeouts (void)
{
  // Schedule timeout every 0.5 seconds, for sending heartbeat events.
  ACE_Time_Value timeout_interval (0, 500000);
  ACE_Reactor *reactor = this->orb_->orb_core ()->reactor ();
  if (!reactor
      || reactor->schedule_timer (&this->timeout_handler_, 0,
                                  timeout_interval,
                                  timeout_interval) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Heartbeat_Application::register_for_timeouts - "
                         "cannot schedule timer\n"),
                        -1);
    }

  return 0;
}
Ejemplo n.º 15
0
int
TAO_Acceptor::handle_accept_error (ACE_Event_Handler* base_acceptor)
{
  if (errno == EMFILE || errno == ENFILE)
    {
      if (TAO_debug_level > 0)
        TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - "
                              "TAO_Acceptor::handle_accept_error - "
                              "Too many files open\n"));

      // If the user has decided to stop accepting when the file handles
      // run out, just return -1;
      if (this->error_retry_delay_ == 0)
        return -1;

      // Get the reactor.  If there isn't one, which isn't very likely,
      // then just return -1.
      ACE_Reactor* reactor = base_acceptor->reactor ();
      if (reactor == 0)
        return -1;

      // So that the reactor doesn't completely remove this handler from
      // the reactor, register it with the except mask.  It should be
      // removed in the timer handler.
      reactor->register_handler (base_acceptor,
                                 ACE_Event_Handler::EXCEPT_MASK);

      // Remove the handler so that the reactor doesn't attempt to
      // process this handle again (and tightly spin).
      reactor->remove_handler (base_acceptor,
                               ACE_Event_Handler::ACCEPT_MASK |
                               ACE_Event_Handler::DONT_CALL);

      // Schedule a timer so that we can resume the handler in hopes
      // that some file handles have freed up.
      ACE_Time_Value timeout (this->error_retry_delay_);
      reactor->schedule_timer (base_acceptor, 0, timeout);
    }

  // We want to keep accepting in all other situations.
  return 0;
}
Ejemplo n.º 16
0
static void
run_svc (ACE_HANDLE handle)
{
  // The <callback> object is an <ACE_Event_Handler> created on the
  // stack.  This is normally not a good idea, but in this case it
  // works because the ACE_Reactor is destroyed before leaving this
  // scope as well, so it'll remove the <callback> object from its
  // internal tables BEFORE it is destroyed.
  Ping_Pong callback (string_name, handle);

  // Note that we put the <reactor> AFTER the <callback> so that the
  // <reactor> will get shutdown first.
  ACE_Reactor reactor;

  // Register the callback object for the various I/O, signal, and
  // timer-based events.

  if (reactor.register_handler (&callback,
				ACE_Event_Handler::READ_MASK
				| ACE_Event_Handler::WRITE_MASK) == -1
#if !defined (CHORUS)
      || reactor.register_handler (SIGINT,
                                   &callback) == -1
#endif /* CHORUS */
      || reactor.schedule_timer (&callback,
                                 0,
                                 SHUTDOWN_TIME) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "reactor"));
      ACE_OS::exit (1);
    }

  // Main event loop (one per process).

  while (callback.is_set () == 0)
    if (reactor.handle_events () == -1)
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "handle_events"));
}
Ejemplo n.º 17
0
int main (int, char* [])
{
    ACE_Reactor reactor;
    Time_Handler* th = new Time_Handler;
    int timer_id[NUMBER_TIMERS];
    for (int i = 0; i < NUMBER_TIMERS; i++)
	{
        timer_id[i] = reactor.schedule_timer(th,
                                              (const void *)i, // argument sent to handle_timeout()
                                              ACE_Time_Value(2 * i + 1)); //set timer to go off with delay
	}
	
    //Cancel the fifth timer before it goes off
    reactor.cancel_timer(timer_id[5]);//Timer ID of timer to be removed
    while (!done)
	{
        reactor.handle_events();
	}

    return 0;
}
Ejemplo n.º 18
0
int HandlersRegister::scheduleTimers (const ACE_Time_Value &p_TestTime)
{
  int i;

  for (i = 0; i < HandlersNo; ++i)
    {
      if (-1 == reactor_->schedule_timer (DgramHandlers_[ i ],
                                          (const void *) 0,
                                          ACE_Time_Value::zero,
                                          p_TestTime * (0.5 / DgramsToSend)))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT (" (%P) %p\n"),
                           ACE_TEXT ("Cannot schedule ACE timer")),
                          -1);

      DgramHandlers_[ i ] ->expectedTriggers (DgramsToSend);

    }

  return 0;
}
Ejemplo n.º 19
0
static void
run_svc (ACE_HANDLE handle)
{
  Ping_Pong *callback = 0;
  ACE_NEW (callback,
           Ping_Pong (ACE_TEXT_ALWAYS_CHAR (string_name),
                      handle));

  ACE_Reactor reactor;

  // Register the callback object for the various I/O, signal, and
  // timer-based events.

  if (reactor.register_handler (callback,
                                ACE_Event_Handler::READ_MASK
                                | ACE_Event_Handler::WRITE_MASK) == -1
#if !defined (CHORUS)
      || reactor.register_handler (SIGINT,
                                   callback) == -1
#endif /* CHORUS */
      || reactor.schedule_timer (callback,
                                 0,
                                 SHUTDOWN_TIME) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%p\n"),
                  ACE_TEXT ("reactor")));
      ACE_OS::exit (1);
    }

  // Main event loop (one per process).

  while (callback->is_set () == 0)
    if (reactor.handle_events () == -1)
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%p\n"),
                  ACE_TEXT ("handle_events")));
}
Ejemplo n.º 20
0
// implement state machine, send, wait (timeout/results) return
int transaction::run(transaction_result * r)
{
    result_ = r;
    int rc;

    // 1. register io port for read access
    ACE_Reactor * reactor = ACE_Reactor::instance();
    if (reactor->register_handler(session_.get_handle(),
                                  this,
                                  READ_MASK) == -1)
        return SNMP_CLASS_INTERNAL_ERROR;

    retry_counter_ = 0;

    // register a time handler and a socket with this
    ACE_Time_Value to = params_.get_timeout();
    if (reactor->schedule_timer(this, 0, to, to) < 0)
        return SNMP_CLASS_INTERNAL_ERROR;

    if ((rc = send()) < 0)      // send pkt to agent
        return rc;
    return 0;
}
Ejemplo n.º 21
0
char *
Simple_Server_i::test_method (Simple_Server_ptr objref)
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) test_method called\n"));
  if (CORBA::is_nil (objref))
    {
      ACE_ERROR ((LM_ERROR, "Nil object reference!\n"));
    }
  else
    {
      try
        {
          {
            ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
            if (!this->timer_registed_)
              {
                ACE_DEBUG ((LM_DEBUG, "(%P|%t) Scheduling timeout...\n"));
                ACE_Time_Value timeout (2, 0);
                ACE_Reactor * reactor = this->orb_->orb_core ()->reactor ();
                reactor->schedule_timer (this, (void*)0, timeout);
                this->timer_registed_ = true;
              }
          }
          ACE_DEBUG ((LM_DEBUG, "(%P|%t)  Calling test_method() on client, "
                      "which will sleep for 3 seconds\n"));
          CORBA::String_var str = objref->test_method (_this());
          ACE_DEBUG ((LM_DEBUG, "(%P|%t) Received \"%C\"\n", str.in ()));

        }
      catch (...)
        {
          ACE_ERROR ((LM_ERROR, "(%P|%t) Caught exception\n"));
        }
    }
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) leaving test_method\n"));
  return CORBA::string_dup("Hello world");
}
Ejemplo n.º 22
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("MT_Reactor_Timer_Test"));

  int status = 0;
  int test_result = 0;

  ACE_Reactor *r = ACE_Reactor::instance ();

  Dispatch_Count_Handler callback;

  for (int i = ACE_MAX_TIMERS; i > 0; i--)
    // Schedule a timeout to expire immediately.
    if (r->schedule_timer (&callback,
                           reinterpret_cast <const void *> (static_cast <size_t> (i)),
                           ACE_Time_Value (0)) == -1)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("schedule_timer")),
                        1);

  ACE_Time_Value no_waiting (0);
  size_t events = 0;

  while (1)
    {
      int result = r->handle_events (no_waiting);

      // Timeout.
      if (result == 0)
        break;

      // Make sure there were no errors.
      ACE_TEST_ASSERT (result != -1);

      events += result;
    }

  // All <ACE_MAX_TIMERS> + 2 I/O dispatches (one for <handle_input>
  // and the other for <handle_exception>) should be counted in
  // events.
  if (events < ACE_MAX_TIMERS + 2)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("expected %d events, got %d instead\n"),
                  ACE_MAX_TIMERS + 2,
                  events));
    }

  status = callback.verify_results ();
  if (status != 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Dispatch counting test failed.\n")));
      test_result = 1;
    }

#if defined (ACE_HAS_THREADS)

  Time_Handler other_thread;
  ACE_Time_Value time_limit (30);

  // Set up initial set of timers.
  other_thread.setup ();

  other_thread.activate (THR_NEW_LWP | THR_JOINABLE);
  status = ACE_Reactor::instance()->run_reactor_event_loop (time_limit);
  // Should have returned only because the time limit is up...
  ACE_TEST_ASSERT (status != -1);
  ACE_TEST_ASSERT (time_limit.sec () == 0);

  status = other_thread.wait ();
  if (status == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%p, errno is %d\n"),
                  "wait ()",
                  ACE_ERRNO_GET));
      ACE_TEST_ASSERT (status != -1);
    }

  status = other_thread.verify_results ();
  if (status != 0)
    test_result = 1;

#else
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */

  ACE_END_TEST;
  return test_result;
}
Ejemplo n.º 23
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Panic: nil RootPOA\n"),
                          1);

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      CORBA::Object_var object =
        orb->resolve_initial_references ("PolicyCurrent");

      CORBA::PolicyCurrent_var policy_current =
        CORBA::PolicyCurrent::_narrow (object.in ());

      if (CORBA::is_nil (policy_current.in ()))
        {
          ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
          return 1;
        }
      CORBA::Any scope_as_any;
      scope_as_any <<= Messaging::SYNC_WITH_SERVER;

      CORBA::PolicyList policies(1); policies.length (1);
      policies[0] =
        orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
                            scope_as_any);

      policy_current->set_policy_overrides (policies,
                                            CORBA::ADD_OVERRIDE);

      policies[0]->destroy ();

      seed = (unsigned int) ACE_OS::gethrtime ();

      if (parse_args (argc, argv) != 0)
        return 1;

      ACE_DEBUG ((LM_DEBUG, "SEED = %u\n", seed));

      Server_Peer *impl;
      ACE_NEW_RETURN (impl,
                      Server_Peer (seed, orb.in (), payload_size),
                      1);
      PortableServer::ServantBase_var owner_transfer(impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (impl);

      CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());

      Test::Peer_var peer =
        Test::Peer::_narrow (object_act.in ());

      CORBA::String_var ior =
        orb->object_to_string (peer.in ());

      // If the ior_output_file exists, output the ior to it
      FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing IOR: %s",
                           ior_output_file),
                              1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      poa_manager->activate ();

      Sleeper sleeper (orb.in ());

      ACE_Time_Value interval(0, 500000);
      ACE_Reactor * reactor = orb->orb_core()->reactor();
      reactor->schedule_timer(&sleeper, 0, interval, interval);

      // ACE_Time_Value run_time(600, 0);
      // orb->run (run_time);
      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Ejemplo n.º 24
0
bool TestHandler::trigger_in(const ACE_Time_Value &delay)
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) TestHandler::trigger_in - scheduling timer\n"));
  return -1 != reactor_->schedule_timer (this, 0, delay, ACE_Time_Value (0));
}
static bool
test_reactor_dispatch_order (ACE_Reactor &reactor)
{
    Handler handler (reactor);
    if (!handler.ok_)
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error initializing test; abort.\n")));
        return false;
    }

    bool ok_to_go = true;

    // This should trigger a call to <handle_input>.
    ssize_t result =
        ACE::send_n (handler.pipe_.write_handle (),
                     message,
                     ACE_OS::strlen (message));
    if (result != ssize_t (ACE_OS::strlen (message)))
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Handler sent %b bytes; should be %B\n"),
                    result, ACE_OS::strlen (message)));
        ok_to_go = false;
    }

    // This should trigger a call to <handle_timeout>.
    if (-1 == reactor.schedule_timer (&handler,
                                      0,
                                      ACE_Time_Value (0)))
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("schedule_timer")));
        ok_to_go = false;
    }

    // Suspend the handlers - only the timer should be dispatched
    ACE_Time_Value tv (1);
    reactor.suspend_handlers ();
    reactor.run_reactor_event_loop (tv);

    // only the timer should have fired
    if (handler.dispatch_order_ != 2)
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Incorrect number fired %d\n"),
                    handler.dispatch_order_));
        ok_to_go = false;
    }

    // Reset the dispatch_order_ count and schedule another timer
    handler.dispatch_order_ = 1;
    if (-1 == reactor.schedule_timer (&handler,
                                      0,
                                      ACE_Time_Value (0)))
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("schedule_timer")));
        ok_to_go = false;
    }

    // Resume the handlers - things should work now
    reactor.resume_handlers ();

    if (ok_to_go)
    {
        reactor.run_reactor_event_loop (tv);
    }

    if (0 != reactor.remove_handler (handler.pipe_.read_handle (),
                                     ACE_Event_Handler::ALL_EVENTS_MASK |
                                     ACE_Event_Handler::DONT_CALL))
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("remover_handler pipe")));

    if (handler.dispatch_order_ != 4)
    {
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Incorrect number fired %d\n"),
                    handler.dispatch_order_));
        ok_to_go = false;
    }

    return ok_to_go;
}
int ManageClientValidation::svc(void)
{
	FUNCTIONTRACE(ManageClientValidation::svc);
	REPORT_THREAD_INFO("ManageClientValidation::svc", ACE_OS::thr_self());

	ACE_Reactor * reactor = NULL;
	while (!m_stop)
	{

#ifdef WIN32
		reactor = new ACE_Reactor(new ACE_Select_Reactor(), true);
#else
		reactor = new ACE_Reactor(new ACE_Dev_Poll_Reactor(), true);
#endif

		LoginAcceptor login_acceptor;
		ACE_INET_Addr port_to_listen(sMsgCfg->getLSCfg().listen_port, sMsgCfg->getLSCfg().host.c_str());
		if (login_acceptor.open(port_to_listen, reactor) == -1)
		{
			GATE_LOG_ERROR(ACE_TEXT("Failed to call login_acceptor.open, host is <%s>, the port is <%d>, last error is <%d>\n"), sMsgCfg->getClientCfg().host.c_str(), sMsgCfg->getClientCfg().listen_port, ACE_OS::last_error());
			return 1;
		}

		ReportTrafficToLoginServer report_traffic;

		m_timer_id = reactor->schedule_timer(this, NULL, ACE_Time_Value(3, 0), ACE_Time_Value(3, 0));
		if (m_timer_id == -1)
		{
			GATE_LOG_ERROR(ACE_TEXT("Failed to schedule timer in ManageClientValidation::svc, last error is <%d>\n"), ACE_OS::last_error());
			return 1;
		}

		//m_report_traffic_timer_id = reactor->schedule_timer(&report_traffic, NULL, ACE_Time_Value(sMsgCfg->getLSCfg().report_interval), ACE_Time_Value(sMsgCfg->getLSCfg().report_interval));
		//if (m_report_traffic_timer_id == -1)
		//{
		//	GATELogp(LM_ERROR, ACE_TEXT("Failed to schedule timer in ManageClientValidation::svc for report traffic, last error is <%d>\n"), ACE_OS::last_error());
		//	return 1;
		//}

		//reactor->run_reactor_event_loop();
		while (true)
		{
			reactor->run_reactor_event_loop();
#ifdef WIN32
			break;
#else
			if (ACE_OS::last_error() == EINTR)
			{
				continue;
			}
			else
			{
				break;
			}
#endif
		}


		GATE_LOG_INFO(ACE_TEXT("Exit thread ManageClientValidation::svc, last error is <%d>\n"), ACE_OS::last_error());
	}

	delete reactor;

	m_wait = false;

	return 0;
}
Ejemplo n.º 27
-1
int
Time_Handler::svc (void)
{
  ACE_Reactor *r = ACE_Reactor::instance ();

  ACE_ASSERT (r->cancel_timer (this->timer_id_[2]) == 1);
  this->timer_id_[2] = Time_Handler::TIMER_CANCELLED;

  this->timer_id_[1] = r->schedule_timer(this,
                                         (const void *) 1,
                                         ACE_Time_Value (2));
  // This one may get the callback before we return, so serialize.
  this->lock_.acquire ();
  this->timer_id_[0] = r->schedule_timer(this,
                                         (const void *) 0,
                                         ACE_Time_Value (0, -5));
  this->lock_.release ();
  ACE_OS::sleep(3);

  this->timer_id_[5] = r->schedule_timer(this,
                                         (const void *)5,
                                         ACE_Time_Value (10));
  this->timer_id_[6] = r->schedule_timer(this,
                                         (const void *)6,
                                         ACE_Time_Value (12));

  ACE_ASSERT (r->cancel_timer (this->timer_id_[4]) == 1);
  this->timer_id_[4] = Time_Handler::TIMER_CANCELLED;

  return 0;
}